3

Using Azure search in Sitecore 9.1.1. We are getting extra results in Azure search only, with Solr results are showing correctly.

Scenario:

Fetching result from the below structure :

enter image description here

When we try to fetch result by passing 1999 in Azure search then it shows result for Data 1999 folder as well. If we pass 1998 then result shows for 1998 only, it also works when we pass Data 1999. Issue is with 1999 only, getting these results while passing 1999 in Azure search:

Test 1
Test 2
Test 3

Instead of

Test 1
Test 2

Using code :

predicate = predicate.And(x => x.Year.Equals(Year));

8
  • Could you provide the code that you are using for the request? looks like you are using Contains function. In that case, it will be no difference for Search Engine between Data 1999 and 1999 folders Commented Mar 3, 2021 at 10:49
  • Also, Sitecore Query Mapper for Azure Search is very poor and has many limitations. Especially for string it all times using Contains. Also in a case when you using Equals function. Provide more information and then I can answer on your question Commented Mar 3, 2021 at 10:57
  • I have updated my question and using Equals operator for this.
    – User7864
    Commented Mar 3, 2021 at 10:59
  • How is your configuration defined for the year field? If you are trying to search by year on those items isn't it better to have a date field on each of them? Commented Mar 3, 2021 at 11:37
  • 1
    I would try to change those folders to be years not string like 'Data 1999' or have a year field directly on the Test item template. Otherwise you need a computed field created as Vadim wrote Commented Mar 3, 2021 at 14:52

1 Answer 1

7

I had a bit same case in my project. When I investigated how Azure Search works underhood I found that string types all times converted to Contains query in Azure Search. You can see that if taking a look into Search.log for your environment.

The same issue with the StartsWith() function and etc. check this link:

In your case I see some scenarios to resolving this issue:

  1. Make a computed field/change type of field year on any numeric type. That can be int. (Equals for numeric types works well)
  2. Switch to Solr (it will take 1-day max but will save a lot of time with Search work). Anyway, the azure search will be deprecated in the next version of Sitecore. Check this link.
  3. Use straight requests to Azure Search instead of Sitecore LINQ provider. There exists an Equals function that can be used. (take a lot of time for rewriting and hard to support solution like this)
  4. Take a look at the Wildcard() LINQ function that allows using Search Engine syntaxis for field requests. Probably it will help too.

My experience with Azure Search was a nightmare till we didn't switch to Solr Engine in all environments and removed Azure-related things from a project (before we had Azure Search for production and Solr for development). Because they're a lot of limitations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.