Solr: exact phrase query with a EdgeNGramFilterFactory

前端 未结 4 1080
谎友^
谎友^ 2021-02-04 17:06

In Solr (3.3), is it possible to make a field letter-by-letter searchable through a EdgeNGramFilterFactory and also sensitive to phrase queries?

By example,

4条回答
  •  别跟我提以往
    2021-02-04 17:59

    Exact phrase search does not work because of query slop parameter = 0 by default. Searching for a phrase '"Hello World"' it searches for terms with sequential positions. I wish EdgeNGramFilter had a parameter to control output positioning, this looks like an old question.

    By setting qs parameter to some very high value (more than maximum distance between ngrams) you can get phrases back. This partially solves problem allowing phrases, but not exact, permutations will be found as well. So that search for "contrat informatique" would match text like "...contract abandoned. Informatique..."

    enter image description here

    To support exact phrase query i end up to use separate fields for ngrams.

    Steps required:

    Define separate field types to index regular values and grams:

    
      
        
        
      
    
    
    
      
        
        
        
      
      
        
        
      
    
    

    Tell solr to copy fields when indexing:

    You can define separate ngrams reflection for each field:

    
    
    
    
    

    Or you can put all ngrams into one field:

    
    
    

    Note that you'll not be able to separate boosters in this case.

    And the last thing is to specify ngrams fields and boosters in the query. One way is to configure your application. Another way is to specify "appends" params in the solrconfig.xml

       
         heap_ngrams
       
    

提交回复
热议问题