post queries: fix handling of '~' operator.
Fix queries like `(~a ~b) (~c ~d)` being handled like `~a ~b ~c ~d`. Caused by trimming AND nodes from the tree before rewriting the '~' operator, which caused `~a` terms to be incorrectly lifted out of subexpressions.
This commit is contained in:
@@ -13,7 +13,7 @@ class PostQuery
|
||||
|
||||
# Return a new PostQuery with aliases replaced.
|
||||
def self.normalize(...)
|
||||
PostQuery.new(...).replace_aliases.trim
|
||||
PostQuery.new(...).replace_aliases.rewrite_opts.trim
|
||||
end
|
||||
|
||||
def initialize(search_or_ast, current_user: User.anonymous, tag_limit: nil, safe_mode: false, hide_deleted_posts: false)
|
||||
@@ -129,6 +129,11 @@ class PostQuery
|
||||
build(ast.trim)
|
||||
end
|
||||
|
||||
# Return a new PostQuery with the '~' operator replaced with OR clauses.
|
||||
def rewrite_opts
|
||||
build(ast.rewrite_opts)
|
||||
end
|
||||
|
||||
# Return a new PostQuery with aliases replaced.
|
||||
def replace_aliases
|
||||
return self if aliases.empty?
|
||||
|
||||
Reference in New Issue
Block a user