Class: FullSearch::Search
- Inherits:
-
Object
- Object
- FullSearch::Search
- Defined in:
- lib/full_search/search.rb
Instance Attribute Summary collapse
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#highlight ⇒ Object
readonly
Returns the value of attribute highlight.
-
#highlight_fields ⇒ Object
readonly
Returns the value of attribute highlight_fields.
-
#include_soft_deleted ⇒ Object
readonly
Returns the value of attribute include_soft_deleted.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#matching_strategy ⇒ Object
readonly
Returns the value of attribute matching_strategy.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
-
#initialize(model, query, filters:, include_soft_deleted:, limit:, offset:, highlight: false, highlight_fields: false, matching_strategy: nil) ⇒ Search
constructor
A new instance of Search.
- #relation ⇒ Object
Constructor Details
#initialize(model, query, filters:, include_soft_deleted:, limit:, offset:, highlight: false, highlight_fields: false, matching_strategy: nil) ⇒ Search
Returns a new instance of Search.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/full_search/search.rb', line 7 def initialize(model, query, filters:, include_soft_deleted:, limit:, offset:, highlight: false, highlight_fields: false, matching_strategy: nil) @model = model @query = query.to_s.strip @filters = filters @include_soft_deleted = include_soft_deleted @limit = limit @offset = offset @highlight = highlight @highlight_fields = highlight_fields @matching_strategy = matching_strategy end |
Instance Attribute Details
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
5 6 7 |
# File 'lib/full_search/search.rb', line 5 def filters @filters end |
#highlight ⇒ Object (readonly)
Returns the value of attribute highlight.
5 6 7 |
# File 'lib/full_search/search.rb', line 5 def highlight @highlight end |
#highlight_fields ⇒ Object (readonly)
Returns the value of attribute highlight_fields.
5 6 7 |
# File 'lib/full_search/search.rb', line 5 def highlight_fields @highlight_fields end |
#include_soft_deleted ⇒ Object (readonly)
Returns the value of attribute include_soft_deleted.
5 6 7 |
# File 'lib/full_search/search.rb', line 5 def include_soft_deleted @include_soft_deleted end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
5 6 7 |
# File 'lib/full_search/search.rb', line 5 def limit @limit end |
#matching_strategy ⇒ Object (readonly)
Returns the value of attribute matching_strategy.
5 6 7 |
# File 'lib/full_search/search.rb', line 5 def matching_strategy @matching_strategy end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/full_search/search.rb', line 5 def model @model end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
5 6 7 |
# File 'lib/full_search/search.rb', line 5 def offset @offset end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
5 6 7 |
# File 'lib/full_search/search.rb', line 5 def query @query end |
Instance Method Details
#relation ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/full_search/search.rb', line 19 def relation validate_required_filters! parsed = QueryParser.parse(query) exact_ids = ExactMatch.ids_for(model, query, filters) primary_ids = fts_match_ids(parsed) fallback_ids = dsl.typo_tolerance? && matching_strategy != "all" ? trigram_match_ids(parsed, primary_ids) : [] fuzzy_ids = dsl.typo_tolerance? && matching_strategy != "all" && primary_ids.empty? && fallback_ids.empty? ? fuzzy_match_ids(parsed) : [] all_ids = (exact_ids + primary_ids + fallback_ids + fuzzy_ids).uniq return model.none if all_ids.empty? rel = model.where(id: all_ids) rel = rel.where(model.arel_table[dsl.soft_delete_column].eq(nil)) if dsl.soft_delete_column && !include_soft_deleted rel = rel.limit(limit) if limit rel = rel.offset(offset) if offset rel = apply_ranking(rel, all_ids, exact_ids) if highlight Highlighter.apply!(rel.to_a, model, query) elsif highlight_fields Highlighter.apply_fields!(rel.to_a, model, query) else rel end end |