简体   繁体   中英

SOLR Case Insensitive Field search issue

What I want to achieve is when I search after test to bring me also Test, TeSt, TesT,TEST with case insensitive search. What should I do ?

I have this textgen type in my schema.xml that is assigned to test_field

<fieldType name="textgen" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
    <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="0"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.StopFilterFactory"
            ignoreCase="true"
            words="stopwords.txt"
            enablePositionIncrements="true"
            />
    <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="0"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="select">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.StopFilterFactory"
            ignoreCase="true"
            words="stopwords.txt"
            enablePositionIncrements="true"
            />
    <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="0"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

Here are the results which I want to recieve with my query.

{
  "responseHeader":{
    "status":0,
    "QTime":2,
    "params":{
      "q":"test_field:*",
      "indent":"true",
      "wt":"json"}},
  "response":{"numFound":5,"start":0,"docs":[
      {
        "id":"change.me",
        "test_field":["test"],
        "_version_":1546932094148542464},
      {
        "id":"change.me1",
        "test_field":["tesT"],
        "_version_":1546932100203020288},
      {
        "id":"change.me2",
        "test_field":["TesT"],
        "_version_":1546932103122255872},
      {
        "id":"change.me3",
        "test_field":["TEsT"],
        "_version_":1546932107768496128},
      {
        "id":"change.me4",
        "test_field":["TEST"],
        "_version_":1546932111283322880}]
  }}

When I use this query it does not give any result because it is case sensitive, even though it has the filter LowerCaseFilterFactory

http://localhost:8983/solr/test-data/select?q=test_field:*test*&wt=json&indent=true

AND the empty results. (what I'm doing wrong?)

{
  "responseHeader":{
    "status":0,
    "QTime":2,
    "params":{
      "q":"test_field:*test*",
      "indent":"true",
      "wt":"json"}},
  "response":{"numFound":1,"start":0,"docs":[
      {
        "id":"change.me",
        "test_field":["test"],
        "_version_":1546932094148542464}]
  }}

Are you actually putting stars (wildcards) at both ends of your search term? You should not need to do that. The whole point of Solr configuration is to tokenize your text in a way that you can just search for words without wildcards.

If you just search for a work in your text, it should work including mixed-case matching. If not, check that your field is actually mapped to the right type and that you reindexed. If still confused, Solr Admin UI has an analyze screen where you can select your fields (or your field types) and see how something is tokenized and how it is matched. You can experiment there.

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