SuggestParameters add parameters to solr query that are related to suggester only (these parameters start with suggest.
prefix).
Simple example:
SolrSuggestQuery query = "acco";
var options = new SuggestHandlerQueryOptions
{
Parameters = new SuggestParameters
{
Count = 5
}
};
var result = context.Suggest(query, options);
This code snippet send to solr request:
/suggest?q=acco&fq=_indexname:(test_search_index)&suggest=true&suggest.count=5
with results:
{
"responseHeader":{
"status":0,
"QTime":0},
"suggest":{
"mySuggesterContent":{
"acco":{
"numFound":5,
"suggestions":[{
"term":"accordance",
"weight":6,
"payload":""},
{
"term":"according",
"weight":3,
"payload":""},
{
"term":"account",
"weight":71,
"payload":""},
{
"term":"account's",
"weight":1,
"payload":""},
{
"term":"accounts",
"weight":46,
"payload":""}]}}
}
When we change our example to following:
SolrSuggestQuery query = "acco";
var options = new SuggestHandlerQueryOptions
{
Parameters = new SuggestParameters
{
Count = 5,
Query = "bank"
}
};
var result = context.Suggest(query, options);
request to sorl will be:
/suggest?q=acco&fq=_indexname:(test_search_index)&suggest=true&suggest.count=5&suggest.q=bank
with results:
{
"responseHeader":{
"status":0,
"QTime":2},
"suggest":{
"mySuggesterContent":{
"bank":{
"numFound":5,
"suggestions":[{
"term":"bank",
"weight":93,
"payload":""},
{
"term":"bank's",
"weight":3,
"payload":""},
{
"term":"banker",
"weight":1,
"payload":""},
{
"term":"bankers",
"weight":2,
"payload":""},
{
"term":"banking",
"weight":55,
"payload":""}]}}
}
As you can see suggest.q
parameter has higher priority and best practice is you use it instead of q
parameter (because all parameter without suggest.
prefix are not interesting for suggester in general).
ContextFilterQuery.
Lets imagine that we have a lot of Product items and each product has category (like sport/food/etc). And we want to find product names in our suggester. But we also want to have an option to find suggested products only in specific category to make our suggestions more relevant.
To do it, we just need to add contextField
parameter in our suggester:
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">mySuggesterContent</str>
<str name="lookupImpl">AnalyzingInfixLookupFactory</str>
<str name="field">name</str>
<str name="weightField">price</str>
<str name="contextField">category</str>
<str name="suggestAnalyzerFieldType">string</str>
<str name="buildOnStartup">false</str>
</lst>
</searchComponent>
And when we change our example to following:
var options = new SuggestHandlerQueryOptions
{
Parameters = new SuggestParameters
{
Count = 5,
Query = "air",
ContextFilterQuery = "shoes"
}
};
request to solr will be:
/suggest?q=&fq=_indexname:(test_search_index)&suggest=true&suggest.count=5&suggest.q=air&suggest.cfq=shoes
with results like: airmax
etc. In this case you force prevent suggestions like airpods
etc, because they are not relevant for you case for some reasons (for example if your users have ability to check categories where they want to search only).