Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Sep 6, 2023
1 parent fdf1d6d commit 4bc813e
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 17 deletions.
128 changes: 112 additions & 16 deletions app/lib/search_query_transformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def initialize(clauses, options = {})

@clauses = clauses
@options = options
@searchability = options[:searchability]&.to_sym || :public

flags_from_clauses!
end
Expand Down Expand Up @@ -64,33 +65,128 @@ def indexes
end

def default_filter
definition_should = [
default_should1,
default_should2,
non_publicly_searchable,
searchability_limited,
]
definition_should << searchability_public if %i(public).include?(@searchability)
definition_should << searchability_private if %i(public private).include?(@searchability)

{
bool: {
should: definition_should,
minimum_should_match: 1,
},
}
end

def default_should1
{
term: {
_index: PublicStatusesIndex.index_name,
},
}
end

def default_should2
{
bool: {
should: [
must: [
{
term: {
_index: PublicStatusesIndex.index_name,
_index: StatusesIndex.index_name,
},
},
{
bool: {
must: [
{
term: {
_index: StatusesIndex.index_name,
},
},
{
term: {
searchable_by: @options[:current_account].id,
},
},
],
term: {
searchable_by: @options[:current_account].id,
},
},
],
},
}
end

minimum_should_match: 1,
def non_publicly_searchable
{
bool: {
must: [
{
term: { _index: StatusesIndex.index_name },
},
{
exists: {
field: 'searchability',
},
},
{
term: { searchable_by: @account.id },
},
],
must_not: [
{
term: { searchability: 'limited' },
},
],
},
}
end

def searchability_public
{
bool: {
must: [
{
exists: {
field: 'searchability',
},
},
{
term: { searchability: 'public' },
},
],
},
}
end

def searchability_private
{
bool: {
must: [
{
exists: {
field: 'searchability',
},
},
{
term: { searchability: 'private' },
},
{
terms: { account_id: following_account_ids },
},
],
},
}
end

def searchability_limited
{
bool: {
must: [
{
exists: {
field: 'searchability',
},
},
{
term: { searchability: 'limited' },
},
{
term: { account_id: @account.id },
},
],
},
}
end
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@
dependencies:
regenerator-runtime "^0.12.0"

"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.0", "@babel/runtime@^7.12.1", "@babel/runtime@^7.12.5", "@babel/runtime@^7.13.8", "@babel/runtime@^7.18.3", "@babel/runtime@^7.2.0", "@babel/runtime@^7.20.13", "@babel/runtime@^7.20.7", "@babel/runtime@^7.22.3", "@babel/runtime@^7.3.1", "@babel/runtime@^7.5.5", "@babel/runtime@^7.6.3", "@babel/runtime@^7.8.4", "@babel/runtime@^7.8.7", "@babel/runtime@^7.9.2":
"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.0", "@babel/runtime@^7.12.1", "@babel/runtime@^7.12.5", "@babel/runtime@^7.13.8", "@babel/runtime@^7.15.4", "@babel/runtime@^7.18.3", "@babel/runtime@^7.2.0", "@babel/runtime@^7.20.13", "@babel/runtime@^7.20.7", "@babel/runtime@^7.22.3", "@babel/runtime@^7.3.1", "@babel/runtime@^7.5.5", "@babel/runtime@^7.6.3", "@babel/runtime@^7.8.4", "@babel/runtime@^7.8.7", "@babel/runtime@^7.9.2":
version "7.22.15"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.22.15.tgz#38f46494ccf6cf020bd4eed7124b425e83e523b8"
integrity sha512-T0O+aa+4w0u06iNmapipJXMV4HoUir03hpx3/YqXXhu9xim3w+dVphjFWl1OH8NbZHw5Lbm9k45drDkgq2VNNA==
Expand Down

0 comments on commit 4bc813e

Please sign in to comment.