Solr wildcard query with whitespace

前端 未结 9 1587
悲哀的现实
悲哀的现实 2020-12-06 04:57

I have a wildcard query that looks something like:

q=location:los a*

I\'d like it to match \"los angeles\" and \"los altos\". A query like

相关标签:
9条回答
  • 2020-12-06 05:17

    I had the same problem in my project. When ever I was search for a word along with the whitespace I was not geting the result. So I replaced the whitespace with a hyphen "-" while indexing and querying. Below is the schema.xml snipet which I used to do so:

    <fieldType name="text_ci" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
    <tokenizer class="solr.NGramTokenizerFactory" minGramSize="2" maxGramSize="250"/>
    <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.TrimFilterFactory" />
        <filter class="solr.PatternReplaceFilterFactory"
                pattern="([/\s+])" replacement="-" replace="all"
        />
    </analyzer>
    <analyzer type="query">
    <tokenizer class="solr.EdgeNGramTokenizerFactory" minGramSize="2" maxGramSize="250"/>
    <filter class="solr.LowerCaseFilterFactory"/>
     <filter class="solr.TrimFilterFactory" />
        <filter class="solr.PatternReplaceFilterFactory"
                pattern="([/\s+])" replacement="-" replace="all"
        />
    </analyzer>
    </fieldType>
    
    0 讨论(0)
  • 2020-12-06 05:22

    Might I suggest the solr prefix query plugin if you are only using it for wildcards on the suffix as we were http://lucene.apache.org/solr/4_0_0/solr-core/org/apache/solr/search/PrefixQParserPlugin.html

    example usage

    http://localhost:8983/solr/collection/select?q={!prefix%20f=name}Bob%20Smi
    

    would match "Bob Smith" or "Bob Smit" but not convert into a check of ("Bob" OR "Smi*") as would happen if you used the first solution you might consider along the lines of q=name:Bob%20Smi*

    Hopefully this is of some help to you or someone else looking for a simple solution because I was banging my head against a wall for hours before I found this!

    0 讨论(0)
  • 2020-12-06 05:22

    For me worked

    <fieldtype name="text_like" class="solr.TextField">
        <analyzer type="index">
            <tokenizer class="solr.NGramTokenizerFactory" minGramSize="3" maxGramSize="1000"/>
            <filter class="solr.LowerCaseFilterFactory"/>
        </analyzer>
        <analyzer type="query">
            <tokenizer class="solr.LowerCaseTokenizerFactory"/>
        </analyzer>
    </fieldtype>
    

    and query field:*some\ phrase* (in java literal one needs to escape \ as \\).

    0 讨论(0)
提交回复
热议问题