Abhijit Guha
Abhijit Guha

Reputation: 31

How to use boosting in solrnet while using default query?

I am using SolrNet to do query on my default search field and not on any specific field. How can I use Boost on a specific field in that case? Below is the code snippet.

List filter = BuildQuerySingleLine(arrParams);

        var customer = solr.Query(parameters.SingleLineSearch, new QueryOptions
        {                
            FilterQueries  = filter,
            SpellCheck = new SpellCheckingParameters { Collate = true },
            OrderBy = new[] { new SortOrder("score", Order.DESC), SortOrder.Parse("score DESC") },
            StartOrCursor = new StartOrCursor.Start(parameters.StartIndex),
            Rows = parameters.NumberOfRows               

        });

Upvotes: 1

Views: 907

Answers (2)

Abhijit Guha
Abhijit Guha

Reputation: 31

At last I found the solution to this problem. For this I have used dismax request handler and passed the qf param value through SOLRNET.

With this you can pass the dynamic boost value to the SOLR query, on different fields.

var extraParams = new Dictionary<string, string> { { "qt", "dismax" }, { "qf", "fieldName^1 FieldName^0.6" } };

var customer = solr.Query(parameters.SingleLineSearch, new QueryOptions
{                
                          
    StartOrCursor = new StartOrCursor.Start(parameters.StartIndex),
    Rows = parameters.NumberOfRows,
    }, 
    ExtraParams = extraParams
});

Upvotes: 2

Rusty Nail
Rusty Nail

Reputation: 2710

According to this document: Querying and The DisMax Query Parser

var extraParams = new List<KeyValuePair<string, string>>();

extraParams.Add(new KeyValuePair<string, string>("bq", "SomeQuery^10"));
extraParams.Add(new KeyValuePair<string, string>("bq", "SomeOtherQuery^10"));

var options new new QueryOptions();
options.ExtraParams = extraParams; //Since my List implements the right interface

solr.Query(myQuery, options)

the bq parameter should be used to boost the Query. @Abhijit Guha has an excellent answer, to use the same idea on the Field: qf (Query fields with optional boosts)

QueryOptions options = new QueryOptions
{
    ExtraParams = new KeyValuePair<string, string>[]
    {
        new KeyValuePair<string,string>("qt", "dismax"),
        new KeyValuePair<string,string>("qf", "title^1")
    },
    Rows = 10,
    Start = 0
};

Thank You!

Upvotes: 0

Related Questions