search.ismatch only matching with first letter in the search

155 Views Asked by At

I have an azure cognitive search index and I am using search.ismatch ODATA full text search function to return records that match a particular key work.

Data

  • Apple

  • Pineapple

    search.ismatch('apple', 'Text')

I am expecting the query to return both values but I am only getting 1. i.e. It only matches first letters in the word.

How to return the data regardless where the search text within the data?

1

There are 1 best solutions below

0
Rishabh Meshram On

One possible solution to search based on substring of text is by using ngarm tokenizer in your index schema.

index_definition = {
    "name": index_name,
    "fields": [
        {"name": "id", "type": "Edm.String", "key": True, "searchable": False},
        {
            "name": "Text",
            "type": "Edm.String",
            "searchable": True,
            "analyzer": "custom_analyzer",
        },
    ],
    "analyzers": [
        {
            "@odata.type": "#Microsoft.Azure.Search.CustomAnalyzer",
            "name": "custom_analyzer",
            "tokenizer": "custom_tokenizer",
            "tokenFilters": ["lowercase"],
        }
    ],
    "tokenizers": [
        {
            "@odata.type": "#Microsoft.Azure.Search.NGramTokenizer",
            "name": "custom_tokenizer",
            "minGram": 5,
            "maxGram": 5,
        }
    ],
}

With above schema I have uploaded the given sample data:

documents = [
    {"@search.action": "upload", "id": "1", "Text": "apple"},
    {"@search.action": "upload", "id": "2", "Text": "pineapple"},
]

With the above index definition and data, I was able to get the required results. enter image description here

Note: This is sample code for demonstration, you might to have to modify and reconfigure based on your requirement.

For more details related to partial search, you can check this documentation.