Skip to content

Commit 8004014

Browse files
committed
Filter for synonym tags by presence of merger_id
1 parent 1d466b0 commit 8004014

File tree

5 files changed

+16
-50
lines changed

5 files changed

+16
-50
lines changed

app/models/search/tag_indexer.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ def document(object)
6969
has_posted_works: object.has_posted_works?,
7070
tag_type: object.type,
7171
uses: object.taggings_count_cache,
72-
unwrangled: object.unwrangled?,
73-
canonical_or_synonymous: object.synonymous? || object.canonical
72+
unwrangled: object.unwrangled?
7473
).merge(parent_data(object))
7574
end
7675

app/models/search/tag_query.rb

+15-8
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ def document_type
1515
def filters
1616
[
1717
type_filter,
18-
canonical_filter,
19-
canonical_or_synonymous_filter,
18+
wrangling_status_filter,
2019
unwrangleable_filter,
2120
posted_works_filter,
2221
media_filter,
@@ -32,6 +31,7 @@ def filters
3231
def exclusion_filters
3332
[
3433
wrangled_filter
34+
# wrangling_status_exclude_filter
3535
].compact
3636
end
3737

@@ -78,12 +78,19 @@ def type_filter
7878
{ term: { tag_type: options[:type] } } if options[:type]
7979
end
8080

81-
def canonical_filter
82-
term_filter(:canonical, bool_value(options[:canonical])) if options[:canonical].present?
83-
end
84-
85-
def canonical_or_synonymous_filter
86-
term_filter(:canonical_or_synonymous, bool_value(options[:canonical_or_synonymous])) if options[:canonical_or_synonymous].present?
81+
def wrangling_status_filter
82+
case options[:wrangling_status]
83+
when "canonical"
84+
term_filter(:canonical, true)
85+
when "noncanonical"
86+
term_filter(:canonical, false)
87+
when "synonymous"
88+
[{ exists: { field: "merger_id" } }, term_filter(:canonical, false)]
89+
when "canonical_synonymous"
90+
{ bool: { should: [{ exists: { field: "merger_id" } }, term_filter(:canonical, true)] } }
91+
when "noncanonical_nonsynonymous"
92+
[{ bool: { must_not: { exists: { field: "merger_id" } } } }, term_filter(:canonical, false)]
93+
end
8794
end
8895

8996
def unwrangleable_filter

app/models/search/tag_search_form.rb

-17
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class TagSearchForm
2525
def initialize(options={})
2626
@options = options
2727
set_fandoms
28-
set_wrangling_status
2928
@searcher = TagQuery.new(@options.delete_if { |_, v| v.blank? })
3029
end
3130

@@ -37,22 +36,6 @@ def search_results
3736
@searcher.search_results
3837
end
3938

40-
def set_wrangling_status
41-
case @options[:wrangling_status]
42-
when "canonical"
43-
@options[:canonical] = "T"
44-
when "noncanonical"
45-
@options[:canonical] = "F"
46-
when "synonymous"
47-
@options[:canonical] = "F"
48-
@options[:canonical_or_synonymous] = "T"
49-
when "canonical_synonymous"
50-
@options[:canonical_or_synonymous] = "T"
51-
when "noncanonical_nonsynonymous"
52-
@options[:canonical_or_synonymous] = "F"
53-
end
54-
end
55-
5639
def set_fandoms
5740
return if @options[:fandoms].blank?
5841

app/models/tag.rb

-5
Original file line numberDiff line numberDiff line change
@@ -635,11 +635,6 @@ def has_posted_works?
635635
self.works.posted.any?
636636
end
637637

638-
# Returns true if a tag is a synonym of a canonical tag
639-
def synonymous?
640-
!self.canonical? && self.merger_id.present?
641-
end
642-
643638
# sort tags by name
644639
def <=>(another_tag)
645640
name.downcase <=> another_tag.name.downcase

spec/models/tag_spec.rb

-18
Original file line numberDiff line numberDiff line change
@@ -342,24 +342,6 @@ def expect_tag_update_flag_in_redis_to_be(flag)
342342
end
343343
end
344344

345-
describe "synonymous?" do
346-
it "is false for a canonical tag" do
347-
tag = create(:freeform, canonical: true)
348-
expect(tag.synonymous?).to be_falsey
349-
end
350-
351-
it "is false for a non-canonical, non-synonymous tag" do
352-
tag = create(:freeform, canonical: false)
353-
expect(tag.synonymous?).to be_falsey
354-
end
355-
356-
it "is true for a synonymous tag" do
357-
canonical_tag = create(:freeform, canonical: true)
358-
synonym_tag = create(:freeform, canonical: false, merger: canonical_tag)
359-
expect(synonym_tag.synonymous?).to be_truthy
360-
end
361-
end
362-
363345
describe "has_posted_works?" do
364346
before do
365347
create(:work, fandom_string: "love live,jjba")

0 commit comments

Comments
 (0)