QueryRequest in Litium 8

How can I convert the following SearchQuery in Litium 7 to work in a similar way in Litium 8.

var request = new QueryRequest(_language.SystemId, ProductCatalogSearchDomains.Products, _securityToken);
request?.QueryTags?.Add(new Tag(TagNames.BaseProductId, item.Code + "*"));

var hits = Solution.Instance.SearchService.Search(request)?.Hits;

Litium version: 8.7.0

Hi,

First of all BaseProductId is not indexed in standard implementation of the accelerators elastic search. You have to index it via extending Litium.Accelerator.Search.ProductDocument (in Litium.Accelerator.Elasticsearch project) with BaseProductId and setting it while indexing. Do not forget rebuild the indices offline after your changes.

Then you can use something like following in order to search (see SearchQueryBilder of elastic saerchs ProductSearchServiceDecorator:

allQueries.Add(qc.Match(x => x.Field(z => z.BaseProductId).Query(item.Code).Fuzziness(Fuzziness.Auto)));

You can experiment with some boosting and different analysers if you don’t get the expected result.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.