Pregunta

I am using solrnet. I have a title and Description fields. I need to search both fields simultaneously. How do I do this?

¿Fue útil?

Solución

Jayendra's answer is correct, but if you want to do this without aggregating data in a single field at index-time (copyFields) and want to do it at query-time instead using the standard handler instead of dismax, in SolrNet you can do:

var query = Query.Field("title").Is(mytitle) || Query.Field("Description").Is(mydescription);
var results = solr.Query(query);

See query operators and DSL for more information.

Otros consejos

If you are using a standard request handler -
Create a new field title_description and copy the title and description field to this field.
Use that field as the default search field.

<defaultSearchField>title_description</defaultSearchField>

Query q fired with search on the default search field -

q=bank

OR

If you can use dismax or edismax query parser, you can define a new request handler.
Define the query fields as qf.

<requestHandler name="dismax" class="solr.SearchHandler">
   <lst name="defaults">
     <str name="echoParams">explicit</str>
     <!-- Query settings -->
     <str name="defType">edismax</str>
     <str name="qf">
        title description
     </str>
     <str name="q.alt">*:*</str>
     <str name="rows">10</str>
     <str name="fl">*,score</str>
   </lst>
</requestHandler>

Query - pass the dismax as the qt parameter which would search on the title and description fields

q=bank&qt=dismax

Please try to pass the string array that contains multiple field names and search text in the below method. I will return the solrnet query for search with multiple filed name with OR condition.

public ISolrQuery BuildQuery(string[] SearchFields, string SearchText)
    {

        AbstractSolrQuery firstQuery = new SolrQueryByField(SearchFields[0], SearchText) { Quoted = false };
        for (var i = 1; i < SearchFields.Length; i++)
        {
            firstQuery = firstQuery || new SolrQueryByField(SearchFields[i], SearchText) { Quoted = false };
        }

        return firstQuery;
    }
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top