Skip to content

Commit

Permalink
改进高亮,解决:hankcs/HanLP#75 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
hankcs committed Oct 22, 2015
1 parent 91eefb5 commit 7a797a6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
15 changes: 14 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.hankcs.nlp</groupId>
<artifactId>hanlp-solr-plugin</artifactId>
<version>1.0.2</version>
<version>1.0.3</version>

<name>hanlp-solr-plugin</name>
<url>https://github.com/hankcs/HanLP</url>
Expand All @@ -20,6 +20,7 @@
<javac.src.version>1.7</javac.src.version>
<javac.target.version>1.7</javac.target.version>
<maven.compiler.plugin.version>3.3</maven.compiler.plugin.version>
<maven-source-plugin.version>2.4</maven-source-plugin.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -74,6 +75,18 @@
</configuration>
<version>${maven.compiler.plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/hankcs/lucene/SegmentWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public Term next() throws IOException
term.offset += offset;
}
index = 0;
offset += line.length() + 1;

return termArray[index++];
}
Expand Down
11 changes: 9 additions & 2 deletions src/test/java/com/hankcs/lucene/HighLighterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,21 @@ public void testHightlight() throws Exception
{
// 加入一个文档
Document doc = new Document();
doc.add(new TextField(fieldName, "我白天是一名语言学习者,晚上是一名初级码农。空的时候喜欢看算法和应用数学书,也喜欢悬疑推理小说,ACG方面喜欢型月、轨迹。喜欢有思想深度的事物,讨厌急躁、拜金与安逸的人。目前在魔都某女校学习,这是我的个人博客。闻道有先后,术业有专攻,请多多关照。你喜欢写代码吗?", Field.Store.YES));
doc.add(new TextField(fieldName, "我白天是一名语言学习者,晚上是一名初级码农。\n" +
"\n" +
"\n" +
"\n空的时候喜欢看算法和应用数学书,也喜欢悬疑推理小说,ACG方面喜欢型月、轨迹。\n" +
"\n" +
"\n" +
"\n" +
"\n喜欢有思想深度的事物,讨厌急躁、拜金与安逸的人。目前在魔都某女校学习,这是我的个人博客。闻道有先后,术业有专攻,请多多关照。你喜欢写代码吗?", Field.Store.YES));
doc.add(new TextField("title", "关于hankcs", Field.Store.YES));
iwriter.addDocument(doc);
}
{
// 再加入一个
Document doc = new Document();
doc.add(new TextField(fieldName, "\n\n \n程序员喜欢黑夜", Field.Store.YES));
doc.add(new TextField(fieldName, "\n\n \n程序员\n\n喜欢黑夜", Field.Store.YES));
doc.add(new TextField("title", "关于程序员", Field.Store.YES));
iwriter.addDocument(doc);
}
Expand Down

0 comments on commit 7a797a6

Please sign in to comment.