Lucene分析仪和点

0 lucene lucene.net

是Lucene的新手.

有什么方法可以让Lucene分析仪不忽略字符串中的点?例如,如果我的搜索条件是:"ABCD",Lucene应该只给我搜索结果中有"ABCD"而不是"ABCD"的文件....

its*_*dok 5

这都与您使用的分析仪有关.在StandardAnalyzer一些复杂的事情用点名称,企图以"做你的意思." 也许这WhitespaceAnalyzer将更符合您的需求.

public static void main(String[] args) throws Exception {
    RAMDirectory dir = new RAMDirectory();
    IndexWriter iw = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
    Document doc = new Document();
    doc.add(new Field("text", "A.B.C.D DEF", Field.Store.YES, Field.Index.ANALYZED));
    iw.addDocument(doc);
    iw.close();

    IndexSearcher searcher = new IndexSearcher(dir);
    QueryParser queryParser = new QueryParser("text", new WhitespaceAnalyzer());

    // prints 0 
    System.out.println(searcher.search(queryParser.parse("ABCD"), 1).totalHits);

    // prints 1
    System.out.println(searcher.search(queryParser.parse("A.B.C.D"), 1).totalHits);
}
Run Code Online (Sandbox Code Playgroud)