How can I Ignore some fields in a SOLR query

你说的曾经没有我的故事 提交于 2019-12-22 13:05:23

问题


I have Solr 5.3.1 and need to do query for all field except some field (what I need search in some field not retrieve fields this way to retrieve [/?q=query&fl=field1,field2,field3] )

i try with some solution but not work

1.How to exclude fields in a SOLR query [this soluation not work]

2.[the below solution work but take more time]

query = field1:"+txtSearch+"OR field1:"+ txtSearch+" OR field1:"+txtSearch 

3.I set indexed="false" in data-config.xml it only Ignore search in this field but when I search for all fields http://localhost:8983/solr/test?q=query the query search in all field regardless indexed="false" OR true

I look for all this links

Retrieving specific fields in a Solr query?

How to exclude fields in a SOLR query

https://www.drupal.org/node/1933996


回答1:


Use copyField

Here is how you can use this:

  • Make all the field stored="true" and indexed="false"
  • Also create a new field say cffield with multiValued="true", stored="false" and indexed="true"

Example Schema :

<field name="field1" type="string" indexed="false" stored="true"/>
<field name="field2" type="string" indexed="false" stored="true"/>
<field name="field3" type="string" indexed="false" stored="true"/>
....
<field name="cffield" type="string" indexed="true" stored="false" multiValued="true"/>
  • Now all the field from you want to search, set source value of use copyField tag to copy from source field to dest

Example Schema :

<copyField source="field1" dest="cffield"/>
<copyField source="field2" dest="cffield"/>
....

Now you can search using

query = cffield:txtSearch

This will give you result from all the field you use copyField's source and cffield as dest




回答2:


indexed="false" needs to be mentioned in the schema.xml.

Once you modify the schema.xml, you need to re-index the data.(you need to re-start the server as well)

Then solr will not search in the fields which are not indexed. And if you want to search in specific field you can use the field name and the search value for the field.

like

   `q=field1:"value1"`
    q=field1:value1 OR field2:value2
    q=field1:value1 AND field2:value2
    q=value1&fq=field2:value2&fq=field3:value3  


来源:https://stackoverflow.com/questions/42247592/how-can-i-ignore-some-fields-in-a-solr-query

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