简体   繁体   中英

Updating Solr configuration to search on all fields

Can anyone advise me on how to search Solr on all fields?

This is my current requestHandler called "search" and using solr.SearchHandler.

<requestHandler name="search" class="solr.SearchHandler" default="true">
  <!-- default values for query parameters can be specified, these
         will be overridden by parameters in the request
    -->
   <lst name="defaults">
    <str name="echoParams">explicit</str>
    <int name="rows">10</int>
   </lst>
</requestHandler>

It appears that I can search on all textual fields, however I need to search on a field called 's_number' and this is an integer.

Do I need to use DisMax to allow for searching on all fields?

Also, do I need to adjust the defaultSearchField in schema.xml? It is currently:

<defaultSearchField>text</defaultSearchField>

The defaultSearchField parameter you're talking about references this field in your schema.xml:

<!-- catchall field, containing all other searchable text fields (implemented
        via copyField further on in this schema  -->
<field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>

If you look a little further down you should see statements that look like this:

<copyField source="name" dest="text"/>
<copyField source="summary" dest="text"/>

What you probably want to do is add a copyfield parameter for your s_number field, like so:

<copyField source="s_number" dest="text"/>

This will copy the number field into your default search field (text). The text field is a "dumping ground" of terms for a default search. The good thing about it is you can control how and what information gets put into default search. The bad thing is that you need to add copyField parameters for each field you want in the default.

To search on non-textual fields you probably don't have to edit the config files. You just need to add the parameter correctly to your solr query.

The basic idea is you can use key/value pairs to search on non-textual fields. See http://wiki.apache.org/solr/SolrQuerySyntax .

To search on just s_number, you'd set up your query to the solr server like this:

q=s_number:123

This will return only results where s_number is 123, as expected -- and it does it as a regular search, not a post-search filter. I don't know what php solr library you're using, so I can't give you the exact code for how to set up this query parameter in your code. If you tell me what library you are using and/or post the source code that actually does the search, I might be able to give you more precise details.

But talking directly to your solr server, the query would look something like this:

http://your-solr-server:8983/solr/select/?q=s_number%3A123

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM