Search code examples
searchluceneazure-cognitive-search

The trouble with searching for a single-word sentence


I have a text field for tags. For example some entities:

{"tags": "apple. fruits. eat."}

{"tags": "green apple."}

{"tags": "banana. apple."}

I want to select entities with tag apple, not green apple or smth apple smth. Different variants lead to the one point: select a sentence with existing expression and it doesn't matter how this sentence looks like. But in this case it's matter. How can I do it by using Lucene syntax or Azure Search tools? Or (in general) how can I search for a completely same sentence?


Solution

  • I presume that the "." is a deliminator for the different tags. There may be a way to express this in lucene, but you may need to add some custom analyzers to preserve the "."'s in tokenization.

    A better strategy in this case would be use use a field of type Collection(Edm.String). This will allow you to better preserve structure the phrases for the tags, and you can use a filter to select the specific value of "apple". Collection(Edm.String) also allows you to enable faceting of the tags which is useful.