Question

My scheme.xlm looks like this:

<fieldType name="text" class="solr.TextField" positionIncrementGap="100">
        <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>

<!-- The searched field -->
<field name="product_name" type="text" indexed="true" stored="true"/>

This should index the field in lowercase and also transform search query into the lowercase.

Data I want to find is: "Nokia Lumia 610"

When I search "nokia" I get the expected result but when searching only "Nokia"(upper case N) there aren't any results.

Above "analyzer" performs lowercase only on index but not on search query.

Is this an error? How to force SOLR indexes and search query to be in lowercase?

Was it helpful?

Solution

Transformation of the search query also depends on the type of query and the analyzer that you are using. For example, the above will not convert your search query to lowercase if you are sending request to the select analyzer. If you are sending request :-

http://url/solr/select?q=Nokia

then the above will not be converted to lowercase since the select analyzer is not present in your fieldtype definition. You will have to modify your code as follows :-

    <fieldType name="text" class="solr.TextField" positionIncrementGap="100">
            <analyzer type="index">
                <tokenizer class="solr.WhitespaceTokenizerFactory"/>
                <filter class="solr.LowerCaseFilterFactory"/>
            </analyzer>      
            <analyzer type="query">
                <tokenizer class="solr.WhitespaceTokenizerFactory"/>
                <filter class="solr.LowerCaseFilterFactory"/>
            </analyzer>
            <analyzer type="select">
                <tokenizer class="solr.WhitespaceTokenizerFactory"/>
                <filter class="solr.LowerCaseFilterFactory"/>
            </analyzer>
    </fieldType>

if the above does not work, then please post the request that you are sending and the output of adding debugQuery=true to the request.

OTHER TIPS

Along with

<fieldType name="text" class="solr.TextField" positionIncrementGap="100">
            <analyzer type="index">
                <tokenizer class="solr.WhitespaceTokenizerFactory"/>
                <filter class="solr.LowerCaseFilterFactory"/>
            </analyzer>      
            <analyzer type="query">
                <tokenizer class="solr.WhitespaceTokenizerFactory"/>
                <filter class="solr.LowerCaseFilterFactory"/>
            </analyzer>
            <analyzer type="select">
                <tokenizer class="solr.WhitespaceTokenizerFactory"/>
                <filter class="solr.LowerCaseFilterFactory"/>
            </analyzer>
    </fieldType>

in schema.xml.

In head.vm change return $("#q").val(); to return $("#q").val().toLowerCase(); for InCaseSensitive autocomplete feature. So that you can get result if you search with Capital Letters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top