我需要检索文本中与 SpanNearQuery.getSpans() 返回的 Spans 匹配相对应的单词。例如,如果我的文本是 [abcdef] 并且我使用 SpanNearQueries 来查询“b”和“e”(以及足够的斜率),那么我会在文本中得到匹配的“bcd e”。现在,我怎样才能最有效地检索匹配中出现的单词,即单词“bcd e”本身的序列?
下面是我需要的示例代码:
SpanNearQuery allNear = new SpanNearQuery(spansTermQueries, numWordsInBetween, true);
Spans allSpans = allNear.getSpans(reader);
现在我想迭代 allSpans 中的所有匹配项,并为每个匹配项检索查询 9 之间与该匹配项对应的文本之间的确切单词。
一种间接的方法是获取该匹配的结束和开始位置,使用文件阅读器通读文本文档,并找到位置“结束”和“开始”之间的文本字符串。但这似乎不是一个非常有效的方法。看来这个信息应该已经存储在 Lucene Index 中了。
有人知道更直接的方法来检索匹配中查询之间的单词吗?
谢谢。
I would need to retrieve the words in my text that correspond to a match of Spans returned by SpanNearQuery.getSpans(). For instance, if my text is [a b c d e f] and I use SpanNearQueries with queries 'b' and 'e' (and sufficient slop), then I get a match 'b c d e' in my text. Now, how can I most efficiently retrieve the words as they appear in the match, that is, the sequence of words 'b c d e' itself?
Here is an example code of what I would need:
SpanNearQuery allNear = new SpanNearQuery(spansTermQueries, numWordsInBetween, true);
Spans allSpans = allNear.getSpans(reader);
Now I would like to iterate over all the matches in allSpans, and for each match retrieve the exact words between the queries 9 the text that correspond to that match.
One indirect way is to get the end and start position of that match, read through the text document using a file reader, and find the string of text between position 'end' and 'start'. But that does not seem a very efficient way. It seems that this information should already be stored in the Lucene Index.
Would anyone know of a more direct way of retrieving the words between the queries in a match?
Thanks.
发布评论
评论(1)
你想做的是 突出显示。您可以使用普通荧光笔或 快速向量荧光笔(如果您存储术语向量)。
What you want to do is highlighting. You can either use the plain highlighter or fast vector highlighter if you store term vectors.