Module: Polysearch::Searchable::ClassMethods
- Defined in:
- app/models/polysearch/searchable.rb
Instance Method Summary collapse
- #fts_string(value) ⇒ Object
- #fts_words(value) ⇒ Object
- #ngrams(value, min: 1, max: 24) ⇒ Object
- #sanitize_sql_value(value) ⇒ Object
Instance Method Details
#fts_string(value) ⇒ Object
21 22 23 24 25 |
# File 'app/models/polysearch/searchable.rb', line 21 def fts_string(value) value = fts_words(value).join(" ") value = value.chop while value.bytes.size > 2046 value end |
#fts_words(value) ⇒ Object
17 18 19 |
# File 'app/models/polysearch/searchable.rb', line 17 def fts_words(value) Loofah.fragment(value.to_s).scrub!(:whitewash).to_text.gsub(/\W/, " ").squeeze(" ").downcase.split end |
#ngrams(value, min: 1, max: 24) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'app/models/polysearch/searchable.rb', line 8 def ngrams(value, min: 1, max: 24) value = value.to_s Set.new.tap do |set| (min..max).each do |num| value.scan(/\w{#{num}}/).each { |item| set << item } end end.to_a end |
#sanitize_sql_value(value) ⇒ Object
27 28 29 |
# File 'app/models/polysearch/searchable.rb', line 27 def sanitize_sql_value(value) sanitize_sql_array ["?", value] end |