From 23a2ff1669850fbf922689e46362ed74506190d5 Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Tue, 18 Jul 2023 11:18:53 -0400 Subject: [PATCH 01/26] fix up a bit how searchable_by works in the real world --- app/services/search_service.rb | 32 ++++---------- app/services/status_search_service.rb | 64 +++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 23 deletions(-) create mode 100644 app/services/status_search_service.rb diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 778ea85fb46fdf..4acd4b67102fa8 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -39,25 +39,15 @@ def perform_accounts_search! end def perform_statuses_search! - definition = parsed_query.apply(StatusesIndex.filter(term: { searchable_by: @account.id })) - - definition = definition.filter(term: { account_id: @options[:account_id] }) if @options[:account_id].present? - - if @options[:min_id].present? || @options[:max_id].present? - range = {} - range[:gt] = @options[:min_id].to_i if @options[:min_id].present? - range[:lt] = @options[:max_id].to_i if @options[:max_id].present? - definition = definition.filter(range: { id: range }) - end - - results = definition.limit(@limit).offset(@offset).objects.compact - account_ids = results.map(&:account_id) - account_domains = results.map(&:account_domain) - preloaded_relations = @account.relations_map(account_ids, account_domains) - - results.reject { |status| StatusFilter.new(status, @account, preloaded_relations).filtered? } - rescue Faraday::ConnectionFailed, Parslet::ParseFailed - [] + StatusSearchService.new.call( + @query, + @account, + limit: @limit, + offset: @offset, + account_id: @options[:account_id].present? ? @options[:account_id] : nil, + min_id: @options[:min_id].present? ? @options[:min_id] : nil, + min_id: @options[:max_id].present? ? @options[:max_id] : nil + ) end def perform_hashtags_search! @@ -114,8 +104,4 @@ def hashtag_search? def statuses_search? @options[:type].blank? || @options[:type] == 'statuses' end - - def parsed_query - SearchQueryTransformer.new.apply(SearchQueryParser.new.parse(@query)) - end end diff --git a/app/services/status_search_service.rb b/app/services/status_search_service.rb new file mode 100644 index 00000000000000..b9a4841c9533a0 --- /dev/null +++ b/app/services/status_search_service.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +class StatusSearchService < BaseService + def call(query, account = nil, options = {}) + @query = query&.strip + @account = account + @options = options + @limit = options[:limit].to_i + @offset = options[:offset].to_i + + status_search_results + end + + private + + def status_search_results + base_query = StatusesIndex.query( + bool: { + should: [ + { + bool: { + must: { + term: { publicly_searchable: false } + }, + filter: { + term: { searchable_by: @account.id } + } + } + }, + { + bool: { + must: { + term: { publicly_searchable: true } + } + } + } + ] + } + ) + definition = parsed_query.apply(base_query) + + definition = definition.filter(term: { account_id: @options[:account_id] }) if @options[:account_id].present? + + if @options[:min_id].present? || @options[:max_id].present? + range = {} + range[:gt] = @options[:min_id].to_i if @options[:min_id].present? + range[:lt] = @options[:max_id].to_i if @options[:max_id].present? + definition = definition.filter(range: { id: range }) + end + + results = definition.limit(@limit).offset(@offset).objects.compact + account_ids = results.map(&:account_id) + account_domains = results.map(&:account_domain) + preloaded_relations = @account.relations_map(account_ids, account_domains) + + results.reject { |status| StatusFilter.new(status, @account, preloaded_relations).filtered? } + rescue Faraday::ConnectionFailed, Parslet::ParseFailed + [] + end + + def parsed_query + SearchQueryTransformer.new.apply(SearchQueryParser.new.parse(@query)) + end +end From 1d89587d6dd685189b426f588c603630ff550d62 Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Tue, 18 Jul 2023 11:24:11 -0400 Subject: [PATCH 02/26] ruby lint --- app/services/search_service.rb | 6 +++--- app/services/status_search_service.rb | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 4acd4b67102fa8..e255a9a6a98a01 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -44,9 +44,9 @@ def perform_statuses_search! @account, limit: @limit, offset: @offset, - account_id: @options[:account_id].present? ? @options[:account_id] : nil, - min_id: @options[:min_id].present? ? @options[:min_id] : nil, - min_id: @options[:max_id].present? ? @options[:max_id] : nil + account_id: @options[:account_id].presence?, + min_id: @options[:min_id].presence?, + max_id: @options[:max_id].presence? ) end diff --git a/app/services/status_search_service.rb b/app/services/status_search_service.rb index b9a4841c9533a0..2774372fcef675 100644 --- a/app/services/status_search_service.rb +++ b/app/services/status_search_service.rb @@ -20,21 +20,21 @@ def status_search_results { bool: { must: { - term: { publicly_searchable: false } + term: { publicly_searchable: false }, }, filter: { - term: { searchable_by: @account.id } - } - } + term: { searchable_by: @account.id }, + }, + }, }, { bool: { must: { - term: { publicly_searchable: true } - } - } - } - ] + term: { publicly_searchable: true }, + }, + }, + }, + ], } ) definition = parsed_query.apply(base_query) @@ -42,10 +42,10 @@ def status_search_results definition = definition.filter(term: { account_id: @options[:account_id] }) if @options[:account_id].present? if @options[:min_id].present? || @options[:max_id].present? - range = {} - range[:gt] = @options[:min_id].to_i if @options[:min_id].present? - range[:lt] = @options[:max_id].to_i if @options[:max_id].present? - definition = definition.filter(range: { id: range }) + range = {} + range[:gt] = @options[:min_id].to_i if @options[:min_id].present? + range[:lt] = @options[:max_id].to_i if @options[:max_id].present? + definition = definition.filter(range: { id: range }) end results = definition.limit(@limit).offset(@offset).objects.compact From 40d8575c682bba2563ec133523f6c630502eae89 Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Tue, 18 Jul 2023 11:35:36 -0400 Subject: [PATCH 03/26] make sure chewy is enabled --- app/services/status_search_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/status_search_service.rb b/app/services/status_search_service.rb index 2774372fcef675..1ed44f1681c284 100644 --- a/app/services/status_search_service.rb +++ b/app/services/status_search_service.rb @@ -8,7 +8,7 @@ def call(query, account = nil, options = {}) @limit = options[:limit].to_i @offset = options[:offset].to_i - status_search_results + status_search_results if Chewy.enabled? end private From a3152a637b78ba842ed5d4bb565f157134457832 Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Tue, 18 Jul 2023 12:04:25 -0400 Subject: [PATCH 04/26] Bring in a change from other pr so we can pass tests --- app/models/concerns/account_statuses_search.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/concerns/account_statuses_search.rb b/app/models/concerns/account_statuses_search.rb index 99b4a7a3898450..0efcf1b5318075 100644 --- a/app/models/concerns/account_statuses_search.rb +++ b/app/models/concerns/account_statuses_search.rb @@ -4,6 +4,11 @@ module AccountStatusesSearch extend ActiveSupport::Concern def update_statuses_index! + return unless Chewy.enabled? + + # This might not scale if a user has a TON of statuses. + # If that is the case, perhaps for users with many statuses, we should: + # (1) get all their statuses and (2) submit requests to ES in batches. Chewy.strategy(:sidekiq) do StatusesIndex.import(query: Status.where(account_id: id)) end From efa83297c09d528c89ff67a4ffd89905c598ac31 Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Wed, 19 Jul 2023 13:37:22 -0400 Subject: [PATCH 05/26] Try to get a cleaner query to work. This is going to fail some tests... --- app/lib/search_query_transformer.rb | 34 ++++++++++--- app/services/search_service.rb | 6 +-- app/services/status_search_service.rb | 71 +++++++++++++++++---------- 3 files changed, 77 insertions(+), 34 deletions(-) diff --git a/app/lib/search_query_transformer.rb b/app/lib/search_query_transformer.rb index aef05e9d9d883c..6aa0fc82a7cae0 100644 --- a/app/lib/search_query_transformer.rb +++ b/app/lib/search_query_transformer.rb @@ -12,12 +12,34 @@ def initialize(clauses) @filter_clauses = grouped.fetch(:filter, []) end - def apply(search) - should_clauses.each { |clause| search = search.query.should(clause_to_query(clause)) } - must_clauses.each { |clause| search = search.query.must(clause_to_query(clause)) } - must_not_clauses.each { |clause| search = search.query.must_not(clause_to_query(clause)) } - filter_clauses.each { |clause| search = search.filter(**clause_to_filter(clause)) } - search.query.minimum_should_match(1) + def apply(query) + query[:bool] ||= {} + + if should_clauses.present? + query[:bool][:should] ||= [] + + query[:bool][:should] += should_clauses.map { |clause| clause_to_query(clause) } + query[:bool][:minimum_should_match] = 1 + end + + if must_clauses.present? + query[:bool][:must] ||= [] + + query[:bool][:must] += must_clauses.map { |clause| clause_to_query(clause) } + end + + if must_not_clauses.present? + query[:bool][:must_not] ||= [] + + query[:bool][:must_not] += must_clauses.map { |clause| clause_to_query(clause) } + end + + if filter_clauses.present? + query[:bool][:filter] ||= [] + query[:bool][:filter] += filter_clauses.map { |clause| clause_to_filter(clause) } + end + + query end private diff --git a/app/services/search_service.rb b/app/services/search_service.rb index e255a9a6a98a01..5fd485fbf10dc8 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -44,9 +44,9 @@ def perform_statuses_search! @account, limit: @limit, offset: @offset, - account_id: @options[:account_id].presence?, - min_id: @options[:min_id].presence?, - max_id: @options[:max_id].presence? + account_id: @options[:account_id], + min_id: @options[:min_id], + max_id: @options[:max_id] ) end diff --git a/app/services/status_search_service.rb b/app/services/status_search_service.rb index 1ed44f1681c284..8572ba31f37995 100644 --- a/app/services/status_search_service.rb +++ b/app/services/status_search_service.rb @@ -8,36 +8,13 @@ def call(query, account = nil, options = {}) @limit = options[:limit].to_i @offset = options[:offset].to_i - status_search_results if Chewy.enabled? + status_search_results end private def status_search_results - base_query = StatusesIndex.query( - bool: { - should: [ - { - bool: { - must: { - term: { publicly_searchable: false }, - }, - filter: { - term: { searchable_by: @account.id }, - }, - }, - }, - { - bool: { - must: { - term: { publicly_searchable: true }, - }, - }, - }, - ], - } - ) - definition = parsed_query.apply(base_query) + definition = get_definition definition = definition.filter(term: { account_id: @options[:account_id] }) if @options[:account_id].present? @@ -58,6 +35,50 @@ def status_search_results [] end + def get_definition + non_publicly_searchable_clauses = non_publicly_searchable + publicly_searchable_clauses = publicly_searchable + + filter = { + bool: { + should: [ + non_publicly_searchable_clauses, + publicly_searchable_clauses, + ], + minimum_should_match: 1 + } + } + + query = StatusesIndex.query(filter) + end + + def publicly_searchable + parsed_query.apply( + { + bool: { + must: [ + { term: { publicly_searchable: true } }, + ], + }, + } + ) + end + + def non_publicly_searchable + parsed_query.apply( + { + bool: { + must: [ + { term: { publicly_searchable: false } }, + ], + filter: [ + { term: { searchable_by: @account.id } }, + ], + }, + } + ) + end + def parsed_query SearchQueryTransformer.new.apply(SearchQueryParser.new.parse(@query)) end From df6767f3d5baafc3a558e9207f998944ba2d59ca Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Wed, 19 Jul 2023 13:57:57 -0400 Subject: [PATCH 06/26] clean up and lint --- app/lib/search_query_transformer.rb | 2 +- app/services/status_search_service.rb | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/lib/search_query_transformer.rb b/app/lib/search_query_transformer.rb index 6aa0fc82a7cae0..17ae3d68d00d84 100644 --- a/app/lib/search_query_transformer.rb +++ b/app/lib/search_query_transformer.rb @@ -31,7 +31,7 @@ def apply(query) if must_not_clauses.present? query[:bool][:must_not] ||= [] - query[:bool][:must_not] += must_clauses.map { |clause| clause_to_query(clause) } + query[:bool][:must_not] += must_not_clauses.map { |clause| clause_to_query(clause) } end if filter_clauses.present? diff --git a/app/services/status_search_service.rb b/app/services/status_search_service.rb index 8572ba31f37995..87522b1fc7b6ef 100644 --- a/app/services/status_search_service.rb +++ b/app/services/status_search_service.rb @@ -14,7 +14,7 @@ def call(query, account = nil, options = {}) private def status_search_results - definition = get_definition + definition = search_definition definition = definition.filter(term: { account_id: @options[:account_id] }) if @options[:account_id].present? @@ -35,7 +35,7 @@ def status_search_results [] end - def get_definition + def search_definition non_publicly_searchable_clauses = non_publicly_searchable publicly_searchable_clauses = publicly_searchable @@ -45,8 +45,8 @@ def get_definition non_publicly_searchable_clauses, publicly_searchable_clauses, ], - minimum_should_match: 1 - } + minimum_should_match: 1, + }, } query = StatusesIndex.query(filter) @@ -60,7 +60,7 @@ def publicly_searchable { term: { publicly_searchable: true } }, ], }, - } + }, ) end @@ -75,7 +75,7 @@ def non_publicly_searchable { term: { searchable_by: @account.id } }, ], }, - } + }, ) end From 8441b95bf129c9f3925e60b0d6d29f526551d56b Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Wed, 19 Jul 2023 14:14:08 -0400 Subject: [PATCH 07/26] more linting cause i goofed up that last one --- app/services/status_search_service.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/services/status_search_service.rb b/app/services/status_search_service.rb index 87522b1fc7b6ef..2a79581f216183 100644 --- a/app/services/status_search_service.rb +++ b/app/services/status_search_service.rb @@ -49,7 +49,7 @@ def search_definition }, } - query = StatusesIndex.query(filter) + StatusesIndex.query(filter) end def publicly_searchable @@ -60,7 +60,7 @@ def publicly_searchable { term: { publicly_searchable: true } }, ], }, - }, + } ) end @@ -75,7 +75,7 @@ def non_publicly_searchable { term: { searchable_by: @account.id } }, ], }, - }, + } ) end From da2cf57874d6777c3e7237b9604cc1266a5fa235 Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Wed, 19 Jul 2023 15:21:54 -0400 Subject: [PATCH 08/26] Try to add tests even though I don't know how to do that... --- spec/lib/search_query_transformer_spec.rb | 54 +++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index 1095334695485d..09da5572b3456d 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -15,4 +15,58 @@ expect(transformer.filter_clauses.first).to be_nil end end + + describe '#apply' do + subject(:applied_query) do + described_class.new( + SearchQueryParser.new.parse('query') + ).apply(query) + end + + let(:query) { { bool: {} } } + let(:search_string) { 'search string' } + let(:term) { { term: { field_name: search_string } } } + + context 'when query is just a bool' do + it 'does not modify the query' do + expect(applied_query).to eq(query) + end + end + + context 'when should_clauses are present' do + let(:should) { { bool: { should: [term] } } } + + it 'adds should clauses to the query' do + expect(applied_query[:bool][:should]).to include(term) + end + + it 'sets minimum_should_match to 1' do + expect(applied_query[:minimum_should_match]).to eq(1) + end + end + + context 'when must_clauses are present' do + let(:must) { { bool: { must: [term] } } } + + it 'adds must clauses to the query' do + expect(applied_query[:bool][:must]).to include(term) + end + end + + context 'when must_not_clauses are present' do + let(:must_not) { { bool: { must_not: [term] } } } + + it 'adds must_not clauses to the query' do + expect(applied_query[:bool][:must_not]).to include(term) + end + end + + context 'when filter_clauses are present' do + let(:filter) { { bool: { filter: [term] } } } + + it 'adds filter clauses to the query' do + expect(applied_query[:bool][:filter]).to include(term) + end + end + end end From cc1ce8bc9701a974ef32fcd38d59c4b9f7ae434b Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Wed, 19 Jul 2023 15:57:31 -0400 Subject: [PATCH 09/26] wait...do i need to apply this? --- spec/lib/search_query_transformer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index 09da5572b3456d..48aa82b811203d 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -18,7 +18,7 @@ describe '#apply' do subject(:applied_query) do - described_class.new( + described_class.new.apply( SearchQueryParser.new.parse('query') ).apply(query) end From b4c0c077b72b7e51a21f2f421abf14311ffdb28c Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Wed, 19 Jul 2023 20:02:19 -0400 Subject: [PATCH 10/26] Try to make better tests --- spec/lib/search_query_transformer_spec.rb | 32 +++++++++++++---------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index 48aa82b811203d..1e6c7d12509018 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -19,25 +19,25 @@ describe '#apply' do subject(:applied_query) do described_class.new.apply( - SearchQueryParser.new.parse('query') + SearchQueryParser.new.parse(search_term) ).apply(query) end - let(:query) { { bool: {} } } - let(:search_string) { 'search string' } - let(:term) { { term: { field_name: search_string } } } + let(:query) { } + let(:search_term) { } context 'when query is just a bool' do - it 'does not modify the query' do - expect(applied_query).to eq(query) + it 'returns a hash of bool' do + expect(applied_query).to eq({ bool: {} }) end end context 'when should_clauses are present' do - let(:should) { { bool: { should: [term] } } } + let(:search_term) { 'test' } it 'adds should clauses to the query' do - expect(applied_query[:bool][:should]).to include(term) + expect(applied_query[:bool][:should]).length eq(1) + expect(applied_query[:bool][:should][multi_match:][query:]).length eq(search_term) end it 'sets minimum_should_match to 1' do @@ -46,26 +46,30 @@ end context 'when must_clauses are present' do - let(:must) { { bool: { must: [term] } } } + let(:search_term) { '+test' } it 'adds must clauses to the query' do - expect(applied_query[:bool][:must]).to include(term) + expect(applied_query[:bool][:must]).length eq(1) + expect(applied_query[:bool][:must][multi_match:][query:]).length eq(search_term) end end context 'when must_not_clauses are present' do - let(:must_not) { { bool: { must_not: [term] } } } + let(:search_term) { '-test' } it 'adds must_not clauses to the query' do - expect(applied_query[:bool][:must_not]).to include(term) + expect(applied_query[:bool][:must_not]).length eq(1) + expect(applied_query[:bool][:must_not][multi_match:][query:]).length eq(search_term) end end context 'when filter_clauses are present' do - let(:filter) { { bool: { filter: [term] } } } + let(:search_term) { 'from:test_account' } + let(:account) { Fabricate(:test_account) } it 'adds filter clauses to the query' do - expect(applied_query[:bool][:filter]).to include(term) + expect(applied_query[:bool][:filter]).length eq(1) + expect(applied_query[:bool][:filter][term:][account_id:]).length eq(account.id) end end end From df2db4688c4e215f89a14be8540814988050daae Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Thu, 20 Jul 2023 09:48:49 -0400 Subject: [PATCH 11/26] colon on wrong side ya dingbat --- spec/lib/search_query_transformer_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index 1e6c7d12509018..30adbff2ce3c0d 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -37,7 +37,7 @@ it 'adds should clauses to the query' do expect(applied_query[:bool][:should]).length eq(1) - expect(applied_query[:bool][:should][multi_match:][query:]).length eq(search_term) + expect(applied_query[:bool][:should][:multi_match][query:]).length eq(search_term) end it 'sets minimum_should_match to 1' do @@ -50,7 +50,7 @@ it 'adds must clauses to the query' do expect(applied_query[:bool][:must]).length eq(1) - expect(applied_query[:bool][:must][multi_match:][query:]).length eq(search_term) + expect(applied_query[:bool][:must][:multi_match][query:]).length eq(search_term) end end @@ -59,7 +59,7 @@ it 'adds must_not clauses to the query' do expect(applied_query[:bool][:must_not]).length eq(1) - expect(applied_query[:bool][:must_not][multi_match:][query:]).length eq(search_term) + expect(applied_query[:bool][:must_not][:multi_match][query:]).length eq(search_term) end end @@ -69,7 +69,7 @@ it 'adds filter clauses to the query' do expect(applied_query[:bool][:filter]).length eq(1) - expect(applied_query[:bool][:filter][term:][account_id:]).length eq(account.id) + expect(applied_query[:bool][:filter][:term][account_id:]).length eq(account.id) end end end From 72d53aead87bf68db4474c6aa534d418839fd2d6 Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Thu, 20 Jul 2023 09:51:26 -0400 Subject: [PATCH 12/26] missed these last time too.... --- spec/lib/search_query_transformer_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index 30adbff2ce3c0d..e532f2b3cd6bf0 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -37,7 +37,7 @@ it 'adds should clauses to the query' do expect(applied_query[:bool][:should]).length eq(1) - expect(applied_query[:bool][:should][:multi_match][query:]).length eq(search_term) + expect(applied_query[:bool][:should][:multi_match][:query]).length eq(search_term) end it 'sets minimum_should_match to 1' do @@ -50,7 +50,7 @@ it 'adds must clauses to the query' do expect(applied_query[:bool][:must]).length eq(1) - expect(applied_query[:bool][:must][:multi_match][query:]).length eq(search_term) + expect(applied_query[:bool][:must][:multi_match][:query]).length eq(search_term) end end @@ -59,7 +59,7 @@ it 'adds must_not clauses to the query' do expect(applied_query[:bool][:must_not]).length eq(1) - expect(applied_query[:bool][:must_not][:multi_match][query:]).length eq(search_term) + expect(applied_query[:bool][:must_not][:multi_match][:query]).length eq(search_term) end end @@ -69,7 +69,7 @@ it 'adds filter clauses to the query' do expect(applied_query[:bool][:filter]).length eq(1) - expect(applied_query[:bool][:filter][:term][account_id:]).length eq(account.id) + expect(applied_query[:bool][:filter][:term][:account_id]).length eq(account.id) end end end From e69221f7b8ad6993d5ccefe0ef02380bd8024b1d Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Thu, 20 Jul 2023 09:57:07 -0400 Subject: [PATCH 13/26] Hopefully last round of linting... --- spec/lib/search_query_transformer_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index e532f2b3cd6bf0..0e6ce1cea47084 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -23,12 +23,12 @@ ).apply(query) end - let(:query) { } - let(:search_term) { } + let(:query) { bool: {} } + let(:search_term) { '' } context 'when query is just a bool' do it 'returns a hash of bool' do - expect(applied_query).to eq({ bool: {} }) + expect(applied_query).to eq({ query }) end end @@ -65,7 +65,7 @@ context 'when filter_clauses are present' do let(:search_term) { 'from:test_account' } - let(:account) { Fabricate(:test_account) } + let(:account) { Fabricate(:test_account) } it 'adds filter clauses to the query' do expect(applied_query[:bool][:filter]).length eq(1) From 9917e4ef2cad43c2627196d219ff64f5e4e4a1ab Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Thu, 20 Jul 2023 10:00:13 -0400 Subject: [PATCH 14/26] I think that should fix this problem --- spec/lib/search_query_transformer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index 0e6ce1cea47084..0dfd77748afe32 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -23,7 +23,7 @@ ).apply(query) end - let(:query) { bool: {} } + let(:query) { { bool: {} } } let(:search_term) { '' } context 'when query is just a bool' do From 837095977774c99ef87b58a28a1eaabfb63acd74 Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Thu, 20 Jul 2023 10:04:35 -0400 Subject: [PATCH 15/26] I think all these tests were going to fail anyways... --- spec/lib/search_query_transformer_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index 0dfd77748afe32..15615e5a6d96f7 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -28,7 +28,7 @@ context 'when query is just a bool' do it 'returns a hash of bool' do - expect(applied_query).to eq({ query }) + expect(applied_query).to eq(query) end end @@ -37,7 +37,7 @@ it 'adds should clauses to the query' do expect(applied_query[:bool][:should]).length eq(1) - expect(applied_query[:bool][:should][:multi_match][:query]).length eq(search_term) + expect(applied_query[:bool][:should][:multi_match][:query]).to eq(search_term) end it 'sets minimum_should_match to 1' do @@ -50,7 +50,7 @@ it 'adds must clauses to the query' do expect(applied_query[:bool][:must]).length eq(1) - expect(applied_query[:bool][:must][:multi_match][:query]).length eq(search_term) + expect(applied_query[:bool][:must][:multi_match][:query]).to eq(search_term) end end @@ -59,7 +59,7 @@ it 'adds must_not clauses to the query' do expect(applied_query[:bool][:must_not]).length eq(1) - expect(applied_query[:bool][:must_not][:multi_match][:query]).length eq(search_term) + expect(applied_query[:bool][:must_not][:multi_match][:query]).to eq(search_term) end end @@ -69,7 +69,7 @@ it 'adds filter clauses to the query' do expect(applied_query[:bool][:filter]).length eq(1) - expect(applied_query[:bool][:filter][:term][:account_id]).length eq(account.id) + expect(applied_query[:bool][:filter][:term][:account_id]).to eq(account.id) end end end From e5e7c8b6bb1f7e57e4c99600b4ca93832c7b830d Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Thu, 20 Jul 2023 10:24:30 -0400 Subject: [PATCH 16/26] Let's move the lengths inside the paren cause otherwise what are we even doing... --- spec/lib/search_query_transformer_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index 15615e5a6d96f7..3e45233af422d5 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -36,7 +36,7 @@ let(:search_term) { 'test' } it 'adds should clauses to the query' do - expect(applied_query[:bool][:should]).length eq(1) + expect(applied_query[:bool][:should].length) eq(1) expect(applied_query[:bool][:should][:multi_match][:query]).to eq(search_term) end @@ -49,7 +49,7 @@ let(:search_term) { '+test' } it 'adds must clauses to the query' do - expect(applied_query[:bool][:must]).length eq(1) + expect(applied_query[:bool][:must].length) eq(1) expect(applied_query[:bool][:must][:multi_match][:query]).to eq(search_term) end end @@ -58,7 +58,7 @@ let(:search_term) { '-test' } it 'adds must_not clauses to the query' do - expect(applied_query[:bool][:must_not]).length eq(1) + expect(applied_query[:bool][:must_not].length) eq(1) expect(applied_query[:bool][:must_not][:multi_match][:query]).to eq(search_term) end end @@ -68,7 +68,7 @@ let(:account) { Fabricate(:test_account) } it 'adds filter clauses to the query' do - expect(applied_query[:bool][:filter]).length eq(1) + expect(applied_query[:bool][:filter].length) eq(1) expect(applied_query[:bool][:filter][:term][:account_id]).to eq(account.id) end end From e13e612a617a5c861fd0c88267754615083f29e7 Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Thu, 20 Jul 2023 10:28:34 -0400 Subject: [PATCH 17/26] oops. Lost my .to's there --- spec/lib/search_query_transformer_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index 3e45233af422d5..b472822486fc76 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -36,7 +36,7 @@ let(:search_term) { 'test' } it 'adds should clauses to the query' do - expect(applied_query[:bool][:should].length) eq(1) + expect(applied_query[:bool][:should].length).to eq(1) expect(applied_query[:bool][:should][:multi_match][:query]).to eq(search_term) end @@ -49,7 +49,7 @@ let(:search_term) { '+test' } it 'adds must clauses to the query' do - expect(applied_query[:bool][:must].length) eq(1) + expect(applied_query[:bool][:must].length).to eq(1) expect(applied_query[:bool][:must][:multi_match][:query]).to eq(search_term) end end @@ -58,7 +58,7 @@ let(:search_term) { '-test' } it 'adds must_not clauses to the query' do - expect(applied_query[:bool][:must_not].length) eq(1) + expect(applied_query[:bool][:must_not].length).to eq(1) expect(applied_query[:bool][:must_not][:multi_match][:query]).to eq(search_term) end end @@ -68,7 +68,7 @@ let(:account) { Fabricate(:test_account) } it 'adds filter clauses to the query' do - expect(applied_query[:bool][:filter].length) eq(1) + expect(applied_query[:bool][:filter].length).to eq(1) expect(applied_query[:bool][:filter][:term][:account_id]).to eq(account.id) end end From dd4242f3611513dbc0d9b9207f81cbcce7576d76 Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Thu, 20 Jul 2023 10:40:55 -0400 Subject: [PATCH 18/26] these are arrays so we need the element of the array in order for us to actually get data from it I think --- spec/lib/search_query_transformer_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index b472822486fc76..0bb9f62b729084 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -37,7 +37,7 @@ it 'adds should clauses to the query' do expect(applied_query[:bool][:should].length).to eq(1) - expect(applied_query[:bool][:should][:multi_match][:query]).to eq(search_term) + expect(applied_query[:bool][:should][0][:multi_match][:query]).to eq(search_term) end it 'sets minimum_should_match to 1' do @@ -50,7 +50,7 @@ it 'adds must clauses to the query' do expect(applied_query[:bool][:must].length).to eq(1) - expect(applied_query[:bool][:must][:multi_match][:query]).to eq(search_term) + expect(applied_query[:bool][:must][0][:multi_match][:query]).to eq(search_term) end end @@ -59,7 +59,7 @@ it 'adds must_not clauses to the query' do expect(applied_query[:bool][:must_not].length).to eq(1) - expect(applied_query[:bool][:must_not][:multi_match][:query]).to eq(search_term) + expect(applied_query[:bool][:must_not][0][:multi_match][:query]).to eq(search_term) end end @@ -69,7 +69,7 @@ it 'adds filter clauses to the query' do expect(applied_query[:bool][:filter].length).to eq(1) - expect(applied_query[:bool][:filter][:term][:account_id]).to eq(account.id) + expect(applied_query[:bool][:filter][0][:term][:account_id]).to eq(account.id) end end end From f1c2f6ef640b322e29a8265619353cc7d58715bf Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Thu, 20 Jul 2023 10:53:24 -0400 Subject: [PATCH 19/26] fix some of the tests and add a new one --- spec/lib/search_query_transformer_spec.rb | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index 0bb9f62b729084..b8cdc13e07ab29 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -41,7 +41,7 @@ end it 'sets minimum_should_match to 1' do - expect(applied_query[:minimum_should_match]).to eq(1) + expect(applied_query[:bool][:minimum_should_match]).to eq(1) end end @@ -50,7 +50,7 @@ it 'adds must clauses to the query' do expect(applied_query[:bool][:must].length).to eq(1) - expect(applied_query[:bool][:must][0][:multi_match][:query]).to eq(search_term) + expect(applied_query[:bool][:must][0][:multi_match][:query]).to eq(search_term[1..-1]) end end @@ -59,7 +59,7 @@ it 'adds must_not clauses to the query' do expect(applied_query[:bool][:must_not].length).to eq(1) - expect(applied_query[:bool][:must_not][0][:multi_match][:query]).to eq(search_term) + expect(applied_query[:bool][:must_not][0][:multi_match][:query]).to eq(search_term[1..-1]) end end @@ -72,5 +72,21 @@ expect(applied_query[:bool][:filter][0][:term][:account_id]).to eq(account.id) end end + + context 'when all clause lists are present' do + let(:should) { 'should' } + let(:must) { '+must' } + let(:must_not) { '-nope' } + let(:filter) { 'from:test_account' } + let(:search_term) { should + ' ' + must + ' ' + must_not + ' ' + filter } + let(:account) { Fabricate(:test_account) } + + it 'adds all clauses to the query' do + expect(applied_query[:bool][:should][0][:multi_match][:query]).to eq(should) + expect(applied_query[:bool][:must][0][:multi_match][:query]).to eq(must[1..-1]) + expect(applied_query[:bool][:must_not][0][:multi_match][:query]).to eq(must_not[1..-1]) + expect(applied_query[:bool][:filter][0][:term][:account_id]).to eq(account.id) + end + end end end From 31bd755dd2b0c2db484ec04b36918aeadc4958a3 Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Thu, 20 Jul 2023 11:00:01 -0400 Subject: [PATCH 20/26] Lint a ton more... --- spec/lib/search_query_transformer_spec.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index b8cdc13e07ab29..beb1c44ccabd80 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -50,7 +50,7 @@ it 'adds must clauses to the query' do expect(applied_query[:bool][:must].length).to eq(1) - expect(applied_query[:bool][:must][0][:multi_match][:query]).to eq(search_term[1..-1]) + expect(applied_query[:bool][:must][0][:multi_match][:query]).to eq(search_term[1..]) end end @@ -59,13 +59,13 @@ it 'adds must_not clauses to the query' do expect(applied_query[:bool][:must_not].length).to eq(1) - expect(applied_query[:bool][:must_not][0][:multi_match][:query]).to eq(search_term[1..-1]) + expect(applied_query[:bool][:must_not][0][:multi_match][:query]).to eq(search_term[1..]) end end context 'when filter_clauses are present' do let(:search_term) { 'from:test_account' } - let(:account) { Fabricate(:test_account) } + let(:account) { Fabricate(:account) } it 'adds filter clauses to the query' do expect(applied_query[:bool][:filter].length).to eq(1) @@ -74,17 +74,17 @@ end context 'when all clause lists are present' do - let(:should) { 'should' } - let(:must) { '+must' } - let(:must_not) { '-nope' } - let(:filter) { 'from:test_account' } - let(:search_term) { should + ' ' + must + ' ' + must_not + ' ' + filter } + let(:should_term) { 'should' } + let(:must_term) { '+must' } + let(:must_not_term) { '-nope' } + let(:filter_term) { 'from:test_account' } + let(:search_term) { "#{should_term} #{must_term} #{must_not_term} #{filter_term}" } let(:account) { Fabricate(:test_account) } it 'adds all clauses to the query' do - expect(applied_query[:bool][:should][0][:multi_match][:query]).to eq(should) - expect(applied_query[:bool][:must][0][:multi_match][:query]).to eq(must[1..-1]) - expect(applied_query[:bool][:must_not][0][:multi_match][:query]).to eq(must_not[1..-1]) + expect(applied_query[:bool][:should][0][:multi_match][:query]).to eq(should_term) + expect(applied_query[:bool][:must][0][:multi_match][:query]).to eq(must_term[1..]) + expect(applied_query[:bool][:must_not][0][:multi_match][:query]).to eq(must_not_term[1..]) expect(applied_query[:bool][:filter][0][:term][:account_id]).to eq(account.id) end end From 190278c9f38952a7cf2fd7388f156c52e04e39f7 Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Thu, 20 Jul 2023 11:14:57 -0400 Subject: [PATCH 21/26] Try to pass the filter tests and add one more final test --- spec/lib/search_query_transformer_spec.rb | 33 ++++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index beb1c44ccabd80..842657fcf8180d 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -65,7 +65,7 @@ context 'when filter_clauses are present' do let(:search_term) { 'from:test_account' } - let(:account) { Fabricate(:account) } + let(:account) { Fabricate(:account, username: 'test_account', domain: 'example.com') } it 'adds filter clauses to the query' do expect(applied_query[:bool][:filter].length).to eq(1) @@ -73,13 +73,13 @@ end end - context 'when all clause lists are present' do + context 'when all clauses are present' do let(:should_term) { 'should' } let(:must_term) { '+must' } let(:must_not_term) { '-nope' } let(:filter_term) { 'from:test_account' } - let(:search_term) { "#{should_term} #{must_term} #{must_not_term} #{filter_term}" } - let(:account) { Fabricate(:test_account) } + let(:search_term) { "#{should_term} #{must_term} #{must_not_term} #{filter_term}" } + let(:account) { Fabricate(:account, username: 'test_account', domain: 'example.com') } it 'adds all clauses to the query' do expect(applied_query[:bool][:should][0][:multi_match][:query]).to eq(should_term) @@ -87,6 +87,31 @@ expect(applied_query[:bool][:must_not][0][:multi_match][:query]).to eq(must_not_term[1..]) expect(applied_query[:bool][:filter][0][:term][:account_id]).to eq(account.id) end + + it 'sets minimum_should_match to 1' do + expect(applied_query[:bool][:minimum_should_match]).to eq(1) + end + end + + context 'when all clauses are present and query has all clauses too' do + let(:should_term) { 'should' } + let(:must_term) { '+must' } + let(:must_not_term) { '-nope' } + let(:filter_term) { 'from:test_account' } + let(:search_term) { "#{should_term} #{must_term} #{must_not_term} #{filter_term}" } + let(:query) { { bool: { should: [{ term: { exists: true } }], must: [{ term: { exists: true } }], must_not: [{ term: { exists: true } }], filter: [{ term: { exists: true } }] } } } + let(:account) { Fabricate(:account, username: 'test_account', domain: 'example.com') } + + it 'adds all clauses to the arrays in the query' do + expect(applied_query[:bool][:should].length).to eq(2) + expect(applied_query[:bool][:must].length).to eq(2) + expect(applied_query[:bool][:must_not].length).to eq(2) + expect(applied_query[:bool][:filter].length).to eq(2) + end + + it 'sets minimum_should_match to 1' do + expect(applied_query[:bool][:minimum_should_match]).to eq(1) + end end end end From 6a2733d62a1bee751a359c9b3f4d9a6cc64f3737 Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Thu, 20 Jul 2023 12:07:19 -0400 Subject: [PATCH 22/26] try to add a bit of debugs so I can see what's up --- spec/lib/search_query_transformer_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index 842657fcf8180d..2e07fd1c4a446c 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -68,8 +68,13 @@ let(:account) { Fabricate(:account, username: 'test_account', domain: 'example.com') } it 'adds filter clauses to the query' do + puts "Initial count of Account records: #{Account.count}" + puts "Account being created: #{account.attributes.inspect}" + expect(applied_query[:bool][:filter].length).to eq(1) expect(applied_query[:bool][:filter][0][:term][:account_id]).to eq(account.id) + + puts "Final count of Account records: #{Account.count}" end end From f2cc491db4c6ca02be0279405290f551860526d1 Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Thu, 20 Jul 2023 12:23:34 -0400 Subject: [PATCH 23/26] bluch. puts don't work... --- spec/lib/search_query_transformer_spec.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index 2e07fd1c4a446c..8222ca7cec24e3 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -65,16 +65,11 @@ context 'when filter_clauses are present' do let(:search_term) { 'from:test_account' } - let(:account) { Fabricate(:account, username: 'test_account', domain: 'example.com') } + # let(:account) { Fabricate(:account, username: 'test_account', domain: 'example.com') } it 'adds filter clauses to the query' do - puts "Initial count of Account records: #{Account.count}" - puts "Account being created: #{account.attributes.inspect}" - expect(applied_query[:bool][:filter].length).to eq(1) - expect(applied_query[:bool][:filter][0][:term][:account_id]).to eq(account.id) - - puts "Final count of Account records: #{Account.count}" + expect(applied_query[:bool][:filter][0][:term][:account_id]).to eq(search_term) end end From 3de1b18ca71477a01de23ff6a4e10c3cf116c841 Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Thu, 20 Jul 2023 12:39:57 -0400 Subject: [PATCH 24/26] let's try a slightly more explict search term --- spec/lib/search_query_transformer_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index 8222ca7cec24e3..acded3dd2766e2 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -64,8 +64,8 @@ end context 'when filter_clauses are present' do - let(:search_term) { 'from:test_account' } - # let(:account) { Fabricate(:account, username: 'test_account', domain: 'example.com') } + let(:search_term) { 'from:@test_account@example.com' } + let(:account) { Fabricate(:account, username: 'test_account', domain: 'example.com') } it 'adds filter clauses to the query' do expect(applied_query[:bool][:filter].length).to eq(1) From 80765ff1ac996d40847f149c0b3856b7108c5c65 Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Thu, 20 Jul 2023 15:11:38 -0400 Subject: [PATCH 25/26] I think I should be passing all the tests now --- spec/lib/search_query_transformer_spec.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index acded3dd2766e2..8ec85f11f1d9a1 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -65,11 +65,13 @@ context 'when filter_clauses are present' do let(:search_term) { 'from:@test_account@example.com' } - let(:account) { Fabricate(:account, username: 'test_account', domain: 'example.com') } it 'adds filter clauses to the query' do + account = Fabricate(:account, username: 'test_account', domain: 'example.com') + expect(applied_query[:bool][:filter].length).to eq(1) - expect(applied_query[:bool][:filter][0][:term][:account_id]).to eq(search_term) + expect(applied_query[:bool][:filter][0][:term][:account_id]).to eq(account.id) + puts "Final count of Account records: #{Account.count}" end end @@ -77,11 +79,12 @@ let(:should_term) { 'should' } let(:must_term) { '+must' } let(:must_not_term) { '-nope' } - let(:filter_term) { 'from:test_account' } + let(:filter_term) { 'from:@test_account@example.com' } let(:search_term) { "#{should_term} #{must_term} #{must_not_term} #{filter_term}" } - let(:account) { Fabricate(:account, username: 'test_account', domain: 'example.com') } it 'adds all clauses to the query' do + account = Fabricate(:account, username: 'test_account', domain: 'example.com') + expect(applied_query[:bool][:should][0][:multi_match][:query]).to eq(should_term) expect(applied_query[:bool][:must][0][:multi_match][:query]).to eq(must_term[1..]) expect(applied_query[:bool][:must_not][0][:multi_match][:query]).to eq(must_not_term[1..]) @@ -89,6 +92,8 @@ end it 'sets minimum_should_match to 1' do + account = Fabricate(:account, username: 'test_account', domain: 'example.com') + expect(applied_query[:bool][:minimum_should_match]).to eq(1) end end @@ -97,12 +102,13 @@ let(:should_term) { 'should' } let(:must_term) { '+must' } let(:must_not_term) { '-nope' } - let(:filter_term) { 'from:test_account' } + let(:filter_term) { 'from:@test_account@example.com' } let(:search_term) { "#{should_term} #{must_term} #{must_not_term} #{filter_term}" } let(:query) { { bool: { should: [{ term: { exists: true } }], must: [{ term: { exists: true } }], must_not: [{ term: { exists: true } }], filter: [{ term: { exists: true } }] } } } - let(:account) { Fabricate(:account, username: 'test_account', domain: 'example.com') } it 'adds all clauses to the arrays in the query' do + account = Fabricate(:account, username: 'test_account', domain: 'example.com') + expect(applied_query[:bool][:should].length).to eq(2) expect(applied_query[:bool][:must].length).to eq(2) expect(applied_query[:bool][:must_not].length).to eq(2) @@ -110,6 +116,8 @@ end it 'sets minimum_should_match to 1' do + account = Fabricate(:account, username: 'test_account', domain: 'example.com') + expect(applied_query[:bool][:minimum_should_match]).to eq(1) end end From 89fd1ee0d4eb9f3e11353b50dc5fcbf30a6ccbec Mon Sep 17 00:00:00 2001 From: jsgoldstein Date: Thu, 20 Jul 2023 15:15:27 -0400 Subject: [PATCH 26/26] I just need the accounts, I don't need to assign it to anything --- spec/lib/search_query_transformer_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/lib/search_query_transformer_spec.rb b/spec/lib/search_query_transformer_spec.rb index 8ec85f11f1d9a1..3a71bbeea75f87 100644 --- a/spec/lib/search_query_transformer_spec.rb +++ b/spec/lib/search_query_transformer_spec.rb @@ -92,7 +92,7 @@ end it 'sets minimum_should_match to 1' do - account = Fabricate(:account, username: 'test_account', domain: 'example.com') + Fabricate(:account, username: 'test_account', domain: 'example.com') expect(applied_query[:bool][:minimum_should_match]).to eq(1) end @@ -107,7 +107,7 @@ let(:query) { { bool: { should: [{ term: { exists: true } }], must: [{ term: { exists: true } }], must_not: [{ term: { exists: true } }], filter: [{ term: { exists: true } }] } } } it 'adds all clauses to the arrays in the query' do - account = Fabricate(:account, username: 'test_account', domain: 'example.com') + Fabricate(:account, username: 'test_account', domain: 'example.com') expect(applied_query[:bool][:should].length).to eq(2) expect(applied_query[:bool][:must].length).to eq(2) @@ -116,7 +116,7 @@ end it 'sets minimum_should_match to 1' do - account = Fabricate(:account, username: 'test_account', domain: 'example.com') + Fabricate(:account, username: 'test_account', domain: 'example.com') expect(applied_query[:bool][:minimum_should_match]).to eq(1) end