我是新手lucene用户,现在尝试获得一些基础知识.
我有三个文件:
> apache_empty.txt(空文件),
> apache.txt(包含许多’apache’令牌),
> other.txt(只包含一个标记 – ‘apache’)
当我尝试搜索’apache’时,我只得到结果中的apache.txt和other.txt,但我想得到apache_empty.txt文件,它的名字中包含搜索到的单词…
这就是我如何向索引添加文档:
protected Document getDocument(File f) throws Exception
{
Document doc = new Document();
Field contents = new Field("contents", new FileReader(f));
Field parent = new Field("parent", f.getParent(), Field.Store.YES, Field.Index.NOT_ANALYZED);
Field filename = new Field("filename", f.getName(), Field.Store.YES, Field.Index.ANALYZED);
Field fullpath = new Field("fullpath", f.getCanonicalPath(), Field.Store.YES, Field.Index.NOT_ANALYZED);
filename.setBoost(2.0F);
doc.add(contents);
doc.add(parent);
doc.add(filename);
doc.add(fullpath);
return doc;
}
如何让lucene索引也是文件名?
解决方法:
要启用通配符,您应该搜索apache *,它也与您的文件名apache_empty匹配,以获得完整语法,另请参阅Apache Lucene Query Parser.
另一种方法是在使用的分析仪中将下划线作为单词分隔符.
标签:java,lucene
来源: https://codeday.me/bug/20190529/1181445.html