Skip to content

Instantly share code, notes, and snippets.

@christopherstyles
Last active December 19, 2015 02:09
Show Gist options
  • Save christopherstyles/5881262 to your computer and use it in GitHub Desktop.
Save christopherstyles/5881262 to your computer and use it in GitHub Desktop.
Tire configuration for partial word matching.
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
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