Lucene 如何返回索引中命中的查询项

Lucene 如何返回索引中命中的查询项,lucene,Lucene,我试图返回在我的Lucene索引中引起点击的原始术语。例如,我的搜索字符串是“敏捷的棕色狐狸跳过懒惰的狗”。“狗”一词在索引中有“狗带”和“遛狗”之类的词条。同样,《狐狸》也有像《狐狸手套》和《狐狸洛西》这样的热门歌曲 因此,我想为用户打印出原始的“QuickBrownFox”字符串,其中突出显示了点击(dog和fox)的术语。下面是几个使用解释方法的例子,但是答案没有提到最后一步。 我认为Lucene不会轻易做到这一点,我将不得不使用正则表达式 我想出了一种方法来生成一个字符串,该字符串是带有

我试图返回在我的Lucene索引中引起点击的原始术语。例如,我的搜索字符串是“敏捷的棕色狐狸跳过懒惰的狗”。“狗”一词在索引中有“狗带”和“遛狗”之类的词条。同样,《狐狸》也有像《狐狸手套》和《狐狸洛西》这样的热门歌曲

因此,我想为用户打印出原始的“QuickBrownFox”字符串,其中突出显示了点击(dog和fox)的术语。下面是几个使用解释方法的例子,但是答案没有提到最后一步。
我认为Lucene不会轻易做到这一点,我将不得不使用正则表达式

我想出了一种方法来生成一个字符串,该字符串是带有突出显示的命中术语的原始用户文本。 原始用户文本以通常的方式根据索引进行查询。原始用户文本和结果将传递给“反向”查询方法。即: 原始用户文本将转换为基于内存的索引,并由原始结果查询。这与我们最初的做法相反。结果是结果中的常用词会被比对回字符串。这在我的索引中有效,因为所有结果都是“严格”定义

高亮显示用于在原始结果中找到的常用词[…]周围插入分隔符。 正则表达式(?)?
//remove found term duplicates and produce a single string with all the hits highlighted
// to be the final modified string with all highlights
String strOutput = searchText;

// creating a hashset using the incoming list
Set<String> textSet = new LinkedHashSet<String>(textResult);
// remove all the elements from the list 
textResult.clear();
// add all the elements of the set to create a

// list of found terms without duplicates
textResult.addAll(textSet);

// add html elements to found terms
for(String term : textResult){
    replacementWord.add("<b>"+term+"</b>");
}
//put original term and the same term with highlights in a hash map
for(int i=0; i<replacementWord.size(); ++i) {
    oldAndNewTerms.put(textResult.get(i), replacementWord.get(i));

}

//use a hash map to modify the original string
for (String key : oldAndNewTerms.keySet()){       

      strOutput = strOutput.replace(key,oldAndNewTerms.get(key) );      }

System.out.println(strOutput);