Fixed issue #2059 - Incorrect display count of a report profile if tree_select is used.

This commit is contained in:
Martin Edenhofer 2019-04-17 08:26:26 +02:00 committed by Thorsten Eckel
parent 4cd36cb200
commit 8a6ffc23cb
3 changed files with 82 additions and 7 deletions

View file

@ -232,8 +232,8 @@ test:integration:es:
- bundle exec rake zammad:db:unseeded
- bundle exec rails test test/integration/elasticsearch_active_test.rb
- bundle exec rails test test/integration/elasticsearch_test.rb
- bundle exec rails test test/integration/report_test.rb
- bundle exec rspec --tag searchindex
- bundle exec rails test test/integration/report_test.rb
### Zendesk

View file

@ -333,7 +333,7 @@ remove whole data from index
return if url.blank?
url += if index
if index.class == Array
if index.is_a?(Array)
"/#{index.join(',')}/_search"
else
"/#{index}/_search"
@ -399,6 +399,7 @@ remove whole data from index
next if value.blank?
next if order_by&.at(index).blank?
# for sorting values use .raw values (no analyzer is used - plain values)
if value !~ /\./ && value !~ /_(time|date|till|id|ids|at)$/
value += '.raw'
end
@ -435,6 +436,24 @@ remove whole data from index
get count of tickets and tickets which match on selector
result = SearchIndexBackend.selectors(index, selector)
example with a simple search:
result = SearchIndexBackend.selectors('Ticket', { category: { operator: 'is', value: 'aa::ab' } })
result = [
{ id: 1, type: 'Ticket' },
{ id: 2, type: 'Ticket' },
{ id: 3, type: 'Ticket' },
]
you also can get aggregations
result = SearchIndexBackend.selectors(index, selector, options, aggs_interval)
example for aggregations within one year
aggs_interval = {
from: '2015-01-01',
to: '2015-12-31',
@ -447,9 +466,8 @@ get count of tickets and tickets which match on selector
current_user: User.find(123),
}
result = SearchIndexBackend.selectors(index, selector, options, aggs_interval)
result = SearchIndexBackend.selectors('Ticket', { category: { operator: 'is', value: 'aa::ab' } }, options, aggs_interval)
# for aggregations
result = {
hits:{
total:4819,
@ -482,7 +500,7 @@ get count of tickets and tickets which match on selector
return if url.blank?
url += if index
if index.class == Array
if index.is_a?(Array)
"/#{index.join(',')}/_search"
else
"/#{index}/_search"
@ -553,9 +571,23 @@ get count of tickets and tickets which match on selector
key_tmp = key.sub(/^.+?\./, '')
t = {}
# use .raw in cases where query contains ::
if data['value'].is_a?(Array)
data['value'].each do |value|
if value.is_a?(String) && value =~ /::/
key_tmp += '.raw'
break
end
end
elsif data['value'].is_a?(String)
if /::/.match?(data['value'])
key_tmp += '.raw'
end
end
# is/is not/contains/contains not
if data['operator'] == 'is' || data['operator'] == 'is not' || data['operator'] == 'contains' || data['operator'] == 'contains not'
if data['value'].class == Array
if data['value'].is_a?(Array)
t[:terms] = {}
t[:terms][key_tmp] = data['value']
else

View file

@ -1,10 +1,36 @@
require 'test_helper'
require 'integration_test_helper'
class ReportTest < ActiveSupport::TestCase
include SearchindexHelper
setup do
# create attribute
attribute1 = ObjectManager::Attribute.add(
object: 'Ticket',
name: 'test_category',
display: 'Test 1',
data_type: 'tree_select',
data_option: {
maxlength: 200,
null: false,
default: '',
options: [
{ 'name' => 'aa', 'value' => 'aa', 'children' => [{ 'name' => 'aa', 'value' => 'aa::aa' }, { 'name' => 'bb', 'value' => 'aa::bb' }, { 'name' => 'cc', 'value' => 'aa::cc' }] },
{ 'name' => 'bb', 'value' => 'bb', 'children' => [{ 'name' => 'aa', 'value' => 'bb::aa' }, { 'name' => 'bb', 'value' => 'bb::bb' }, { 'name' => 'cc', 'value' => 'bb::cc' }] },
{ 'name' => 'cc', 'value' => 'cc', 'children' => [{ 'name' => 'aa', 'value' => 'cc::aa' }, { 'name' => 'bb', 'value' => 'cc::bb' }, { 'name' => 'cc', 'value' => 'cc::cc' }] },
]
},
active: true,
screens: {},
position: 20,
created_by_id: 1,
updated_by_id: 1,
editable: false,
to_migrate: false,
)
ObjectManager::Attribute.migration_execute
configure_elasticsearch(required: true)
Ticket.destroy_all
@ -26,6 +52,7 @@ class ReportTest < ActiveSupport::TestCase
priority: Ticket::Priority.lookup(name: '2 normal'),
created_at: '2015-10-28 09:30:00 UTC',
updated_at: '2015-10-28 09:30:00 UTC',
test_category: 'cc::bb',
updated_by_id: 1,
created_by_id: 1,
)
@ -1353,6 +1380,22 @@ class ReportTest < ActiveSupport::TestCase
assert(result)
assert_nil(result[:ticket_ids][0])
# search for test_category.raw to find values with :: in query
result = Report::TicketGenericTime.items(
range_start: Time.zone.parse('2015-01-01T00:00:00Z'),
range_end: Time.zone.parse('2015-12-31T23:59:59Z'),
selector: {
'test_category' => {
'operator' => 'is',
'value' => 'cc::bb'
},
}, # ticket selector to get only a collection of tickets
params: { field: 'created_at' },
)
assert(result)
assert_equal(@ticket1.id, result[:ticket_ids][0].to_i)
assert_nil(result[:ticket_ids][1])
end
end