Class: MultiSearchIndex

Inherits:
Chewy::Index
  • Object
show all
Defined in:
app/models/multi_search_index.rb

Overview

Definition of ElasticSearch index for the /search resource.

Defined Under Namespace

Classes: SearchResult

Constant Summary collapse

DEFAULT_OPTS =
{
  index_analyzer: 'standard_ascii_engram',
  search_analyzer: 'standard_ascii',
  include_in_all: false
}

Class Method Summary collapse

Class Method Details

.search(str, offset: 0, limit: 10) ⇒ Array<SearchResult>

Search courses, people and rooms with the given string in ID or title.

Parameters:

  • str (String)

    a string to search.

  • offset (Integer) (defaults to: 0)
  • limit (Integer) (defaults to: 10)

Returns:


59
60
61
62
63
64
65
66
# File 'app/models/multi_search_index.rb', line 59

def self.search(str, offset: 0, limit: 10)
  transform_result query(multi_match: {
    query: str,
    type: 'best_fields',
    fields: %w[course.id^2 course.title person.id person.last_name person.title room.id],
    operator: 'and'
  }).only(:id, :title).limit(limit).offset(offset)
end