Fix
This commit is contained in:
parent
fdf1d6df38
commit
4bc813eb67
2 changed files with 113 additions and 17 deletions
|
@ -18,6 +18,7 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
|
|
||||||
@clauses = clauses
|
@clauses = clauses
|
||||||
@options = options
|
@options = options
|
||||||
|
@searchability = options[:searchability]&.to_sym || :public
|
||||||
|
|
||||||
flags_from_clauses!
|
flags_from_clauses!
|
||||||
end
|
end
|
||||||
|
@ -64,33 +65,128 @@ class SearchQueryTransformer < Parslet::Transform
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_filter
|
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: {
|
bool: {
|
||||||
should: [
|
should: definition_should,
|
||||||
|
minimum_should_match: 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_should1
|
||||||
|
{
|
||||||
|
term: {
|
||||||
|
_index: PublicStatusesIndex.index_name,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_should2
|
||||||
|
{
|
||||||
|
bool: {
|
||||||
|
must: [
|
||||||
{
|
{
|
||||||
term: {
|
term: {
|
||||||
_index: PublicStatusesIndex.index_name,
|
_index: StatusesIndex.index_name,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
bool: {
|
term: {
|
||||||
must: [
|
searchable_by: @options[:current_account].id,
|
||||||
{
|
|
||||||
term: {
|
|
||||||
_index: StatusesIndex.index_name,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
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
|
end
|
||||||
|
|
|
@ -1087,7 +1087,7 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
regenerator-runtime "^0.12.0"
|
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"
|
version "7.22.15"
|
||||||
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.22.15.tgz#38f46494ccf6cf020bd4eed7124b425e83e523b8"
|
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.22.15.tgz#38f46494ccf6cf020bd4eed7124b425e83e523b8"
|
||||||
integrity sha512-T0O+aa+4w0u06iNmapipJXMV4HoUir03hpx3/YqXXhu9xim3w+dVphjFWl1OH8NbZHw5Lbm9k45drDkgq2VNNA==
|
integrity sha512-T0O+aa+4w0u06iNmapipJXMV4HoUir03hpx3/YqXXhu9xim3w+dVphjFWl1OH8NbZHw5Lbm9k45drDkgq2VNNA==
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue