Spliced searches to separate call to handle limit issue (only usable for one query/request).

This commit is contained in:
Martin Edenhofer 2016-07-08 01:22:09 +02:00
parent 96fd35d1dd
commit 80a9fd5dab
2 changed files with 20 additions and 7 deletions

View file

@ -29,7 +29,7 @@
* rails r "Setting.set('es_attachment_ignore', [ '.png', '.jpg', '.jpeg', '.mpeg', '.mpg', '.mov', '.bin', '.exe', '.box', '.mbox' ] )"
# optional - max attachment size which is used by es, default is 50 mb
* rails r "Setting.set('es_attachment_max_size_in_mb', 50 )"
* rails r "Setting.set('es_attachment_max_size_in_mb', 50)"
* Create elastic search indexes

View file

@ -59,7 +59,7 @@ create/update/delete index
)
Rails.logger.info "# #{response.code}"
return true if response.success?
raise response.inspect
raise "Unable to proccess PUT at #{url}\n#{response.inspect}"
end
=begin
@ -91,7 +91,7 @@ add new object to search index
)
Rails.logger.info "# #{response.code}"
return true if response.success?
raise response.inspect
raise "Unable to proccess POST at #{url} (size: #{data.to_json.bytesize / 1024 / 1024}M)\n#{response.inspect}"
end
=begin
@ -121,7 +121,7 @@ remove whole data from index
)
Rails.logger.info "# #{response.code}"
return true if response.success?
#Rails.logger.info "NOTICE: can't drop index: " + response.inspect
#Rails.logger.info "NOTICE: can't delete index #{url}: " + response.inspect
false
end
@ -152,6 +152,19 @@ return search result
def self.search(query, limit = 10, index = nil, query_extention = {})
return [] if !query
if index.class == Array
ids = []
index.each { |local_index|
local_ids = search_by_index(query, limit, local_index, query_extention)
ids = ids.concat(local_ids)
}
return ids
end
search_by_index(query, limit, index, query_extention)
end
def self.search_by_index(query, limit = 10, index = nil, query_extention = {})
return [] if !query
url = build_url()
return if !url
@ -215,7 +228,7 @@ return search result
Rails.logger.info "# #{response.code}"
if !response.success?
Rails.logger.error "ERROR: #{response.inspect}"
Rails.logger.error "ERROR: POST on #{url}\n#{response.inspect}"
return []
end
data = response.data
@ -308,7 +321,7 @@ get count of tickets and tickets which match on selector
Rails.logger.info "# #{response.code}"
if !response.success?
raise "ERROR: #{response.inspect}"
raise "Unable to proccess POST at #{url}\n#{response.inspect}"
end
Rails.logger.debug response.data.to_json
@ -447,7 +460,7 @@ return true if backend is configured
def self.build_url(type = nil, o_id = nil)
return if !SearchIndexBackend.enabled?
index = Setting.get('es_index').to_s + "_#{Rails.env}"
index = "#{Setting.get('es_index')}_#{Rails.env}"
url = Setting.get('es_url')
url = if type
if o_id