Add before: and after: filters
This commit is contained in:
parent
a6ee508eb7
commit
30faf1f6da
1 changed files with 15 additions and 2 deletions
|
@ -45,7 +45,7 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
def clause_to_filter(clause)
|
def clause_to_filter(clause)
|
||||||
case clause
|
case clause
|
||||||
when PrefixClause
|
when PrefixClause
|
||||||
{ term: { clause.filter => clause.term } }
|
{ clause.query => { clause.filter => clause.term } }
|
||||||
else
|
else
|
||||||
raise "Unexpected clause type: #{clause}"
|
raise "Unexpected clause type: #{clause}"
|
||||||
end
|
end
|
||||||
|
@ -99,9 +99,11 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
end
|
end
|
||||||
|
|
||||||
class PrefixClause
|
class PrefixClause
|
||||||
attr_reader :filter, :operator, :term, :order
|
attr_reader :filter, :operator, :term, :order, :query
|
||||||
|
|
||||||
def initialize(prefix, operator, term)
|
def initialize(prefix, operator, term)
|
||||||
|
@query = :term
|
||||||
|
|
||||||
case operator
|
case operator
|
||||||
when '+', nil
|
when '+', nil
|
||||||
@operator = :filter
|
@operator = :filter
|
||||||
|
@ -115,6 +117,17 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
when 'domain', 'is', 'has', 'lang', 'visibility'
|
when 'domain', 'is', 'has', 'lang', 'visibility'
|
||||||
@filter = prefix.to_s
|
@filter = prefix.to_s
|
||||||
@term = term
|
@term = term
|
||||||
|
when 'before', 'after'
|
||||||
|
@query = :range
|
||||||
|
@filter = 'created_at'
|
||||||
|
case prefix
|
||||||
|
when 'before'
|
||||||
|
@term = { lt: term }
|
||||||
|
when 'after'
|
||||||
|
@term = { gt: term }
|
||||||
|
else
|
||||||
|
raise Mastodon::SyntaxError
|
||||||
|
end
|
||||||
when 'from'
|
when 'from'
|
||||||
@filter = :account_id
|
@filter = :account_id
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue