Understading Solr nested queries

試著忘記壹切 提交于 2019-12-20 04:14:40

问题


I'm trying to understand solr nested queries but I'm having a problem undestading the syntax.

I have the following two indexed documents (among others):

<doc>
    <str name="city">Guarulhos</str>
    <str name="name">Fulano Silva</str>
</doc>

<doc>
    <str name="city">Fortaleza</str>
    <str name="name">Fulano Cardoso Silva</str>
</doc>

If I query for q="Fulano Silva"~2&defType=edismax&qf=name&fl=score I have:

<doc>
    <float name="score">28.038431</float>
    <str name="city">Guarulhos</str>
    <str name="name">Fulano Silva</str>
</doc>

<doc>
    <float name="score">19.826164</float>
    <str name="city">Fortaleza</str>
    <str name="name">Fulano Cardoso Silva</str>
</doc>

So I thought that if I queried for:

q="Fulano Silva"~2 AND __query__="{!edismax qf=city}fortaleza" &defType=edismax&qf=name&fl=score

I'd give a bit more score for the second document, but actually I get an empty result set with numFound=0.

What am I doing wrong here?


回答1:


Need to remove the "=" and replace it with ":" to use the nested query syntax:

q="Fulano Silva"~2 AND _query_:"{!edismax qf=city}fortaleza" &defType=edismax&qf=name&fl=score

*Use _query_: instead of _query_=

Hope this works...




回答2:


EDIT: When you say q=, are you specifying the query in a URL, or is the text after the q= being put in an application or the Solr dashboard? If we're talking about a URL, you may need to use percent-encoding to get it to work. I mentioned that below, but since I haven't heard from you, I thought I'd reiterate.

Why don't you do q=name:"Fulano Silva" AND city:"fortaleza"?

Another possibility: q=_query_:"{!edismax qf='name'}Fulano Silva" AND city:"fortaleza"

If you're set on a nested query, select?defType=edismax&q="Fulano Silva" AND _query_:"{!edismax qf='city' v='fortaleza'}" should work, but the results and the way it matches will depend on what analyzers you are using to query and index name and city. Also, if these queries are in your query string, make sure you are encoding them properly.

In order to help you any more, I need to know what you're trying to accomplish with your query. Then perhaps we can be sure you have the right indexing set up, that edismax is the right query handler, etc.




回答3:


On top of the previous comments, the asker has mispelled _query_ as __query__ (note the double underscore in the second, mispelled, version); Solr expects _query_ to be spelled with only one underscore (_) before and one after the word query, not two.



来源:https://stackoverflow.com/questions/18389226/understading-solr-nested-queries

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