Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 Lucene 的邻近搜索中,搜索单词的顺序是不被维护的。
有什么方法可以过滤搜索,以便 word1 在结果文档中总是出现在 word2 之前。
有SpanNearQuery那个。
SpanNearQuery
http://lucene.apache.org/core/old_versioned_docs/versions/2_9_4/api/all/org/apache/lucene/search/spans/SpanNearQuery.html
SpanTermQuery tq1 = new SpanTermQuery(new Term("field", "word1")); SpanTermQuery tq2 = new SpanTermQuery(new Term("field", "word2")); SpanNearQuery spanNear = new SpanNearQuery(new SpanQuery[]{tq1,tq2}, 2, true);