Proximity Search using phrases in Solr

感情迁移 提交于 2019-12-02 17:42:44

This appears to be "somewhat" doable. Consider this text:

This is more about traffic between Solr servers themselves 

"more traffic between solr" ~2

"more about between solr" ~2

Even if you change the order it works:

"more about solr between" ~2" ~2

But too far apart and it stops working:

"more about servers themselves" ~2

I think if that doesn't work, it would probably not be TOO hard to make a custom request handler that does this. I think you might need to define a new syntax, prehaps something like ("phrase one" "phrase two") ~2. I would guess that if you are shingling, and you create a Lucene query where there is a token of just "phrase one" and another of "phrase two" that have a certain proximity, i think it will work. (of course you will need to actually make the lucene java call, you can't just hand the query over (read this http://lucene.apache.org/java/2_2_0/api/index.html)).

Out of the box I have discovered a way to perform a Solr proximity search using more then one word, or phrases, see below

eg. with 3 words:

"(word1) (word2) (word3)"~10

eg. with 2 phrases: (note the double quote needs to be escaped)

"(\"phrase1\") (\"phrase2\")"~10

Since Solr 4 it is possible with SurroundQueryParser.

E.g. to query where "phrase two" follows "phrase one" not further than 3 words after:

3W(phrase W one, phrase W two)

To query "phrase two" in proximity of 5 words of "phrase one":

5N(phrase W one, phrase W two)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!