Class: GamesSearch

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/searches/games_search.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#not_idObject

Returns the value of attribute not_id


16
17
18
# File 'app/searches/games_search.rb', line 16

def not_id
  @not_id
end

#platformObject

Returns the value of attribute platform


14
15
16
# File 'app/searches/games_search.rb', line 14

def platform
  @platform
end

#queryObject

attribute :query, type: String attribute :author_id, type: Integer attribute :min_year, type: Integer attribute :max_year, type: Integer attribute :tags, mode: :arrayed, type: String, normalize: ->(value) { value.reject(&:blank?) } attribute :sort, type: String, enum: %w(title year relevance), default_blank: 'relevance'


13
14
15
# File 'app/searches/games_search.rb', line 13

def query
  @query
end

#typeObject

Returns the value of attribute type


15
16
17
# File 'app/searches/games_search.rb', line 15

def type
  @type
end

Instance Method Details

#allObject

def sorting index.order(SORT) end


48
49
50
51
52
53
54
55
56
# File 'app/searches/games_search.rb', line 48

def all
	if platform.present?
		index.query(match: {
			platform_id: platform
		})
	else
		index.filter{ match_all }
	end
end

#editions_countObject


40
41
42
# File 'app/searches/games_search.rb', line 40

def editions_count
	index.filter({ type: { value: "edition"}}).search_type(:count)
end

#expansions_countObject


37
38
39
# File 'app/searches/games_search.rb', line 37

def expansions_count
	index.filter({ type: { value: "expansion"}}).search_type(:count)
end

#indexObject

def tag_list self.tags.join(', ') end


28
29
30
# File 'app/searches/games_search.rb', line 28

def index
	GamesIndex
end

#index_queryObject


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/searches/games_search.rb', line 82

def index_query
	index.query(bool: {
			should: [
				{
					multi_match: {
						fields: [:title],# :author, :description],
						query: query,
						operator: "AND"
					}
				},
				{
					multi_match: {
						fields: [:title],#, :author, :description],
						query: query,
						fuzziness: "AUTO",
						operator: "AND"
					}
				}
			]
		}
	) if query.present?
end

#platform_queryObject


74
75
76
77
78
79
80
# File 'app/searches/games_search.rb', line 74

def platform_query
	if platform.present?
		index_query.filter(term: {platform_id: platform})
	else
		index_query
	end
end

#query_stringObject


58
59
60
61
62
63
64
# File 'app/searches/games_search.rb', line 58

def query_string
	if not_id.present?
		type_query.filter({not: {ids: {values: [not_id]}}})
	else
		type_query
	end
end

#searchObject


32
33
34
35
# File 'app/searches/games_search.rb', line 32

def search	#[query_string, author_id_filter, year_filter, tags_filter, sorting].compact.reduce(:merge)

	query_string
end

#type_queryObject


66
67
68
69
70
71
72
# File 'app/searches/games_search.rb', line 66

def type_query
	if type.present?
		platform_query.filter({type: {value: type}})
	else
		platform_query
	end
end