user2114049
user2114049

Reputation: 21

Azure search find Matching Text

How we can search a part of a text in a field index? For example: if I have a Invoicenumber filed in Index,Say InvoiceNumber ='INV04552'

if I enter search ='45' and searchFileds=InvoiceNumber it will not give any result but it gives the result when search='INV04552'.

I need to have result when search ='45' how I can fix this?

Upvotes: 0

Views: 1212

Answers (1)

Yahnoosh
Yahnoosh

Reputation: 1972

For searchable fields Azure Search supports exact matching and prefix matching (please read about the suffix operator '*' here: Simple query syntax. For filterable fields we only support exact matching.

At indexing time text in your documents is broken into terms. For example, if you use the standard (default), non-language-specific analyzer, this will be the list of terms generated for the second sentence in your question:

1: [for] 
2: [example] 
3: [if] 
4: [i] 
5: [have] 
6: [a] 
7: [invoicenumber] 
8: [filed] 
9: [in] 
10: [index] 
11: [say] 
12: [invoicenumber] 
13: [inv04552] 

If your query contains one of those terms, the document will be found. As you can see 'INV04552' is on the list but '45' is not. The standard analyzer uses the Unicode Text Segmentation algorithm to break the sentence into terms. In this case it was broken on each space, comma, and the '=' sign.

To work around this, if your invoice numbers follow a well-defined pattern, you can preprocess them before indexing by introducing a dash '-', or a space e.g., INV-04552. That what would tell the analyzer to break INV-04552 into two terms. As a result each would be searchable. Alternatively you could trim the first 3-4 characters of the invoice number and use prefix query to find '45' in the '4552'. This is only a valid solution if the first 4 characters are not meaningful.

Please let me know if this answers your question. I can provide more details if you're interested.

Upvotes: 1

Related Questions