Last active
          December 19, 2015 02:09 
        
      - 
      
 - 
        
Save christopherstyles/5881262 to your computer and use it in GitHub Desktop.  
    Tire configuration for partial word matching.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | tire.search(tire_params, load: true) do | |
| query do | |
| # Assumes +term+ is the text you're searching for | |
| string term, default_field: 'title', default_operator: 'AND' | |
| match :title, term, type: 'phrase_prefix', max_expansions: 10 | |
| end | |
| end | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | tire.settings analysis: { | |
| analyzer: { | |
| full_title: { | |
| filter: %w(standard lowercase asciifolding), | |
| type: 'custom', | |
| tokenizer: 'standard' | |
| }, | |
| partial_title: { | |
| filter: %w(standard lowercase asciifolding title_ngram), | |
| type: 'custom', | |
| tokenizer: 'standard' | |
| } | |
| }, | |
| filter: { | |
| title_ngram: { | |
| side: 'front', | |
| max_gram: 20, | |
| min_gram: 2, | |
| type: 'edgeNGram', | |
| token_chars: %w(letter digit whitespace) | |
| } | |
| } | |
| } do | |
| tire.mapping do | |
| indexes :title, type: 'string', index_analyzer: 'partial_title', | |
| search_analyzer: 'full_title' | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment