Solr does not search into integers?

前端 未结 3 635
梦如初夏
梦如初夏 2021-01-15 15:36

I\'m currently developping a search engine using Solr for an ecommerce website. So I get these two fields in my schema.xml:

   

        
相关标签:
3条回答
  • 2021-01-15 16:06

    Yes add a directive like this in your schema.xml after the field definitions:

    <copyField source="sku" dest="text">
    

    assuming that the defaultSearchField is set to text.

    To search for all SKUs beginning with 96 you can search for 96*. Keep in mind though this will return all fields (not just SKUs) that begin with 96. To restrict it to SKUs, you will have to search for sku:96*.

    0 讨论(0)
  • 2021-01-15 16:08

    You'll need a copyField setting for the fields you want to be searchable by default.

    Since your defaultSearchField is set to global, try:

    <copyField source="sku" dest="global"/>
    

    You'll probably want to do the same for collection:

    <copyField source="collection" dest="global"/>
    

    In order to have partial matches (e.g.: ?q=95) without special operators, you need to tweak the NGram filter. Your current setting, for both the index-time and the query-time analyzer is:

    <filter class="solr.EdgeNGramFilterFactory" minGramSize="3" maxGramSize="6"/>
    

    This means that partial matching will be available from 3 to 6 characters, per example:

    • 959
    • 9596
    • 95962
    • 596
    • ...

    If you want to allow it from 2 characters (e.g.: 95), change the minGramSize in both analyzers' filters and you should be good to go:

    <filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="6"/>
    

    Lastly, your global field probably shouldn't be stored (by default) but only indexed:

    <field name="global" type="text_fr" indexed="true" stored="false" required="false" multiValued="true" />
    

    Remember that you need to restart Solr and re-index for the changes to be in effect.

    0 讨论(0)
  • 2021-01-15 16:17

    Based on the behavior described it sounds like you're trying to use basic SearchHandler query syntax out of the box to search against multiple fields. That's not going to work out as you'd hope.

    There are numerous options available:

    1. Front-end the query so that fully-qualified field names get sent (eg "fielda:foo OR fieldb:foo")
    2. Copy the contents of searchable fields into a single search field (through copyField) and make that the default field to search
    3. Use Solr Dismax syntax and specify multiple QueryFields (qf parameter in the request)

    Since you have fields of different types, and want to apply wildcard matching and other such things, I'd recommend you go the Dismax route and look into creating a Query Handler that better suits your needs:

    More info on:

    • The default SearchHandler: http://wiki.apache.org/solr/SearchHandler
    • Solr with Dismax: http://wiki.apache.org/solr/DisMaxQParserPlugin
    0 讨论(0)
提交回复
热议问题