Add group suggestion
This commit is contained in:
parent
141a3d8a01
commit
c6417be067
5 changed files with 24 additions and 5 deletions
|
@ -35,6 +35,8 @@ class AccountsIndex < Chewy::Index
|
||||||
field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'content'
|
field :edge_ngram, type: 'text', analyzer: 'edge_ngram', search_analyzer: 'content'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
field :actor_type, type: 'keyword', analyzer: 'content'
|
||||||
|
|
||||||
field :following_count, type: 'long', value: ->(account) { account.following.local.count }
|
field :following_count, type: 'long', value: ->(account) { account.following.local.count }
|
||||||
field :followers_count, type: 'long', value: ->(account) { account.followers.local.count }
|
field :followers_count, type: 'long', value: ->(account) { account.followers.local.count }
|
||||||
field :subscribing_count, type: 'long', value: ->(account) { account.subscribing.local.count }
|
field :subscribing_count, type: 'long', value: ->(account) { account.subscribing.local.count }
|
||||||
|
|
|
@ -18,6 +18,7 @@ class Api::V1::Accounts::SearchController < Api::BaseController
|
||||||
limit: limit_param(DEFAULT_ACCOUNTS_LIMIT),
|
limit: limit_param(DEFAULT_ACCOUNTS_LIMIT),
|
||||||
resolve: truthy_param?(:resolve),
|
resolve: truthy_param?(:resolve),
|
||||||
following: truthy_param?(:following),
|
following: truthy_param?(:following),
|
||||||
|
group_only: truthy_param?(:group_only),
|
||||||
offset: params[:offset]
|
offset: params[:offset]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -451,9 +451,11 @@ const fetchComposeSuggestionsAccounts = throttle((dispatch, getState, token) =>
|
||||||
}),
|
}),
|
||||||
|
|
||||||
params: {
|
params: {
|
||||||
q: token.slice(1),
|
q: token.replace(/^@@?/, ''),
|
||||||
resolve: false,
|
resolve: false,
|
||||||
limit: 4,
|
limit: 4,
|
||||||
|
following: token.startsWith('@@'),
|
||||||
|
group_only: token.startsWith('@@'),
|
||||||
},
|
},
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
dispatch(importFetchedAccounts(response.data));
|
dispatch(importFetchedAccounts(response.data));
|
||||||
|
|
|
@ -443,9 +443,13 @@ class Account < ApplicationRecord
|
||||||
DeliveryFailureTracker.without_unavailable(urls)
|
DeliveryFailureTracker.without_unavailable(urls)
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_for(terms, limit = 10, offset = 0)
|
def search_for(terms, limit = 10, group = false, offset = 0)
|
||||||
textsearch, query = generate_query_for_search(terms)
|
textsearch, query = generate_query_for_search(terms)
|
||||||
|
|
||||||
|
sql_where_group = <<-SQL if group
|
||||||
|
AND accounts.actor_type = 'Group'
|
||||||
|
SQL
|
||||||
|
|
||||||
sql = <<-SQL.squish
|
sql = <<-SQL.squish
|
||||||
SELECT
|
SELECT
|
||||||
accounts.*,
|
accounts.*,
|
||||||
|
@ -454,6 +458,7 @@ class Account < ApplicationRecord
|
||||||
WHERE #{query} @@ #{textsearch}
|
WHERE #{query} @@ #{textsearch}
|
||||||
AND accounts.suspended_at IS NULL
|
AND accounts.suspended_at IS NULL
|
||||||
AND accounts.moved_to_account_id IS NULL
|
AND accounts.moved_to_account_id IS NULL
|
||||||
|
#{sql_where_group}
|
||||||
ORDER BY rank DESC
|
ORDER BY rank DESC
|
||||||
LIMIT ? OFFSET ?
|
LIMIT ? OFFSET ?
|
||||||
SQL
|
SQL
|
||||||
|
@ -463,9 +468,13 @@ class Account < ApplicationRecord
|
||||||
records
|
records
|
||||||
end
|
end
|
||||||
|
|
||||||
def advanced_search_for(terms, account, limit = 10, following = false, offset = 0)
|
def advanced_search_for(terms, account, limit = 10, following = false, group = false, offset = 0)
|
||||||
textsearch, query = generate_query_for_search(terms)
|
textsearch, query = generate_query_for_search(terms)
|
||||||
|
|
||||||
|
sql_where_group = <<-SQL if group
|
||||||
|
AND accounts.actor_type = 'Group'
|
||||||
|
SQL
|
||||||
|
|
||||||
if following
|
if following
|
||||||
sql = <<-SQL.squish
|
sql = <<-SQL.squish
|
||||||
WITH first_degree AS (
|
WITH first_degree AS (
|
||||||
|
@ -484,6 +493,7 @@ class Account < ApplicationRecord
|
||||||
AND #{query} @@ #{textsearch}
|
AND #{query} @@ #{textsearch}
|
||||||
AND accounts.suspended_at IS NULL
|
AND accounts.suspended_at IS NULL
|
||||||
AND accounts.moved_to_account_id IS NULL
|
AND accounts.moved_to_account_id IS NULL
|
||||||
|
#{sql_where_group}
|
||||||
GROUP BY accounts.id
|
GROUP BY accounts.id
|
||||||
ORDER BY rank DESC
|
ORDER BY rank DESC
|
||||||
LIMIT ? OFFSET ?
|
LIMIT ? OFFSET ?
|
||||||
|
@ -500,6 +510,7 @@ class Account < ApplicationRecord
|
||||||
WHERE #{query} @@ #{textsearch}
|
WHERE #{query} @@ #{textsearch}
|
||||||
AND accounts.suspended_at IS NULL
|
AND accounts.suspended_at IS NULL
|
||||||
AND accounts.moved_to_account_id IS NULL
|
AND accounts.moved_to_account_id IS NULL
|
||||||
|
#{sql_where_group}
|
||||||
GROUP BY accounts.id
|
GROUP BY accounts.id
|
||||||
ORDER BY rank DESC
|
ORDER BY rank DESC
|
||||||
LIMIT ? OFFSET ?
|
LIMIT ? OFFSET ?
|
||||||
|
|
|
@ -61,11 +61,11 @@ class AccountSearchService < BaseService
|
||||||
end
|
end
|
||||||
|
|
||||||
def advanced_search_results
|
def advanced_search_results
|
||||||
Account.advanced_search_for(terms_for_query, account, limit_for_non_exact_results, options[:following], offset)
|
Account.advanced_search_for(terms_for_query, account, limit_for_non_exact_results, options[:following], options[:group_only], offset)
|
||||||
end
|
end
|
||||||
|
|
||||||
def simple_search_results
|
def simple_search_results
|
||||||
Account.search_for(terms_for_query, limit_for_non_exact_results, offset)
|
Account.search_for(terms_for_query, limit_for_non_exact_results, options[:group_only], offset)
|
||||||
end
|
end
|
||||||
|
|
||||||
def from_elasticsearch
|
def from_elasticsearch
|
||||||
|
@ -80,6 +80,9 @@ class AccountSearchService < BaseService
|
||||||
elsif following_ids.any?
|
elsif following_ids.any?
|
||||||
should_clauses << { terms: { id: following_ids, boost: 100 } }
|
should_clauses << { terms: { id: following_ids, boost: 100 } }
|
||||||
end
|
end
|
||||||
|
if options[:group_only]
|
||||||
|
must_clauses << { term: { actor_type: 'group' } }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
query = { bool: { must: must_clauses, should: should_clauses } }
|
query = { bool: { must: must_clauses, should: should_clauses } }
|
||||||
|
|
Loading…
Reference in a new issue