user3278732
user3278732

Reputation: 1724

Solr returning way more values

Using Django 2.2.7, Python 3.6.9, PySolr 3.8.1, DJANGO Haystack 2.8.1

haystack_conn = {}
search_engine = 'solr'
if search_engine == 'whoosh':
    haystack_conn = {
        'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
        'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),
    }
elif search_engine == 'solr':
    haystack_conn = {
        'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
        'URL': 'http://127.0.0.1:8983/solr/bsd',
    }
elif search_engine == 'elastic_search':
    haystack_conn = {
        'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
        'URL': 'http://127.0.0.1:9200/',
        'INDEX_NAME': 'artifacts',
    }

HAYSTACK_CONNECTIONS = {
    'default': haystack_conn,
}


HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
HAYSTACK_SEARCH_RESULTS_PER_PAGE = 10

When I search for ex. ios I get 250 results. When I search ios 10 i get 500 results, although I should get less .. around 90.

Upvotes: 0

Views: 48

Answers (2)

user3278732
user3278732

Reputation: 1724

If someone in future searches for this

in solrconfig.xml I added the below, this solution worked for me.

<requestHandler name="/select" class="solr.SearchHandler">
    <!-- default values for query parameters can be specified, these
      will be overridden by parameters in the request
    -->
    <lst name="defaults">
        <str name="df">text_en</str>
        <str name="q.op">AND</str>
    </lst>
</requestHandler>

Upvotes: 0

Abhijit Bashetti
Abhijit Bashetti

Reputation: 8658

Use the string type for your field artifact_name as below.

<fieldType class="solr.StrField" name="string" omitNorms="true" sortMissingLast="true" />

(the above line must be in your schema.xml.)

<field name="artifact_name" type="string" indexed="true" stored="true" multiValued="false" />

Or You can have another way to it like below.

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

<field name="artifact_name" type="customFieldType" indexed="true" stored="true" multiValued="false" />

Upvotes: 1

Related Questions