Multi-word synonym search in Solr

后端 未结 3 812
星月不相逢
星月不相逢 2021-02-10 00:52

I\'m trying to use a synonym filter to search for a phrase.

peter=> spider man, spiderman, Mary Jane, .....

I use the default configuration.

3条回答
  •  -上瘾入骨i
    2021-02-10 01:43

    My usually strategy for this kind of problem is to use the synonym filter not to expand a search to include all of the possible synonyms, but to normalize to a single form. I do this both in my index and query field analysis.

    For example, with this line in my fieldType/analyzer block in schema.xml:

    
    

    (Note the expand="false")
    ...and this line in my synonyms.txt:

    spiderman, spider man, Mary Jane => peter
    

    This way I make sure that any of these four values will be indexed and searched as "peter". For example, if the source document mentions "The Amazing Spider Man" it will be indexed as "The Amazing peter". When a user searches for "Mary Jane" it will search for "peter" instead, so it will match.

    The important thing here is that because "Mary" is not one of the comma-separated synonyms, it won't be changed if it appears without "Jane" following. So searching for "Mary is amazing" will actually search for "Mary is amazing", and it will not match the document.

    One of the important details, is that I choose a normalized form (e.g. "peter") that is only one word. I could organize it this way:

    peter, spiderman, spider man => Mary Jane
    

    but because Mary Jane is two words, it may (depending on other features of my search), match the two words separately as well as together. By choosing a single word form to normalize into, I make sure that my tokenizer won't try to break it up.

提交回复
热议问题