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
|
||||
extend Memoist
|
||||
|
||||
# How many tags a `blah*` search should match.
|
||||
MAX_WILDCARD_TAGS = 100
|
||||
|
||||
COUNT_METATAGS = %w[
|
||||
comment_count deleted_comment_count active_comment_count
|
||||
note_count deleted_note_count active_note_count
|
||||
@@ -77,9 +80,9 @@ class PostQueryBuilder
|
||||
optional_tags = optional_tags.map(&:name)
|
||||
required_tags = required_tags.map(&:name)
|
||||
|
||||
negated_tags += negated_wildcard_tags.flat_map { |tag| Tag.wildcard_matches(tag.name) }
|
||||
optional_tags += optional_wildcard_tags.flat_map { |tag| Tag.wildcard_matches(tag.name) }
|
||||
optional_tags += required_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).limit(MAX_WILDCARD_TAGS).pluck(: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 << "(#{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)
|
||||
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
|
||||
Tag.wildcard_matches(tag_string)
|
||||
Tag.wildcard_matches(tag_string).limit(PostQueryBuilder::MAX_WILDCARD_TAGS).pluck(:name)
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
def tag_set_presenter
|
||||
@tag_set_presenter ||= TagSetPresenter.new(related_tags.take(MAX_SIDEBAR_TAGS))
|
||||
@tag_set_presenter ||= TagSetPresenter.new(related_tags)
|
||||
end
|
||||
|
||||
def tag_list_html(**options)
|
||||
|
||||
@@ -249,8 +249,8 @@ class Tag < ApplicationRecord
|
||||
name_matches(name).or(alias_matches(name))
|
||||
end
|
||||
|
||||
def wildcard_matches(tag, limit: 25)
|
||||
nonempty.name_matches(tag).order(post_count: :desc, name: :asc).limit(limit).pluck(:name)
|
||||
def wildcard_matches(tag)
|
||||
nonempty.name_matches(tag).order(post_count: :desc, name: :asc)
|
||||
end
|
||||
|
||||
def abbreviation_matches(abbrev)
|
||||
|
||||
Reference in New Issue
Block a user