0

Wildcard search in luncene query syntax , the suffix with * is appened the word.I need for startwith like, eg1 : search : "associate*" should give me

[{
    "field1": "Associated for"
}, {
    "field1": "Associates for"
}, {
    "field1": "Associates word"
}]

but it returns

[{
    "field1": "you Associated for"
}, {
    "field1": "Associates for"
}, {
    "field1": "word Associates with"
}]

Can any one help me to find a solution for this.

eg2 : "search":"word associate*"

Result expected

[{
    "field1": "word Associated"
}, {
    "field1": "word Associated are"
}, {
    "field1": "word Associates with"
}]

if i use a keyword analyser it gives me result as expected for eg1 but for eg: ( "search":"associates for*") search gave me

[{
    "field1": "forest are located"
}, {
    "field1": "fort are build with"
}, {
    "field1": "fore are"
}]

Result expected

[{
    "field1": "Associates for"
}, {
    "field1": "Associates for abc"
}, {
    "field1": "Associates for xyz"
}]
Nayana
  • 1
  • 1

1 Answers1

1

The result (although is not what you need) is correct. You're searching for documents where "field1" contains associate*

so

"field1":"you Associated for" and "field1":"word Associates with" are correct.

You can find a good explanation in here https://stackoverflow.com/a/57703999/1384539

To produce what you want, you need to use keyword analyzer so that the entire field1 value is tokenized into a single token.

https://learn.microsoft.com/en-us/azure/search/index-add-custom-analyzers

As another option you try using Regular Expression, but I'm afraid it can be expensive depending on the number of documents you have in your index.

https://learn.microsoft.com/en-us/azure/search/query-lucene-syntax?redirectedfrom=MSDN#bkmk_regex

enter image description here

Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90
  • Thank you Thiago Custodio for help. if i use keyword analyser for eg : "Search":"associate*" for this search it give me the result as expected. but for "Search":"word associate*" gives me wrong result (request you to check my edited question). i need to search like as i type a letter search should result startwith value from index (autocomplete basically) – Nayana Jan 23 '20 at 06:33
  • it's the way default analyzer works. In other words, you're asking for "for*" or "associates". – Thiago Custodio Jan 23 '20 at 14:34