From a223dfb936ea5519cb9ffffbaa900773a84aea02 Mon Sep 17 00:00:00 2001 From: Ruslan Kornev Date: Fri, 16 Jun 2023 06:33:57 +0600 Subject: [PATCH] feat: cutoff slash at the end of link_url --- app/models/entity.rb | 2 +- app/queries/things_search_query.rb | 2 +- spec/api/entities_spec.rb | 3 +- .../entities/seek_interactor_spec.rb | 3 +- spec/models/entity_spec.rb | 11 ++++--- spec/queries/things_search_query_spec.rb | 30 +++++++++++++++++++ 6 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 spec/queries/things_search_query_spec.rb diff --git a/app/models/entity.rb b/app/models/entity.rb index 1feb85ba..b04ae7ec 100644 --- a/app/models/entity.rb +++ b/app/models/entity.rb @@ -108,7 +108,7 @@ def as_indexed_json(_options = {}) text_end: cites.map(&:text_end), prefix: cites.map(&:prefix), suffix: cites.map(&:suffix), - link_url: cites.map(&:link_url).compact, + link_url: cites.filter_map { _1.link_url&.chomp('/') }, hostname: hostname&.to_label, intro:, lookups: lookups.map { |lookup| { id: lookup.id, title: lookup.title } }, diff --git a/app/queries/things_search_query.rb b/app/queries/things_search_query.rb index 2e6d06f4..44eb0212 100644 --- a/app/queries/things_search_query.rb +++ b/app/queries/things_search_query.rb @@ -108,7 +108,7 @@ def call json.array! ['fuck'] do json.term do json.set! "link_url.keyword" do - json.value context[:link_url] + json.value context[:link_url]&.chomp('/') json.boost Rails.application.config.global[:perfect_match_score_boost] end end diff --git a/spec/api/entities_spec.rb b/spec/api/entities_spec.rb index 4b6c9f53..04a5e9bd 100644 --- a/spec/api/entities_spec.rb +++ b/spec/api/entities_spec.rb @@ -32,7 +32,8 @@ 'kinds' => [match('id' => topic.id, 'title' => topic.title)], 'links' => ['https://example.com'], 'lookups' => [match('id' => lookup.id, 'title' => lookup.title)], - 'title' => entity.title + 'title' => entity.title, + 'perfect_match' => nil, ) end end diff --git a/spec/interactors/entities/seek_interactor_spec.rb b/spec/interactors/entities/seek_interactor_spec.rb index 09bb800a..f474df3d 100644 --- a/spec/interactors/entities/seek_interactor_spec.rb +++ b/spec/interactors/entities/seek_interactor_spec.rb @@ -31,7 +31,8 @@ images: [], kinds: [{ id: 1, title: 'topic' }], links: ['https://cite.ru'], - lookups: [{ id: 1, title: 'lookup' }] + lookups: [{ id: 1, title: 'lookup' }], + perfect_match: false ) ) ) diff --git a/spec/models/entity_spec.rb b/spec/models/entity_spec.rb index b1bb1d7a..bdb8a77e 100644 --- a/spec/models/entity_spec.rb +++ b/spec/models/entity_spec.rb @@ -99,7 +99,7 @@ end describe '#as_indexed_json', responsible: :user do - subject { entity.as_indexed_json } + subject { entity.reload.as_indexed_json } around do |example| freeze_time do @@ -109,14 +109,16 @@ let(:entity) do create(:entity, title: "https://#{hostname.title}", topics: [topic], lookups: [lookup], - images: [create(:image)]) + images: [create(:image)], index: false) end let(:lookup) { create(:lookup, title: 'lookup title') } let(:topic) { create(:topic, title: 'topic title') } let(:hostname) { create(:hostname) } + let!(:mention) { create(:mention, entities: [entity]) } + before do - create(:mention, entities: [entity]) + create(:cite, mention:, entity:, link_url: 'https://cite.link/') end it 'returns correct result' do @@ -133,7 +135,8 @@ user_id: entity.user_id, entities_mentions_count: 1, created_at: Time.current, - updated_at: Time.current + updated_at: Time.current, + link_url: ['https://cite.link/'] ) end end diff --git a/spec/queries/things_search_query_spec.rb b/spec/queries/things_search_query_spec.rb new file mode 100644 index 00000000..e4a17515 --- /dev/null +++ b/spec/queries/things_search_query_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe ThingsSearchQuery do + subject { described_class.call(fragment:, search_string: '', link_url: 'https://link.url/', from: 0, size: 1) } + + let(:texts) do + [Fragment::Text.new( + text_start: 'British-based', text_end: '', prefix: 'Jamaican-born and', suffix: 'community leader and' + )] + end + let(:fragment) { Fragment::Struct.new(url: 'https://example.com', texts:) } + + it 'cuts exessive slash at the end of the link url' do + expect(subject.object).to include( + body: include( + query: include( + bool: include( + should: include( + term: include( + 'link_url.keyword': include({ value: 'https://link.url' }) + ) + ) + ) + ) + ) + ) + end +end