Search query FilterTags

Hi

I need to check either one of the two String fields has value in search query.

I tried two ways, but found its wrong

  1. ExcludeTagClause
request.FilterTags.Add (new ExcludeTagClause (new [] 
{ 
new Tag (NordicFeelFieldNames.SustainableBeauty.GetFieldDefinitionForProducts (). GetTagName (), String.Empty), 
new Tag (NordicFeelFieldNames. Certificate.GetFieldDefinitionForProducts (). GetTagName (), String.Empty 
}})); 
  1. OptionalTagClause
request.FilterTags.Add (new OptionalTagClause (new [] 
{ 
new Tag (NordicFeelFieldNames.SustainableBeauty.GetFieldDefinitionForProducts (). GetTagName (), "*"),
new tag (NordicFeelFieldNames.Certificate.GetFieldDefinitionForProducts (). GetTagName (), "*") 
})); 
  1. Search index will not include data that not is set, example null values. Also back office often translate empty string into null of properties when they are stored.

  2. Searching for everything like wildcard searches or strings that’s start with wildcard is the best way to kill performance in the search. Please avoid that! And when you search you can not only have wildcard, you also need another character before or after the wildcard.

@patric.forsgard Would it be possible to use the Data service in this case? The documentation on https://docs.litium.com/documentation/architecture/data-service is somewhat lacking so it would be helpful if you could give some pointers and improve the documentation.

@hans, you may use the data service for what you want to do. Right now the question is only a little code fragment and it is hard to answer about alternative ways of doing what the same thing that @nmshkjhn trying to do.

To remember is that data service is touching the database for every execution and that is something that a public website should avoid for the performance.

Ok, thanks. So what operators can we use for retrieving all products which have any (non-empty) value in at least one of two string fields?

With the search index or the data query?

The data query.

It’s little hard to write a query that I know will work for you but I think something like this should work

using (var query = _dataService.CreateQuery<Variant>())
{
    var systemIds = query.Filter(f => f.Bool(b => b.Should(x => x
        .Field("SustainableBeauty", "any", CultureInfo.CurrentCulture, null)
        .Field("Certificate", "any", CultureInfo.CurrentCulture, null))))
        .ToSystemIdList();

    var variants = _variantService.Get(systemIds);
}