Lucene 分词
程序员文章站
2022-03-05 12:42:17
...
PhraseQuery query2 = new PhraseQuery();
query2.setSlop(4); //可以设置slop
query2.add(new Term("text","天山长宁"));
Query queryIK = IKQueryParser.parse("text", "南京西路");
System.out.println(queryIK);
List<String> testStr = new ArrayList<String>();
testStr.add("天山支路");
for(String t : testStr){
System.out.println("key:"+t);
IKSegmentation ikSeg = new IKSegmentation(new StringReader(t) , true);
try {
Lexeme l = null;
while( (l = ikSeg.next()) != null){
System.out.println(l.getLexemeText());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("***************");
}
//Term============================================
Term t1 = new Term("text","天山");
TermQuery query2 = new TermQuery(t1);
Term t2 = new Term("text","长宁");
TermQuery query21 = new TermQuery(t2);
//================================================
BooleanQuery query3 = new BooleanQuery();
query3.add(query2, BooleanClause.Occur.MUST);
query3.add(query21, BooleanClause.Occur.MUST_NOT);