search: let wildcard searches match up to 100 tags.
Let searching for things like *_legwear match up to 100 tags. Previously the limit was 25.
This commit is contained in:
@@ -3,6 +3,9 @@ require "strscan"
|
|||||||
class PostQueryBuilder
|
class PostQueryBuilder
|
||||||
extend Memoist
|
extend Memoist
|
||||||
|
|
||||||
|
# How many tags a `blah*` search should match.
|
||||||
|
MAX_WILDCARD_TAGS = 100
|
||||||
|
|
||||||
COUNT_METATAGS = %w[
|
COUNT_METATAGS = %w[
|
||||||
comment_count deleted_comment_count active_comment_count
|
comment_count deleted_comment_count active_comment_count
|
||||||
note_count deleted_note_count active_note_count
|
note_count deleted_note_count active_note_count
|
||||||
@@ -77,9 +80,9 @@ class PostQueryBuilder
|
|||||||
optional_tags = optional_tags.map(&:name)
|
optional_tags = optional_tags.map(&:name)
|
||||||
required_tags = required_tags.map(&:name)
|
required_tags = required_tags.map(&:name)
|
||||||
|
|
||||||
negated_tags += negated_wildcard_tags.flat_map { |tag| Tag.wildcard_matches(tag.name) }
|
negated_tags += negated_wildcard_tags.flat_map { |tag| Tag.wildcard_matches(tag.name).limit(MAX_WILDCARD_TAGS).pluck(:name) }
|
||||||
optional_tags += optional_wildcard_tags.flat_map { |tag| Tag.wildcard_matches(tag.name) }
|
optional_tags += optional_wildcard_tags.flat_map { |tag| Tag.wildcard_matches(tag.name).limit(MAX_WILDCARD_TAGS).pluck(:name) }
|
||||||
optional_tags += required_wildcard_tags.flat_map { |tag| Tag.wildcard_matches(tag.name) }
|
optional_tags += required_wildcard_tags.flat_map { |tag| Tag.wildcard_matches(tag.name).limit(MAX_WILDCARD_TAGS).pluck(:name) }
|
||||||
|
|
||||||
tsquery << "!(#{negated_tags.sort.uniq.map(&:to_escaped_for_tsquery).join(" | ")})" if negated_tags.present?
|
tsquery << "!(#{negated_tags.sort.uniq.map(&:to_escaped_for_tsquery).join(" | ")})" if negated_tags.present?
|
||||||
tsquery << "(#{optional_tags.sort.uniq.map(&:to_escaped_for_tsquery).join(" | ")})" if optional_tags.present?
|
tsquery << "(#{optional_tags.sort.uniq.map(&:to_escaped_for_tsquery).join(" | ")})" if optional_tags.present?
|
||||||
|
|||||||
@@ -187,16 +187,19 @@ module PostSets
|
|||||||
RelatedTagCalculator.frequent_tags_for_post_array(posts).take(MAX_SIDEBAR_TAGS)
|
RelatedTagCalculator.frequent_tags_for_post_array(posts).take(MAX_SIDEBAR_TAGS)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Wildcard searches can show up to 100 tags in the sidebar, not 25,
|
||||||
|
# because that's how many tags the search itself will use.
|
||||||
def wildcard_tags
|
def wildcard_tags
|
||||||
Tag.wildcard_matches(tag_string)
|
Tag.wildcard_matches(tag_string).limit(PostQueryBuilder::MAX_WILDCARD_TAGS).pluck(:name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def saved_search_tags
|
def saved_search_tags
|
||||||
["search:all"] + SavedSearch.labels_for(CurrentUser.user.id).map {|x| "search:#{x}"}
|
searches = ["search:all"] + SavedSearch.labels_for(CurrentUser.user.id).map {|x| "search:#{x}"}
|
||||||
|
searches.take(MAX_SIDEBAR_TAGS)
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_set_presenter
|
def tag_set_presenter
|
||||||
@tag_set_presenter ||= TagSetPresenter.new(related_tags.take(MAX_SIDEBAR_TAGS))
|
@tag_set_presenter ||= TagSetPresenter.new(related_tags)
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_list_html(**options)
|
def tag_list_html(**options)
|
||||||
|
|||||||
@@ -249,8 +249,8 @@ class Tag < ApplicationRecord
|
|||||||
name_matches(name).or(alias_matches(name))
|
name_matches(name).or(alias_matches(name))
|
||||||
end
|
end
|
||||||
|
|
||||||
def wildcard_matches(tag, limit: 25)
|
def wildcard_matches(tag)
|
||||||
nonempty.name_matches(tag).order(post_count: :desc, name: :asc).limit(limit).pluck(:name)
|
nonempty.name_matches(tag).order(post_count: :desc, name: :asc)
|
||||||
end
|
end
|
||||||
|
|
||||||
def abbreviation_matches(abbrev)
|
def abbreviation_matches(abbrev)
|
||||||
|
|||||||
Reference in New Issue
Block a user