Skip to content

Commit

Permalink
feat: cutoff slash at the end of link_url
Browse files Browse the repository at this point in the history
  • Loading branch information
woto committed Jun 17, 2023
1 parent 0f4b8fd commit a223dfb
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/models/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 } },
Expand Down
2 changes: 1 addition & 1 deletion app/queries/things_search_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion spec/api/entities_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion spec/interactors/entities/seek_interactor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
)
Expand Down
11 changes: 7 additions & 4 deletions spec/models/entity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
30 changes: 30 additions & 0 deletions spec/queries/things_search_query_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a223dfb

Please sign in to comment.