我使用Lucene Highlighter来突出我在Lucene Index中找到的匹配.现在,我的问题是,如果我必须搜索文档的多个字段,并且我需要显示匹配的文本,那么如何才能获得命中发生的字段?
我用于荧光笔的代码基本上就是这里的第二个功能
如果我不知道命中发生在哪个字段中,那么我将传递给上面定义的函数哪个字段来获取匹配的片段?
Lucene 4.3.1荧光笔是如何工作的?我想从文档打印出搜索结果(作为搜索的单词和该单词后面的8个单词).我如何使用荧光笔类来做到这一点?我已将完整的txt,html和xml文档添加到文件中并将其添加到我的索引中,现在我有一个搜索公式,我可能会从中添加荧光笔功能:
String index = "index";
String field = "contents";
String queries = null;
int repeat = 1;
boolean raw = true; //not sure what raw really does???
String queryString = null; //keep null, prompt user later for it
int hitsPerPage = 10; //leave it at 10, go from there later
//need to add all files to same directory
index = "C:\\Users\\plib\\Documents\\index";
repeat = 4;
IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(index)));
IndexSearcher searcher = new IndexSearcher(reader);
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_43); …Run Code Online (Sandbox Code Playgroud)