admin管理员组

文章数量:1279050

I have cosmos document with name "Test Only"

There is search index created on the cosmos.

when I am searching with search text "olly~1 AND olly~1" getting above record.

Below is the code block

var client = new SearchClient(new Uri(searchServiceEndpoint), indexName, new DefaultAzureCredential());

string fuzzySearchText = "olly~1 AND olly~1";

var options = new SearchOptions
{
    SearchMode = SearchMode.All, // Ensures all terms should be considered
    QueryType = SearchQueryType.Full, // Allows fuzzy searching
    IncludeTotalCount = true
};

var results = await client.SearchAsync<dynamic>(fuzzySearchText, options);

I need result that the record "Test Only" should no match with "olly~1 AND olly~1".

Any suggestion?.

I have cosmos document with name "Test Only"

There is search index created on the cosmos.

when I am searching with search text "olly~1 AND olly~1" getting above record.

Below is the code block

var client = new SearchClient(new Uri(searchServiceEndpoint), indexName, new DefaultAzureCredential());

string fuzzySearchText = "olly~1 AND olly~1";

var options = new SearchOptions
{
    SearchMode = SearchMode.All, // Ensures all terms should be considered
    QueryType = SearchQueryType.Full, // Allows fuzzy searching
    IncludeTotalCount = true
};

var results = await client.SearchAsync<dynamic>(fuzzySearchText, options);

I need result that the record "Test Only" should no match with "olly~1 AND olly~1".

Any suggestion?.

Share Improve this question edited Feb 27 at 15:08 Sampath 3,6592 gold badges6 silver badges24 bronze badges Recognized by Microsoft Azure Collective asked Feb 24 at 11:17 user29776536user29776536 11 bronze badge 1
  • Instead of ~1, you can remove it or set it to ~0 – Sampath Commented Feb 26 at 9:34
Add a comment  | 

1 Answer 1

Reset to default 0

Fuzzy search (~1) allows for a one-character difference, meaning "olly~1" can match "only" due to their similarity.

To prevent "Test Only" from matching "olly~1" and "olly1", you can try the following steps:

  • Using Full enables the full Lucene query syntax, which sometimes leads to unexpected matches.
QueryType = SearchQueryType.Simple

Instead of ~1, you can remove it or set it to ~0 (exact match). Modify:

string fuzzySearchText = "olly AND olly";

(or)

string fuzzySearchText = "olly~0 AND olly~0";

A value of ~0 signifies no expansion (only the exact term is considered a match). However, you can specify ~1 to allow for one character difference (one edit distance).

For example, "blue~" or "blue~1" would return matches like "blue", "blues", and "glue".

Refer to this MSDOC for information on Fuzzy Search in Azure AI Search. Also, check out this MSDOC to learn how to perform searches using Azure SDKs in Azure AI Search.

Below is the code

var client = new SearchClient(new Uri(searchServiceEndpoint), indexName, new DefaultAzureCredential());

string fuzzySearchText = "olly AND olly";

var options = new SearchOptions
{
    SearchMode = SearchMode.Any, 
    QueryType = SearchQueryType.Simple,
    IncludeTotalCount = true
};

var results = await client.SearchAsync<dynamic>(fuzzySearchText, options);

Output:

本文标签: Azure AI searchFuzzy search with same terms one char dfferenceStack Overflow