0

What I need to achive is left side match. I'm using Query Type full. Please find my model and analyzer below:

public class Product
{
    [System.ComponentModel.DataAnnotations.Key]
    public string Id { get; set; }

    [IsSearchable, Analyzer("polish_analyzer")]
    public string Name { get; set; }
}

Analyzers = new[]
{
    new CustomAnalyzer()
    {
        Name="polish_analyzer",
        Tokenizer = "polish_tokenizer",
        TokenFilters = new TokenFilterName[] {"lowercase", "asciifolding" }
    }
},
Tokenizers = new[]
{
    new MicrosoftLanguageStemmingTokenizer()
    {
        Language = MicrosoftStemmingTokenizerLanguage.Polish,
        IsSearchTokenizer = true,
        Name = "polish_tokenizer"
    }
}

I've added doucment { Id = "1", Name = "Łódka" } to the index, created based on Product class.

For search query "Lod*" document with id 1 is being returned but search query "Łód*" deosn't return any result. I've checked "polish_analyzer" and for text "Łódka" it returns token "lodka". My second approach was to use EdgeNGramTokenFilterV2, and add it to TokenFilters:

new EdgeNGramTokenFilterV2()
{
    MaxGram=300,
    MinGram=1,
    Name="token_edge"
}

With EdgeNGramTokenFilterV2 I don't have to use '*' and left side match is working fine for both cases "Łód", "Lod" but I don't know if this solution is efficient as analyzer with EdgeNGramTokenFilterV2 token filter produces a lot of tokens.

Does anybody know why left side match is not working in the first case? Or if second approch is efficient?

mbiernatek
  • 37
  • 8

1 Answers1

1

Your prefix query doesn't return any results because lexical analyzers are not applied on prefix query terms, you can learn more here: Exceptions to lexical analysis

Prefix matching will be much more efficient if you used the edge ngram token filter and you can combine it with the Polish stemming tokenizer.

With two fields processed differently for exact term matching and prefix matching, you can use field-scoped queries to search against both:

search=NameExact:Łódź NamePrefix:Łód&queryType=full
Yahnoosh
  • 1,932
  • 1
  • 11
  • 13