How can I prioritize products in Elasticsearch results, is there a way that i can get the search result by changing the score or by adding tags?
Litium version 7.6.1
There is a boost attribute that should do it. But there is no backoffice to control it though.
So you would need to add a field somewhere to later add it when it sorts.
It depends on how you want to boost I guess. Could you explain the requirements a bit more?
You can apply Boost to a particular field to have hits from there be scored higher.
if (!string.IsNullOrWhiteSpace(searchQuery.Text))
{
allQueries.Add((qc.Match(x => x.Field(z => z.Name).Query(searchQuery.Text).Fuzziness(Fuzziness.Auto).Boost(10).SynonymAnalyzer())
|| qc.Match(x => x.Field(z => z.ArticleNumber).Query(searchQuery.Text.ToLower()).Boost(2))
|| qc.Match(x => x.Field(z => z.Content).Query(searchQuery.Text).Fuzziness(Fuzziness.Auto).SynonymAnalyzer())));
}
You can also add a boost if the field contains a specific value:
allQueries.Add((qc.Match(x => x.Field(z => z.Name).Query(searchQuery.Text).Fuzziness(Fuzziness.Auto).Boost(10).SynonymAnalyzer())
|| qc.Match(x => x.Field(z => z.ArticleNumber).Query(searchQuery.Text.ToLower()).Boost(2))
|| qc.Match(x => x.Field(z => z.Content).Query(searchQuery.Text).Fuzziness(Fuzziness.Auto).SynonymAnalyzer())
|| qc.Match(x => x.Field(z => z.Content).Query("my_value").Boost(100))));
You can filter on properties on the ProductDocument
itself, in this example a property InStock
has been added.
allQueries.Add(qc.Bool(b => b.Filter(bf => bf.Term(t => t.Field(x => x.InStock).Value(true)))));
You can also add a weight if a field contains a predetermined value. Here we are boosting a particular brand.
allQueries.Add(qc.Nested(n => n
.Path(p => p.Tags)
.Query(q => q
.FunctionScore(fs => fs
.Functions(fu => fu
.Weight(w => w
.Weight(42)
.Filter(wf => wf
.Term(t => t
.Field(f => f.Tags[0].Key).Value(BrandListViewModel.TagName)
.Field(f => f.Tags[0].Value).Value(boostedBrand)
))))))));
Thank You @Artur for the quick replay
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.