Question

I am trying to search Solr Instance with Solr.Net. I have field body which is defined in schema as:

<field name="body" 
       type="text_general" 
       indexed="true" 
       stored="true" 
       omitNorms="true"/>

text_general uses solr.StandardTokenizerFactory in schema and defined as:

<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
  <analyzer type="index">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
    <!-- in this example, we will only use synonyms at query time
    <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
    -->
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" />
    <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>

(I haven't changed anything with this field type, It is the one I got with the default installation of solr)

I am trying to query records against search term LISTBU5.RCV, it is returning me results containing LISTBU4.RCV. Like:

Items left on queue: \\111.11.11.11\Lists\SAVELIST\ABC2\LISTBU4.RCV

False Result: The number at the end of the search term is different

My code for querying is:

SolrQueryByField solrQuery = new SolrQueryByField("body", searchTerm);

var result = solr.Query(solrQuery, new SolrNet.Commands.Parameters.QueryOptions
{
    Rows = 100, // 
    Start = 0,
    OrderBy = new[] { new SortOrder("ID", Order.DESC) },
});

But if I use Text Query like:

SolrQuery solrQuery = new SolrQuery("(body:" + "\"" + searchTerm + "\")");

It returns exact results. I know that creating a Text query is not encouraged in Solr.Net but what should I do about it ?

I am using SolrNet.dll version 0.4.0.2002 with Solr Instance 4.4.0 version.

Was it helpful?

Solution

I have been able to find the problem. The reason I was getting the false result was because of the SortOrder specified in my query options. It was overriding the default SortOrder based on relevance score. I just modified my query options like:

var result = solr.Query(solrQuery, new SolrNet.Commands.Parameters.QueryOptions
{
    Rows = 100, // 
    Start = 0,
    OrderBy = new[] { new SortOrder("score", Order.DESC), new SortOrder("ID", Order.DESC) },
});

new SortOrder("score", Order.DESC) will force the results to be returned based on relevance score first and then it will do the sorting based on the ID.

I am not really sure why SortOrder was overridden when sending a text query to SOLR. But this seems to work since it will select top 100 rows with exact term instead of false positives.

I will just leave this answer for future visitors, and will accept any future answer if it provides reason for this search behaviour.

OTHER TIPS

Looks like the two queries were different because of the term was tokenized in the 1st example but not the second, which was protected by double quote. Would you mind to try:

SolrQueryByField solrQuery = new SolrQueryByField("body", "\""+searchTerm+"\"");

This might give you the same result as the 2nd query(if not consider the ordering). HIH

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