dpnw86361
dpnw86361
2011-12-01 11:24

更新Solr配置以搜索所有字段

已采纳

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>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • dongzichan2886 dongzichan2886 10年前

    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
    
    点赞 评论 复制链接分享
  • duanchao9559 duanchao9559 10年前

    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.

    点赞 评论 复制链接分享