Skip to content

Commit 82f6a61

Browse files
committed
feat: cutoff slash at the end of link_url
1 parent 0f4b8fd commit 82f6a61

File tree

6 files changed

+43
-8
lines changed

6 files changed

+43
-8
lines changed

app/models/entity.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def as_indexed_json(_options = {})
108108
text_end: cites.map(&:text_end),
109109
prefix: cites.map(&:prefix),
110110
suffix: cites.map(&:suffix),
111-
link_url: cites.map(&:link_url).compact,
111+
link_url: cites.filter_map { _1.link_url&.chomp('/') },
112112
hostname: hostname&.to_label,
113113
intro:,
114114
lookups: lookups.map { |lookup| { id: lookup.id, title: lookup.title } },

app/queries/things_search_query.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def call
108108
json.array! ['fuck'] do
109109
json.term do
110110
json.set! "link_url.keyword" do
111-
json.value context[:link_url]
111+
json.value context[:link_url]&.chomp('/')
112112
json.boost Rails.application.config.global[:perfect_match_score_boost]
113113
end
114114
end

spec/api/entities_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
'kinds' => [match('id' => topic.id, 'title' => topic.title)],
3333
'links' => ['https://example.com'],
3434
'lookups' => [match('id' => lookup.id, 'title' => lookup.title)],
35-
'title' => entity.title
35+
'title' => entity.title,
36+
'perfect_match' => nil,
3637
)
3738
end
3839
end

spec/interactors/entities/seek_interactor_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
images: [],
3232
kinds: [{ id: 1, title: 'topic' }],
3333
links: ['https://cite.ru'],
34-
lookups: [{ id: 1, title: 'lookup' }]
34+
lookups: [{ id: 1, title: 'lookup' }],
35+
perfect_match: false
3536
)
3637
)
3738
)

spec/models/entity_spec.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
end
100100

101101
describe '#as_indexed_json', responsible: :user do
102-
subject { entity.as_indexed_json }
102+
subject { entity.reload.as_indexed_json }
103103

104104
around do |example|
105105
freeze_time do
@@ -109,14 +109,16 @@
109109

110110
let(:entity) do
111111
create(:entity, title: "https://#{hostname.title}", topics: [topic], lookups: [lookup],
112-
images: [create(:image)])
112+
images: [create(:image)], index: false)
113113
end
114114
let(:lookup) { create(:lookup, title: 'lookup title') }
115115
let(:topic) { create(:topic, title: 'topic title') }
116116
let(:hostname) { create(:hostname) }
117117

118+
let!(:mention) { create(:mention, entities: [entity]) }
119+
118120
before do
119-
create(:mention, entities: [entity])
121+
create(:cite, mention:, entity:, link_url: 'https://cite.link/')
120122
end
121123

122124
it 'returns correct result' do
@@ -133,7 +135,8 @@
133135
user_id: entity.user_id,
134136
entities_mentions_count: 1,
135137
created_at: Time.current,
136-
updated_at: Time.current
138+
updated_at: Time.current,
139+
link_url: ['https://cite.link']
137140
)
138141
end
139142
end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
describe ThingsSearchQuery do
6+
subject { described_class.call(fragment:, search_string: '', link_url: 'https://link.url/', from: 0, size: 1) }
7+
8+
let(:texts) do
9+
[Fragment::Text.new(
10+
text_start: 'British-based', text_end: '', prefix: 'Jamaican-born and', suffix: 'community leader and'
11+
)]
12+
end
13+
let(:fragment) { Fragment::Struct.new(url: 'https://example.com', texts:) }
14+
15+
it 'cuts exessive slash at the end of the link url' do
16+
expect(subject.object).to include(
17+
body: include(
18+
query: include(
19+
bool: include(
20+
should: include(
21+
term: include(
22+
'link_url.keyword': include({ value: 'https://link.url' })
23+
)
24+
)
25+
)
26+
)
27+
)
28+
)
29+
end
30+
end

0 commit comments

Comments
 (0)