Is my search query possible?

Marc Selman | EasyAds 1 Reputation point
2021-04-09T21:31:52.627+00:00

I have a document model that represents product data that looks something like this:

ProductId
UserId
Title/Value
Title/ChannelId
Brand/Value
Brand/ChannelId

A product can have a title and a brand.
The title and brand can differ for every channel the product would be listed on.
The default title and brand is if the ChannelId is NULL , that would always be there.
Optionally there could be a different title or brand with a valid ChannelId value.

What I want is to query the index with a string that would match either a brand or a title.
When I pass no ChannelId as a filter it should match only if ChannelId is NULL.
But when I do pass a ChannelId it should find documents where there's a match on title or brand with that specific ChannelId OR the document does not contain a specific value for that ChannelId and then it should match the default value with ChannelId NULL.

I found out I could do something like:

Title/any(title: title/ChannelId eq 14 and title/Value eq 'my query') or not Title/any(title: title/ChannelId eq 14) and Title/any(title: title/ChannelId eq null and title/Value eq 'my query')

But that would search for an exact match. I would like to use search.ismatch but that cannot be used inside a lamda query.

Maybe I am missing something and I am making it too complex...

Is this possible in any way?

I am currently working with a new index so if I should change the whole model and the fields that's not a problem.

Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
1,062 questions
{count} votes

1 answer

Sort by: Most helpful
  1. SnehaAgrawal-MSFT 21,691 Reputation points
    2021-04-12T15:47:04.08+00:00

    Thanks for asking question! Azure Cognitive Search implements two Lucene-based query languages: Simple Query Parser and the Lucene Query Parser. Check Filter Functions: Filter expressions can include "search.ismatch" and "search.ismatchscoring" functions, allowing you to build a search query within the filter.

    You may want to refer to this document link might helps: https://learn.microsoft.com/en-us/azure/search/search-query-odata-full-text-search-functions.

    Let us know if issue remains.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.