From cdc2970038fe4d01da6052e72238177d1364adb6 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Wed, 21 Dec 2016 17:21:10 -0800 Subject: [PATCH] Added section on tags and dynamic synonyms - closes #788 --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+), 0 deletions(-) diff --git a/README.md b/README.md index 0a3bad2..d47d59b 100644 --- a/README.md +++ b/README.md @@ -285,6 +285,29 @@ end Call `Product.reindex` after changing synonyms. +### Tags and Dynamic Synonyms + +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: + +```ruby +class Product < ActiveRecord::Base + acts_as_taggable_on + scope :search_import, -> { includes(:tags) } + + def search_data + { + name_tagged: "#{name} #{tags.map(&:name).join(" ")}" + } + end +end +``` + +Search with: + +```ruby +Product.search query, fields: [:name_tagged] +``` + ### WordNet Prepopulate English synonyms with the [WordNet database](https://en.wikipedia.org/wiki/WordNet). -- libgit2 0.21.0