Commit cdc2970038fe4d01da6052e72238177d1364adb6
1 parent
a62efa36
Exists in
master
and in
21 other branches
Added section on tags and dynamic synonyms - closes #788
Showing
1 changed file
with
23 additions
and
0 deletions
Show diff stats
README.md
... | ... | @@ -285,6 +285,29 @@ end |
285 | 285 | |
286 | 286 | Call `Product.reindex` after changing synonyms. |
287 | 287 | |
288 | +### Tags and Dynamic Synonyms | |
289 | + | |
290 | +The above approach works well when your synonym list is static, but in practice, this is often not the case. When you analyze search conversions, you often want to add new synonyms or tags without a full reindex. You can use a library like [ActsAsTaggableOn](https://github.com/mbleigh/acts-as-taggable-on) and do: | |
291 | + | |
292 | +```ruby | |
293 | +class Product < ActiveRecord::Base | |
294 | + acts_as_taggable_on | |
295 | + scope :search_import, -> { includes(:tags) } | |
296 | + | |
297 | + def search_data | |
298 | + { | |
299 | + name_tagged: "#{name} #{tags.map(&:name).join(" ")}" | |
300 | + } | |
301 | + end | |
302 | +end | |
303 | +``` | |
304 | + | |
305 | +Search with: | |
306 | + | |
307 | +```ruby | |
308 | +Product.search query, fields: [:name_tagged] | |
309 | +``` | |
310 | + | |
288 | 311 | ### WordNet |
289 | 312 | |
290 | 313 | Prepopulate English synonyms with the [WordNet database](https://en.wikipedia.org/wiki/WordNet). | ... | ... |