diff --git a/app/assets/javascripts/app/controllers/tag.coffee b/app/assets/javascripts/app/controllers/tag.coffee index 49039a90c..62496f3fe 100644 --- a/app/assets/javascripts/app/controllers/tag.coffee +++ b/app/assets/javascripts/app/controllers/tag.coffee @@ -95,7 +95,7 @@ class Table extends App.Controller e.preventDefault() e.stopPropagation() item = $(e.target).closest('tr').find('.js-name').text() - App.GlobalSearchWidget.search(item, 'tag') + App.GlobalSearchWidget.search(item, 'tags') class Edit extends App.ControllerModal buttonClose: true diff --git a/app/assets/javascripts/app/controllers/widget/tag.coffee b/app/assets/javascripts/app/controllers/widget/tag.coffee index 7b6cf5437..894816e03 100644 --- a/app/assets/javascripts/app/controllers/widget/tag.coffee +++ b/app/assets/javascripts/app/controllers/widget/tag.coffee @@ -115,4 +115,4 @@ class App.WidgetTag extends App.Controller searchTag: (e) -> e.preventDefault() item = $(e.target).text() - App.GlobalSearchWidget.search(item, 'tag') + App.GlobalSearchWidget.search(item, 'tags') diff --git a/app/models/chat/session/search_index.rb b/app/models/chat/session/search_index.rb index 7ed607b39..08f09d624 100644 --- a/app/models/chat/session/search_index.rb +++ b/app/models/chat/session/search_index.rb @@ -22,7 +22,7 @@ returns attributes = super return if !attributes - attributes[:tag] = tag_list + attributes[:tags] = tag_list messages = Chat::Message.where(chat_session_id: id) attributes['messages'] = [] diff --git a/app/models/ticket/search_index.rb b/app/models/ticket/search_index.rb index a86822c27..a0dc15ed7 100644 --- a/app/models/ticket/search_index.rb +++ b/app/models/ticket/search_index.rb @@ -23,7 +23,7 @@ returns # add tags tags = tag_list if tags.present? - attributes[:tag] = tags + attributes[:tags] = tags end # list ignored file extentions diff --git a/lib/search_index_backend.rb b/lib/search_index_backend.rb index 74ec1d2a3..d97ebe783 100644 --- a/lib/search_index_backend.rb +++ b/lib/search_index_backend.rb @@ -502,6 +502,27 @@ get count of tickets and tickets which match on selector t[:term] = {} t[:term][key_tmp] = data['value'] end + if data['operator'] == 'is' || data['operator'] == 'contains' + query_must.push t + elsif data['operator'] == 'is not' || data['operator'] == 'contains not' + query_must_not.push t + end + elsif data['operator'] == 'contains all' || data['operator'] == 'contains one' || data['operator'] == 'contains all not' || data['operator'] == 'contains one not' + values = data['value'].split(',').map(&:strip) + t[:query_string] = {} + if data['operator'] == 'contains all' + t[:query_string][:query] = "#{key_tmp}:\"#{values.join('" AND "')}\"" + query_must.push t + elsif data['operator'] == 'contains one not' + t[:query_string][:query] = "#{key_tmp}:\"#{values.join('" OR "')}\"" + query_must_not.push t + elsif data['operator'] == 'contains one' + t[:query_string][:query] = "#{key_tmp}:\"#{values.join('" OR "')}\"" + query_must.push t + elsif data['operator'] == 'contains all not' + t[:query_string][:query] = "#{key_tmp}:\"#{values.join('" AND "')}\"" + query_must_not.push t + end # within last/within next (relative) elsif data['operator'] == 'within last (relative)' || data['operator'] == 'within next (relative)' @@ -516,6 +537,7 @@ get count of tickets and tickets which match on selector else t[:range][key_tmp][:lt] = "now+#{data['value']}#{range}" end + query_must.push t # before/after (relative) elsif data['operator'] == 'before (relative)' || data['operator'] == 'after (relative)' @@ -530,6 +552,7 @@ get count of tickets and tickets which match on selector else t[:range][key_tmp][:gt] = "now+#{data['value']}#{range}" end + query_must.push t # before/after (absolute) elsif data['operator'] == 'before (absolute)' || data['operator'] == 'after (absolute)' @@ -540,22 +563,6 @@ get count of tickets and tickets which match on selector else t[:range][key_tmp][:gt] = (data['value']).to_s end - else - raise "unknown operator '#{data['operator']}' for #{key}" - end - if data['operator'] == 'is' - query_must.push t - elsif data['operator'] == 'is not' - query_must_not.push t - elsif data['operator'] == 'contains' - query_must_not.push t - elsif data['operator'] == 'contains not' - query_must_not.push t - elsif data['operator'] == 'within last (relative)' || data['operator'] == 'within next (relative)' - query_must.push t - elsif data['operator'] == 'before (relative)' || data['operator'] == 'after (relative)' - query_must.push t - elsif data['operator'] == 'before (absolute)' || data['operator'] == 'after (absolute)' query_must.push t else raise "unknown operator '#{data['operator']}' for #{key}" diff --git a/test/integration/elasticsearch_test.rb b/test/integration/elasticsearch_test.rb index 5411ddab4..a6c5e3fbc 100644 --- a/test/integration/elasticsearch_test.rb +++ b/test/integration/elasticsearch_test.rb @@ -405,7 +405,7 @@ class ElasticsearchTest < ActiveSupport::TestCase # search for tags result = Ticket.search( current_user: @agent, - query: 'tag:someTagA', + query: 'tags:someTagA', limit: 15, ) assert(result[0], 'record 1') @@ -414,7 +414,7 @@ class ElasticsearchTest < ActiveSupport::TestCase result = Ticket.search( current_user: @agent, - query: 'tag:someTagB', + query: 'tags:someTagB', limit: 15, ) assert(result[0], 'record 2') @@ -437,7 +437,7 @@ class ElasticsearchTest < ActiveSupport::TestCase # search for tags result = Ticket.search( current_user: @agent, - query: 'tag:someTagA', + query: 'tags:someTagA', limit: 15, ) assert(!result[0], 'record 1') @@ -445,7 +445,7 @@ class ElasticsearchTest < ActiveSupport::TestCase result = Ticket.search( current_user: @agent, - query: 'tag:someTagB', + query: 'tags:someTagB', limit: 15, ) assert(result[0], 'record 2') @@ -454,7 +454,7 @@ class ElasticsearchTest < ActiveSupport::TestCase result = Ticket.search( current_user: @agent, - query: 'tag:someTagC', + query: 'tags:someTagC', limit: 15, ) assert(result[0], 'record 1') diff --git a/test/integration/report_test.rb b/test/integration/report_test.rb index 4965f7990..6e1d03721 100644 --- a/test/integration/report_test.rb +++ b/test/integration/report_test.rb @@ -44,6 +44,8 @@ class ReportTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) + @ticket1.tag_add('aaa', 1) + @ticket1.tag_add('bbb', 1) @ticket1.update!( group: Group.lookup(name: 'Users'), updated_at: '2015-10-28 14:30:00 UTC', @@ -75,6 +77,7 @@ class ReportTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) + @ticket2.tag_add('aaa', 1) @ticket2.update!( group_id: group2.id, updated_at: '2015-10-28 14:30:00 UTC', @@ -162,6 +165,7 @@ class ReportTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) + @ticket5.tag_add('bbb', 1) @ticket5.update!( state: Ticket::State.lookup(name: 'open'), updated_at: '2015-10-28 14:30:00 UTC', @@ -1161,6 +1165,194 @@ class ReportTest < ActiveSupport::TestCase assert_equal(@ticket9.id, result[:ticket_ids][0].to_i) assert_nil(result[:ticket_ids][1]) + result = Report::TicketGenericTime.items( + range_start: '2015-01-01T00:00:00Z', + range_end: '2015-12-31T23:59:59Z', + selector: { + 'tags' => { + 'operator' => 'contains all', + 'value' => 'aaa, bbb' + } + }, # 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]) + + result = Report::TicketGenericTime.items( + range_start: '2015-01-01T00:00:00Z', + range_end: '2015-12-31T23:59:59Z', + selector: { + 'tags' => { + 'operator' => 'contains all not', + 'value' => 'aaa, bbb' + } + }, # ticket selector to get only a collection of tickets + params: { field: 'created_at' }, + ) + + assert(result) + assert_equal(@ticket7.id, result[:ticket_ids][0].to_i) + assert_equal(@ticket6.id, result[:ticket_ids][1].to_i) + assert_equal(@ticket5.id, result[:ticket_ids][2].to_i) + assert_equal(@ticket4.id, result[:ticket_ids][3].to_i) + assert_equal(@ticket3.id, result[:ticket_ids][4].to_i) + assert_equal(@ticket2.id, result[:ticket_ids][5].to_i) + assert_nil(result[:ticket_ids][6]) + + result = Report::TicketGenericTime.items( + range_start: '2015-01-01T00:00:00Z', + range_end: '2015-12-31T23:59:59Z', + selector: { + 'tags' => { + 'operator' => 'contains all', + 'value' => 'aaa' + } + }, # ticket selector to get only a collection of tickets + params: { field: 'created_at' }, + ) + + assert(result) + + assert_equal(@ticket2.id, result[:ticket_ids][0].to_i) + assert_equal(@ticket1.id, result[:ticket_ids][1].to_i) + assert_nil(result[:ticket_ids][2]) + + result = Report::TicketGenericTime.items( + range_start: '2015-01-01T00:00:00Z', + range_end: '2015-12-31T23:59:59Z', + selector: { + 'tags' => { + 'operator' => 'contains all not', + 'value' => 'aaa' + } + }, # ticket selector to get only a collection of tickets + params: { field: 'created_at' }, + ) + + assert(result) + assert_equal(@ticket7.id, result[:ticket_ids][0].to_i) + assert_equal(@ticket6.id, result[:ticket_ids][1].to_i) + assert_equal(@ticket5.id, result[:ticket_ids][2].to_i) + assert_equal(@ticket4.id, result[:ticket_ids][3].to_i) + assert_equal(@ticket3.id, result[:ticket_ids][4].to_i) + assert_nil(result[:ticket_ids][5]) + + result = Report::TicketGenericTime.items( + range_start: '2015-01-01T00:00:00Z', + range_end: '2015-12-31T23:59:59Z', + selector: { + 'tags' => { + 'operator' => 'contains one not', + 'value' => 'aaa' + } + }, # ticket selector to get only a collection of tickets + params: { field: 'created_at' }, + ) + + assert(result) + + assert_equal(@ticket7.id, result[:ticket_ids][0].to_i) + assert_equal(@ticket6.id, result[:ticket_ids][1].to_i) + assert_equal(@ticket5.id, result[:ticket_ids][2].to_i) + assert_equal(@ticket4.id, result[:ticket_ids][3].to_i) + assert_equal(@ticket3.id, result[:ticket_ids][4].to_i) + assert_nil(result[:ticket_ids][5]) + + result = Report::TicketGenericTime.items( + range_start: '2015-01-01T00:00:00Z', + range_end: '2015-12-31T23:59:59Z', + selector: { + 'tags' => { + 'operator' => 'contains one not', + 'value' => 'aaa, bbb' + } + }, # ticket selector to get only a collection of tickets + params: { field: 'created_at' }, + ) + + assert(result) + assert_equal(@ticket7.id, result[:ticket_ids][0].to_i) + assert_equal(@ticket6.id, result[:ticket_ids][1].to_i) + assert_equal(@ticket4.id, result[:ticket_ids][2].to_i) + assert_equal(@ticket3.id, result[:ticket_ids][3].to_i) + assert_nil(result[:ticket_ids][4]) + + result = Report::TicketGenericTime.items( + range_start: '2015-01-01T00:00:00Z', + range_end: '2015-12-31T23:59:59Z', + selector: { + 'tags' => { + 'operator' => 'contains one', + 'value' => 'aaa' + } + }, # ticket selector to get only a collection of tickets + params: { field: 'created_at' }, + ) + + assert(result) + + assert_equal(@ticket2.id, result[:ticket_ids][0].to_i) + assert_equal(@ticket1.id, result[:ticket_ids][1].to_i) + assert_nil(result[:ticket_ids][2]) + + result = Report::TicketGenericTime.items( + range_start: '2015-01-01T00:00:00Z', + range_end: '2015-12-31T23:59:59Z', + selector: { + 'tags' => { + 'operator' => 'contains one', + 'value' => 'aaa, bbb' + } + }, # ticket selector to get only a collection of tickets + params: { field: 'created_at' }, + ) + + assert(result) + assert_equal(@ticket5.id, result[:ticket_ids][0].to_i) + assert_equal(@ticket2.id, result[:ticket_ids][1].to_i) + assert_equal(@ticket1.id, result[:ticket_ids][2].to_i) + assert_nil(result[:ticket_ids][3]) + + result = Report::TicketGenericTime.items( + range_start: '2015-01-01T00:00:00Z', + range_end: '2015-12-31T23:59:59Z', + selector: { + 'title' => { + 'operator' => 'contains', + 'value' => 'test' + } + }, # ticket selector to get only a collection of tickets + params: { field: 'created_at' }, + ) + + assert(result) + assert_equal(@ticket7.id, result[:ticket_ids][0].to_i) + assert_equal(@ticket6.id, result[:ticket_ids][1].to_i) + assert_equal(@ticket5.id, result[:ticket_ids][2].to_i) + assert_equal(@ticket4.id, result[:ticket_ids][3].to_i) + assert_equal(@ticket3.id, result[:ticket_ids][4].to_i) + assert_equal(@ticket2.id, result[:ticket_ids][5].to_i) + assert_equal(@ticket1.id, result[:ticket_ids][6].to_i) + assert_nil(result[:ticket_ids][7]) + + result = Report::TicketGenericTime.items( + range_start: '2015-01-01T00:00:00Z', + range_end: '2015-12-31T23:59:59Z', + selector: { + 'title' => { + 'operator' => 'contains not', + 'value' => 'test' + } + }, # ticket selector to get only a collection of tickets + params: { field: 'created_at' }, + ) + + assert(result) + assert_nil(result[:ticket_ids][0]) + # cleanup Rake::Task['searchindex:drop'].execute end diff --git a/test/unit/search_index_backend_test.rb b/test/unit/search_index_backend_test.rb index 102486349..3a6681a80 100644 --- a/test/unit/search_index_backend_test.rb +++ b/test/unit/search_index_backend_test.rb @@ -21,7 +21,7 @@ class SearchIndexBackendTest < ActiveSupport::TestCase (state:new OR state:open) OR priority:”3 normal” (state:new OR state:open) AND customer.lastname:smith state:(new OR open) AND title:(full text search) # state: new OR open & title: full OR text OR search - tag: “some tag” + tags: “some tag” owner.email: “bod@example.com” AND state: (new OR open OR pending*) # show all open tickets of a certain agent state:closed AND _missing_:tag # all closed objects without tags article_count: [1 TO 5] # tickets with 1 to 5 articles