Class: Zinx::Client
Constant Summary
Sphinx::Client::SEARCHD_COMMAND_EXCERPT, Sphinx::Client::SEARCHD_COMMAND_KEYWORDS, Sphinx::Client::SEARCHD_COMMAND_SEARCH, Sphinx::Client::SEARCHD_COMMAND_UPDATE, Sphinx::Client::SEARCHD_ERROR, Sphinx::Client::SEARCHD_OK, Sphinx::Client::SEARCHD_RETRY, Sphinx::Client::SEARCHD_WARNING, Sphinx::Client::SPH_ATTR_BIGINT, Sphinx::Client::SPH_ATTR_BOOL, Sphinx::Client::SPH_ATTR_FLOAT, Sphinx::Client::SPH_ATTR_INTEGER, Sphinx::Client::SPH_ATTR_MULTI, Sphinx::Client::SPH_ATTR_MULTI64, Sphinx::Client::SPH_ATTR_ORDINAL, Sphinx::Client::SPH_ATTR_STRING, Sphinx::Client::SPH_ATTR_TIMESTAMP, Sphinx::Client::SPH_FILTER_FLOATRANGE, Sphinx::Client::SPH_FILTER_RANGE, Sphinx::Client::SPH_FILTER_VALUES, Sphinx::Client::SPH_GROUPBY_ATTR, Sphinx::Client::SPH_GROUPBY_ATTRPAIR, Sphinx::Client::SPH_GROUPBY_DAY, Sphinx::Client::SPH_GROUPBY_MONTH, Sphinx::Client::SPH_GROUPBY_WEEK, Sphinx::Client::SPH_GROUPBY_YEAR, Sphinx::Client::SPH_MATCH_ALL, Sphinx::Client::SPH_MATCH_ANY, Sphinx::Client::SPH_MATCH_BOOLEAN, Sphinx::Client::SPH_MATCH_EXTENDED, Sphinx::Client::SPH_MATCH_EXTENDED2, Sphinx::Client::SPH_MATCH_FULLSCAN, Sphinx::Client::SPH_MATCH_PHRASE, Sphinx::Client::SPH_RANK_BM25, Sphinx::Client::SPH_RANK_NONE, Sphinx::Client::SPH_RANK_PROXIMITY, Sphinx::Client::SPH_RANK_PROXIMITY_BM25, Sphinx::Client::SPH_RANK_WORDCOUNT, Sphinx::Client::SPH_SORT_ATTR_ASC, Sphinx::Client::SPH_SORT_ATTR_DESC, Sphinx::Client::SPH_SORT_EXPR, Sphinx::Client::SPH_SORT_EXTENDED, Sphinx::Client::SPH_SORT_RELEVANCE, Sphinx::Client::SPH_SORT_TIME_SEGMENTS, Sphinx::Client::VER_COMMAND_EXCERPT, Sphinx::Client::VER_COMMAND_KEYWORDS, Sphinx::Client::VER_COMMAND_SEARCH, Sphinx::Client::VER_COMMAND_UPDATE
Class Attribute Summary collapse
Class Method Summary
collapse
-
.add_query ⇒ Object
add query for multiple queries.
-
.build_excerpts(docs, index, words, opts = {}) ⇒ Object
-
.build_keywords(query, index, hits) ⇒ Object
-
.excerpts(docs, words, opts = {}) ⇒ Object
-
.field_weight(field, weight) ⇒ Object
-
.filter(field, value, exclude = false) ⇒ Object
-
.filter_float_range(field, min, max, exclude = false) ⇒ Object
-
.filter_range(field, min, max, exclude = false) ⇒ Object
-
.geo_anchor(attr_lat, attr_lng, lat, lng) ⇒ Object
-
.group(mode, value) ⇒ Object
-
.group_distinct(field) ⇒ Object
-
.id_range(min, max) ⇒ Object
-
.index_weight(index, weight) ⇒ Object
-
.init(params = {}) ⇒ Object
-
.last_error ⇒ Object
-
.last_warning ⇒ Object
-
.limits(offset, limit, max = 0, cutoff = 0) ⇒ Object
-
.match_mode(mode) ⇒ Object
-
.matches ⇒ Object
syntax sugar for results.matches when using only one query you don’t even have to call ‘run’ before using this.
-
.max_query_time(time) ⇒ Object
-
.override(field, type, values) ⇒ Object
-
.ranking_mode(mode) ⇒ Object
-
.reset ⇒ Object
-
.reset_filters ⇒ Object
-
.reset_groups ⇒ Object
-
.reset_overrides ⇒ Object
-
.retries(count, delay = 0) ⇒ Object
-
.run ⇒ Object
must call run before accessing search results.
-
.search(query, params = {}) {|_self| ... } ⇒ Object
Entry point for searches Valid params are: :server => Sphinx server address (defaults to ‘localhost’) :port => Sphinx port number (defaults to 9312) :match_mode => Sphinx matching mode (defaults to Zinx::SPH_MATCH_EXTENDED) :index_name => Name of the index to search on.
-
.select(value) ⇒ Object
-
.server(host, port) ⇒ Object
-
.sort(mode, value = '') ⇒ Object
-
.update(index, attrs, values, mva = false) ⇒ Object
#AddQuery, #BuildExcerpts, #BuildKeywords, #GetLastError, #GetLastWarning, #Query, #ResetFilters, #ResetGroupBy, #ResetOverrides, #RunQueries, #SetFieldWeights, #SetFilter, #SetFilterFloatRange, #SetFilterRange, #SetGeoAnchor, #SetGroupBy, #SetGroupDistinct, #SetIDRange, #SetIndexWeights, #SetLimits, #SetMatchMode, #SetMaxQueryTime, #SetOverride, #SetRankingMode, #SetRetries, #SetSelect, #SetServer, #SetSortMode, #SetWeights, #UpdateAttributes, #initialize
Constructor Details
This class inherits a constructor from Sphinx::Client
Class Attribute Details
.client ⇒ Object
8
9
10
|
# File 'lib/zinx.rb', line 8
def client
@client
end
|
.field_weights(hash) ⇒ Object
8
9
10
|
# File 'lib/zinx.rb', line 8
def field_weights
@field_weights
end
|
.index_name ⇒ Object
8
9
10
|
# File 'lib/zinx.rb', line 8
def index_name
@index_name
end
|
.index_weights(hash) ⇒ Object
8
9
10
|
# File 'lib/zinx.rb', line 8
def index_weights
@index_weights
end
|
.multiple_queries ⇒ Object
8
9
10
|
# File 'lib/zinx.rb', line 8
def multiple_queries
@multiple_queries
end
|
.query ⇒ Object
8
9
10
|
# File 'lib/zinx.rb', line 8
def query
@query
end
|
.results ⇒ Object
8
9
10
|
# File 'lib/zinx.rb', line 8
def results
@results
end
|
Class Method Details
.add_query ⇒ Object
add query for multiple queries
174
175
176
177
|
# File 'lib/zinx.rb', line 174
def add_query
@multiple_queries = true
@client.AddQuery(@query, @index_name)
end
|
.build_excerpts(docs, index, words, opts = {}) ⇒ Object
122
123
124
125
|
# File 'lib/zinx.rb', line 122
def build_excerpts(docs, index, words, opts = {})
init
@client.BuildExcerpts(docs, index, words, opts)
end
|
.build_keywords(query, index, hits) ⇒ Object
132
133
134
135
|
# File 'lib/zinx.rb', line 132
def build_keywords(query, index, hits)
init
@client.BuildKeywords(query, index, hits)
end
|
.excerpts(docs, words, opts = {}) ⇒ Object
127
128
129
130
|
# File 'lib/zinx.rb', line 127
def excerpts(docs, words, opts = {})
run if @results.empty?
@client.BuildExcerpts(docs, @index_name, words, opts)
end
|
.field_weight(field, weight) ⇒ Object
72
73
74
|
# File 'lib/zinx.rb', line 72
def field_weight(field, weight)
@field_weights[field] = weight
end
|
.filter(field, value, exclude = false) ⇒ Object
16
17
18
|
# File 'lib/zinx.rb', line 16
def filter(field, value, exclude = false)
@client.SetFilter(field, value.instance_of?(Array) ? value : [value], exclude)
end
|
.filter_float_range(field, min, max, exclude = false) ⇒ Object
24
25
26
|
# File 'lib/zinx.rb', line 24
def filter_float_range(field, min, max, exclude = false)
@client.SetFilterFloatRange(field, min, max, exclude)
end
|
.filter_range(field, min, max, exclude = false) ⇒ Object
20
21
22
|
# File 'lib/zinx.rb', line 20
def filter_range(field, min, max, exclude = false)
@client.SetFilterRange(field, min, max, exclude)
end
|
.geo_anchor(attr_lat, attr_lng, lat, lng) ⇒ Object
92
93
94
|
# File 'lib/zinx.rb', line 92
def geo_anchor(attr_lat, attr_lng, lat, lng)
@client.Set(attr_lat, attr_lng, lat, lng)
end
|
.group(mode, value) ⇒ Object
32
33
34
|
# File 'lib/zinx.rb', line 32
def group(mode, value)
@client.SetGroupBy(value, mode)
end
|
.group_distinct(field) ⇒ Object
36
37
38
|
# File 'lib/zinx.rb', line 36
def group_distinct(field)
@client.SetGroupDistinct(field)
end
|
.id_range(min, max) ⇒ Object
88
89
90
|
# File 'lib/zinx.rb', line 88
def id_range(min, max)
@client.SetIDRange(min, max)
end
|
.index_weight(index, weight) ⇒ Object
80
81
82
|
# File 'lib/zinx.rb', line 80
def index_weight(index, weight)
@index_weights[index] = weight
end
|
.init(params = {}) ⇒ Object
192
193
194
195
196
197
198
199
200
201
202
|
# File 'lib/zinx.rb', line 192
def init(params = {})
@client = Client.new
@client.SetServer(params[:server] || 'localhost', params[:port] || 9312)
@client.SetMatchMode(params[:match_mode] || Zinx::Client::SPH_MATCH_EXTENDED)
@query = params[:query]
@index_name = params[:index_name] || "*"
@multiple_queries = false
@results = []
@field_weights = {}
@index_weights = {}
end
|
.last_error ⇒ Object
44
45
46
|
# File 'lib/zinx.rb', line 44
def last_error
@client.GetLastError
end
|
.last_warning ⇒ Object
48
49
50
|
# File 'lib/zinx.rb', line 48
def last_warning
@client.GetLastWarning
end
|
.limits(offset, limit, max = 0, cutoff = 0) ⇒ Object
56
57
58
|
# File 'lib/zinx.rb', line 56
def limits(offset, limit, max = 0, cutoff = 0)
@client.SetLimits(offset, limit, max, cutoff)
end
|
.match_mode(mode) ⇒ Object
64
65
66
|
# File 'lib/zinx.rb', line 64
def match_mode(mode)
@client.SetMatchMode(mode)
end
|
.matches ⇒ Object
syntax sugar for results.matches when using only one query you don’t even have to call ‘run’ before using this
148
149
150
151
|
# File 'lib/zinx.rb', line 148
def matches
run if @results.empty?
!@multiple_queries && @results.count > 0 ? @results[0].matches : []
end
|
.max_query_time(time) ⇒ Object
60
61
62
|
# File 'lib/zinx.rb', line 60
def max_query_time(time)
@client.SetMaxQueryTime(time)
end
|
.override(field, type, values) ⇒ Object
100
101
102
|
# File 'lib/zinx.rb', line 100
def override(field, type, values)
@client.SetOverride(field, type, values)
end
|
.ranking_mode(mode) ⇒ Object
68
69
70
|
# File 'lib/zinx.rb', line 68
def ranking_mode(mode)
@client.SetRankingMode(mode)
end
|
.reset ⇒ Object
104
105
106
107
108
|
# File 'lib/zinx.rb', line 104
def reset
@client.ResetFilters
@client.ResetGroupBy
@client.ResetOverrides
end
|
.reset_filters ⇒ Object
110
111
112
|
# File 'lib/zinx.rb', line 110
def reset_filters
@client.ResetFilters
end
|
.reset_groups ⇒ Object
114
115
116
|
# File 'lib/zinx.rb', line 114
def reset_groups
@client.ResetGroupBy
end
|
.reset_overrides ⇒ Object
118
119
120
|
# File 'lib/zinx.rb', line 118
def reset_overrides
@client.ResetOverrides
end
|
.retries(count, delay = 0) ⇒ Object
96
97
98
|
# File 'lib/zinx.rb', line 96
def retries(count, delay = 0)
@client.SetRetries(count, delay)
end
|
.run ⇒ Object
must call run before accessing search results
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# File 'lib/zinx.rb', line 154
def run
@client.SetFieldWeights(@field_weights) unless @field_weights.empty?
@client.SetIndexWeights(@index_weights) unless @index_weights.empty?
if @multiple_queries
q = @client.RunQueries
q.each do |result|
@results << Result.new(result)
end
@results
else
q = @client.Query(@query, @index_name)
@results << Result.new(q)
@results.first
end
end
|
.search(query, params = {}) {|_self| ... } ⇒ Object
Entry point for searches Valid params are: :server => Sphinx server address (defaults to ‘localhost’)
:port => Sphinx port number (defaults to 9312)
:match_mode => Sphinx matching mode (defaults to Zinx::SPH_MATCH_EXTENDED)
:index_name => Name of the index to search on
185
186
187
188
189
190
|
# File 'lib/zinx.rb', line 185
def search(query, params = {}, &block)
params[:query] = query
init(params)
yield self if block_given?
run
end
|
.select(value) ⇒ Object
40
41
42
|
# File 'lib/zinx.rb', line 40
def select(value)
@client.SetSelect(value)
end
|
.server(host, port) ⇒ Object
52
53
54
|
# File 'lib/zinx.rb', line 52
def server(host, port)
@client.SetServer(host, port)
end
|
.sort(mode, value = '') ⇒ Object
28
29
30
|
# File 'lib/zinx.rb', line 28
def sort(mode, value = '')
@client.SetSortMode(mode, value)
end
|
.update(index, attrs, values, mva = false) ⇒ Object
137
138
139
140
|
# File 'lib/zinx.rb', line 137
def update(index, attrs, values, mva = false)
init
@client.UpdateAttributes(index, attrs, values, mva)
end
|