Fixed issue #2611 - SearchIndexBackend.remove() (ES) is not removing entries
This commit is contained in:
parent
5745fa46bd
commit
c60e1c0780
4 changed files with 59 additions and 19 deletions
|
@ -331,7 +331,7 @@ remove whole data from index
|
|||
return [] if query.blank?
|
||||
|
||||
url = build_url
|
||||
return if url.blank?
|
||||
return [] if url.blank?
|
||||
|
||||
url += build_search_url(index)
|
||||
|
||||
|
@ -735,9 +735,11 @@ return true if backend is configured
|
|||
if Setting.get('es_multi_index') == false
|
||||
url = Setting.get('es_url')
|
||||
url = if type
|
||||
url_pipline = Setting.get('es_pipeline')
|
||||
if url_pipline.present?
|
||||
url_pipline = "?pipeline=#{url_pipline}"
|
||||
if pipeline == true
|
||||
url_pipline = Setting.get('es_pipeline')
|
||||
if url_pipline.present?
|
||||
url_pipline = "?pipeline=#{url_pipline}"
|
||||
end
|
||||
end
|
||||
if o_id
|
||||
"#{url}/#{index}/#{type}/#{o_id}#{url_pipline}"
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SearchIndexBackend do
|
||||
RSpec.describe SearchIndexBackend, searchindex: true do
|
||||
|
||||
before do
|
||||
configure_elasticsearch
|
||||
rebuild_searchindex
|
||||
end
|
||||
|
||||
describe '.build_query' do
|
||||
subject(:query) { described_class.build_query('', query_extension: params) }
|
||||
|
||||
|
@ -20,7 +26,7 @@ RSpec.describe SearchIndexBackend do
|
|||
context 'on a single index' do
|
||||
let(:index) { 'User' }
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
it { is_expected.to be_an(Array).and be_empty }
|
||||
end
|
||||
|
||||
context 'on multiple indices' do
|
||||
|
@ -99,4 +105,28 @@ RSpec.describe SearchIndexBackend do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.remove' do
|
||||
context 'ticket' do
|
||||
it 'from index after ticket delete' do
|
||||
|
||||
skip('No ES configured') if !SearchIndexBackend.enabled?
|
||||
|
||||
ticket = create :ticket
|
||||
described_class.add('Ticket', ticket)
|
||||
|
||||
# give es time to rebuild index
|
||||
sleep 2
|
||||
result = described_class.search(ticket.number, 'Ticket', sort_by: ['updated_at'], order_by: ['desc'])
|
||||
expect(result).to eq([{ id: ticket.id.to_s, type: 'Ticket' }])
|
||||
|
||||
described_class.remove('Ticket', ticket.id)
|
||||
# give es time to rebuild index
|
||||
sleep 2
|
||||
|
||||
result = described_class.search(ticket.number, 'Ticket', sort_by: ['updated_at'], order_by: ['desc'])
|
||||
expect(result).to eq([])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,21 @@
|
|||
require 'rake'
|
||||
|
||||
# if you make changes, then please also change this file 'test/support/searchindex_helper.rb'
|
||||
# this is required as long as our test suite is made of RSpec and MiniTest
|
||||
module SearchindexBackendHelper
|
||||
|
||||
def self.included(base)
|
||||
# Execute in RSpec class context
|
||||
base.class_exec do
|
||||
|
||||
after(:each) do
|
||||
next if ENV['ES_URL'].blank?
|
||||
|
||||
Rake::Task['searchindex:drop'].execute
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def configure_elasticsearch(required: false)
|
||||
if ENV['ES_URL'].blank?
|
||||
return if !required
|
||||
|
@ -16,7 +32,7 @@ module SearchindexBackendHelper
|
|||
|
||||
if ENV['ES_INDEX_RAND'].present?
|
||||
rand_id = ENV.fetch('CI_JOB_ID', "r#{rand(999)}")
|
||||
test_method_name = subject.gsub(/[^\w]/, '_')
|
||||
test_method_name = self.class.description.gsub(/[^\w]/, '_')
|
||||
ENV['ES_INDEX'] = "es_index_#{test_method_name}_#{rand_id}_#{rand(999_999_999)}"
|
||||
end
|
||||
if ENV['ES_INDEX'].blank?
|
||||
|
@ -32,21 +48,11 @@ module SearchindexBackendHelper
|
|||
end
|
||||
|
||||
def rebuild_searchindex
|
||||
Rake::Task.clear
|
||||
Zammad::Application.load_tasks
|
||||
Rake::Task['searchindex:rebuild'].execute
|
||||
end
|
||||
|
||||
def self.included(base)
|
||||
|
||||
# Execute in RSpec class context
|
||||
base.class_exec do
|
||||
|
||||
after(:each) do
|
||||
next if ENV['ES_URL'].blank?
|
||||
|
||||
Rake::Task['searchindex:drop'].execute
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
require 'rake'
|
||||
|
||||
# if you make changes, then please also change this file 'spec/support/searchindex_backend.rb'
|
||||
# this is required as long as our test suite is made of RSpec and MiniTest
|
||||
module SearchindexHelper
|
||||
|
||||
def self.included(base)
|
||||
|
|
Loading…
Reference in a new issue