parent
c0d0ac07c8
commit
4c2675be41
2 changed files with 47 additions and 0 deletions
|
@ -30,6 +30,8 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
def request
|
def request
|
||||||
search = Chewy::Search::Request.new(*indexes).filter(default_filter)
|
search = Chewy::Search::Request.new(*indexes).filter(default_filter)
|
||||||
|
|
||||||
|
search = search.filter(flag_following_only) if following_only?
|
||||||
|
|
||||||
must_clauses.each { |clause| search = search.query.must(clause.to_query) }
|
must_clauses.each { |clause| search = search.query.must(clause.to_query) }
|
||||||
must_not_clauses.each { |clause| search = search.query.must_not(clause.to_query) }
|
must_not_clauses.each { |clause| search = search.query.must_not(clause.to_query) }
|
||||||
filter_clauses.each { |clause| search = search.filter(**clause.to_query) }
|
filter_clauses.each { |clause| search = search.filter(**clause.to_query) }
|
||||||
|
@ -59,6 +61,10 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
@flags = clauses_by_operator.fetch(:flag, []).to_h { |clause| [clause.prefix, clause.term] }
|
@flags = clauses_by_operator.fetch(:flag, []).to_h { |clause| [clause.prefix, clause.term] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def following_only?
|
||||||
|
@flags['following']
|
||||||
|
end
|
||||||
|
|
||||||
def must_clauses
|
def must_clauses
|
||||||
clauses_by_operator.fetch(:must, [])
|
clauses_by_operator.fetch(:must, [])
|
||||||
end
|
end
|
||||||
|
@ -198,6 +204,16 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def flag_following_only
|
||||||
|
{
|
||||||
|
bool: {
|
||||||
|
(@flags['following'] == 'following' ? :must : :must_not) => {
|
||||||
|
terms: { account_id: following_account_ids },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def following_account_ids
|
def following_account_ids
|
||||||
return @following_account_ids if defined?(@following_account_ids)
|
return @following_account_ids if defined?(@following_account_ids)
|
||||||
|
|
||||||
|
@ -299,6 +315,10 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
when 'in'
|
when 'in'
|
||||||
@operator = :flag
|
@operator = :flag
|
||||||
@term = term
|
@term = term
|
||||||
|
if term == 'following'
|
||||||
|
@prefix = 'following'
|
||||||
|
@term = @negated ? 'not_following' : 'following'
|
||||||
|
end
|
||||||
when 'my'
|
when 'my'
|
||||||
@type = :term
|
@type = :term
|
||||||
@term = @options[:current_account]&.id
|
@term = @options[:current_account]&.id
|
||||||
|
|
|
@ -262,5 +262,32 @@ describe StatusesSearchService do
|
||||||
it_behaves_like 'does not hit status', 'when double quote search with multiple letter in word but does not contain half', 'ず ご'
|
it_behaves_like 'does not hit status', 'when double quote search with multiple letter in word but does not contain half', 'ず ご'
|
||||||
it_behaves_like 'hit status', 'when specify user name', 'りんご from:alice'
|
it_behaves_like 'hit status', 'when specify user name', 'りんご from:alice'
|
||||||
it_behaves_like 'does not hit status', 'when specify not existing user name', 'りんご from:ohagi'
|
it_behaves_like 'does not hit status', 'when specify not existing user name', 'りんご from:ohagi'
|
||||||
|
|
||||||
|
context 'when in:following is specified' do
|
||||||
|
let(:following) { Fabricate(:user).account }
|
||||||
|
let(:other) { Fabricate(:user).account }
|
||||||
|
|
||||||
|
before do
|
||||||
|
following.follow!(alice)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with myself' do
|
||||||
|
let(:account) { alice }
|
||||||
|
|
||||||
|
it_behaves_like 'does not hit status', 'when search with following', 'in:following りんご'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with following' do
|
||||||
|
let(:account) { following }
|
||||||
|
|
||||||
|
it_behaves_like 'hit status', 'when search with following', 'in:following りんご'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'without following' do
|
||||||
|
let(:account) { other }
|
||||||
|
|
||||||
|
it_behaves_like 'does not hit status', 'when search with following', 'in:following りんご'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue