Added elasticsearch 2.4 support.

This commit is contained in:
Martin Edenhofer 2016-09-09 23:10:27 +02:00
parent 0fbb5f8ec6
commit 5fc8e6c510
4 changed files with 40 additions and 13 deletions

View file

@ -111,18 +111,18 @@ returns
group_condition.push group.id group_condition.push group.id
} }
access_condition = { access_condition = {
'query_string' => { 'default_field' => 'Ticket.group_id', 'query' => "\"#{group_condition.join('" OR "')}\"" } 'query_string' => { 'default_field' => 'group_id', 'query' => "\"#{group_condition.join('" OR "')}\"" }
} }
else else
access_condition = if !current_user.organization || ( !current_user.organization.shared || current_user.organization.shared == false ) access_condition = if !current_user.organization || ( !current_user.organization.shared || current_user.organization.shared == false )
{ {
'query_string' => { 'default_field' => 'Ticket.customer_id', 'query' => current_user.id } 'query_string' => { 'default_field' => 'customer_id', 'query' => current_user.id }
} }
# customer_id: XXX # customer_id: XXX
# conditions = [ 'customer_id = ?', current_user.id ] # conditions = [ 'customer_id = ?', current_user.id ]
else else
{ {
'query_string' => { 'query' => "Ticket.customer_id:#{current_user.id} OR Ticket.organization_id:#{current_user.organization.id}" } 'query_string' => { 'query' => "customer_id:#{current_user.id} OR organization_id:#{current_user.organization.id}" }
} }
# customer_id: XXX OR organization_id: XXX # customer_id: XXX OR organization_id: XXX
# conditions = [ '( customer_id = ? OR organization_id = ? )', current_user.id, current_user.organization.id ] # conditions = [ '( customer_id = ? OR organization_id = ? )', current_user.id, current_user.organization.id ]

View file

@ -33,7 +33,7 @@ returns
# collect article data # collect article data
articles = Ticket::Article.where(ticket_id: id) articles = Ticket::Article.where(ticket_id: id)
attributes['articles'] = [] attributes['article'] = []
articles.each { |article| articles.each { |article|
article_attributes = article.attributes article_attributes = article.attributes
@ -53,8 +53,8 @@ returns
# lookup attachments # lookup attachments
article.attachments.each { |attachment| article.attachments.each { |attachment|
if !article_attributes['attachments'] if !article_attributes['attachment']
article_attributes['attachments'] = [] article_attributes['attachment'] = []
end end
# check file size # check file size
@ -73,9 +73,9 @@ returns
'_name' => attachment.filename, '_name' => attachment.filename,
'_content' => Base64.encode64(attachment.content) '_content' => Base64.encode64(attachment.content)
} }
article_attributes['attachments'].push data article_attributes['attachment'].push data
} }
attributes['articles'].push article_attributes attributes['article'].push article_attributes
} }
attributes attributes

View file

@ -21,12 +21,13 @@ namespace :searchindex do
data: { data: {
mappings: { mappings: {
Ticket: { Ticket: {
_source: { excludes: [ 'articles.attachments' ] }, _source: { excludes: [ 'article.attachment' ] },
properties: { properties: {
articles: { article: {
type: 'nested', type: 'nested',
include_in_parent: true,
properties: { properties: {
attachments: { attachment: {
type: 'attachment', type: 'attachment',
} }
} }

View file

@ -148,7 +148,6 @@ class ElasticsearchTest < ActiveSupport::TestCase
) )
attributes = ticket1.search_index_attribute_lookup attributes = ticket1.search_index_attribute_lookup
assert_equal('Users', attributes['group']) assert_equal('Users', attributes['group'])
assert_equal('new', attributes['state']) assert_equal('new', attributes['state'])
assert_equal('2 normal', attributes['priority']) assert_equal('2 normal', attributes['priority'])
@ -472,7 +471,34 @@ class ElasticsearchTest < ActiveSupport::TestCase
limit: 15, limit: 15,
) )
assert(result[0], 'record 1') assert(result[0], 'record 1')
assert(!result[1], 'record 1') assert(!result[1], 'record 2')
assert_equal(result[0].id, ticket1.id)
result = Ticket.search(
current_user: agent,
query: 'state:open',
limit: 15,
)
assert(result[0], 'record 1')
assert(!result[1], 'record 2')
assert_equal(result[0].id, ticket2.id)
result = Ticket.search(
current_user: agent,
query: '"some_sender@example.com"',
limit: 15,
)
assert(result[0], 'record 1')
assert(!result[1], 'record 2')
assert_equal(result[0].id, ticket1.id)
result = Ticket.search(
current_user: agent,
query: 'article.from:"some_sender@example.com"',
limit: 15,
)
assert(result[0], 'record 1')
assert(!result[1], 'record 2')
assert_equal(result[0].id, ticket1.id) assert_equal(result[0].id, ticket1.id)
end end