Class: Workarea::Search::SearchSuggestions

Inherits:
Object
  • Object
show all
Includes:
Query
Defined in:
app/queries/workarea/search/search_suggestions.rb

Instance Method Summary collapse

Methods included from Query

#additional_options, #aggregations, #body, #id, #initialize, #load_model_from, #loaded_results, #post_filter, #query_string, #response, #scroll, #stats, #total

Instance Method Details

#queryObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/queries/workarea/search/search_suggestions.rb', line 16

def query
  {
    bool: {
      must: [
        {
          match_phrase_prefix: {
            'content.name': {
              query: sanitized_string,
              max_expansions: 10
            }
          }
        },
        { term: { 'active.now' => true } }
      ]
    }
  }
end

#resultsObject



8
9
10
# File 'app/queries/workarea/search/search_suggestions.rb', line 8

def results
  response['hits']['hits']
end

#sanitized_stringObject



12
13
14
# File 'app/queries/workarea/search/search_suggestions.rb', line 12

def sanitized_string
  @sanitized_query ||= QueryString.new(params[:q]).sanitized
end

#sizeObject



38
39
40
# File 'app/queries/workarea/search/search_suggestions.rb', line 38

def size
  Workarea.config.search_suggestions
end

#sortObject



34
35
36
# File 'app/queries/workarea/search/search_suggestions.rb', line 34

def sort
  { type: :desc }
end