18

I've a problem in SOLR Search.
I have a data like this:
enter image description here

I use solr admin to find this data using query like this:

address_s:*Nadi*

and found those data. But when I use this query:

address_s:*nadi*

it doesn't found anything.
I've googling and I found an answer to create a field with the following script:

<fieldType name="c_text" class="solr.TextField">
    <analyzer type="index">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>

    <analyzer type="query">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
</fieldType>

I've copy paste those script into schema.xml, but it still doesn't work. What should I do? Can anyone help me?

Kris
  • 14,426
  • 7
  • 55
  • 65
Praditha
  • 1,162
  • 5
  • 24
  • 45

5 Answers5

12

I've used this as field type:

<fieldType name="string" class="solr.TextField">
  <analyzer type="index">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

And defined my fields using:

<field name="address" type="string" indexed="true" stored="true"/>

The result: My document returns the fields in the right case (like inserted) and I can search case-insensitive (using both upper- and lowercase letters)...

Version: Solr 3.6

Jeff Maes
  • 707
  • 8
  • 13
  • @ Jeff Maes that is giving an error. "string": FieldType: StrField (string) does not support specifying an analyzer – Jenish Oct 09 '19 at 10:38
12

The address_s field should be defined as -

<field name="address_s" type="c_text" indexed="true" stored="true"/>

If you are using the default schema.xml, this defination should come before -

<dynamicField name="*_s"  type="string"  indexed="true"  stored="true"/>

which defines it as a string field type with no analysis performed.

Wildcard queries does not undergo analysis.
So if you apply lower case filter at index time query address_s:*nadi* would work.
However, query address_s:*Nadi* would not, as Nadi will not match nadi in index and you would need to lower case the queries at client side.

Jayendra
  • 52,349
  • 4
  • 80
  • 90
  • 2
    I've followed your instruction, but it still can't work. I copy paste `` to schema.xml, and re-run `java -jar start.jar` and tried the query. Sorry, I wanna ask first, I used schema.xml at ..\solr_302\example\solr\conf, is that right,.? – Praditha Nov 24 '11 at 06:52
  • hey it's work, I need to re-insert the document first. thanks,. do you know how to defined those field through PHP,.? so I don't need to defined it in schema.xml manually. – Praditha Nov 24 '11 at 08:34
  • 7
    `However, query address_s:*Nadi* would not, as Nadi will not match nadi in index` -- But isn't that the point of having `LowerCaseFilterFactory` in ``, so that *queries* are lowercased automatically? – Madbreaks Jun 27 '12 at 23:31
  • I tried this out. But it does not work with solr 5.3.0 – aasha Oct 14 '15 at 11:54
5

Does your address_s field use this c_text field type in your schema.xml?

If your index has been created with the previous configuration, you need to re-index everything to take the changes into account.

jpountz
  • 9,904
  • 1
  • 31
  • 39
  • How to do that,.? because I make all fields using php. I enter all fields into array like this: $data = array(... , 'address_s' => 'value', 'city_name_s' => 'value', ...); and use addDocument($data) function. Any idea.,? – Praditha Nov 23 '11 at 10:22
  • 3
    Then you need to re-run these commands for all the documents which have been added to the index. The representation of the data in the index depends on the analyzer which has been used. Therefore, if you update the analyzer that you use for indexing, you need to re-index all your documents. – jpountz Nov 23 '11 at 13:08
  • sorry, I still don't understand what should I do, can you describe it step by step :D and when I should use `c_text` field type to all index, when I re-run my php command,.? – Praditha Nov 24 '11 at 06:39
  • 2
    The only thing you need to do to make it work is to re-insert all your documents to the index. – jpountz Nov 24 '11 at 14:33
1

I have used something like this ... In schema.xml i 've put a new fieldType

<fieldType name="newType" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.ReversedWildcardFilterFactory" />
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.ReversedWildcardFilterFactory" />
      </analyzer>
 </fieldType>

Assign the new type to the field that you want to make it case & whitespace insensitive Then you have to construct the solr query in the form : fieldName:(*fieldValue\ *)

Manos
  • 21
  • 1
  • 4
1

instead of type="string" define the field type="text_general" (as defined in the default schema.xml). On eof its property is ignore case=true

jan
  • 2,879
  • 2
  • 19
  • 28
Shimon Benattar
  • 173
  • 1
  • 3
  • 9