Method: Lcms::Engine::Search::Repository#tags_query

Defined in:
app/models/lcms/engine/search/repository.rb

#tags_query(term, tags, options) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'app/models/lcms/engine/search/repository.rb', line 159

def tags_query(term, tags, options)
  return term if term.respond_to?(:to_hash)

  limit = options.fetch(:per_page, 20)
  page = options.fetch(:page, 1)

  query = {
    query: {
      bool: {
        filter: [],
        should: tags.map { |t| { match: { t => term } } }.concat(
          [
            { match_phrase: { title: term } },
            { match_phrase: { teaser: term } }
          ]
        ),
        minimum_should_match: 1
      }
    },
    size: limit,
    from: (page - 1) * limit
  }

  apply_filters query, options
end