mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Improve search queries (#755)
* refactoring search fields * Searching without spaces * Adapting nospace term to a prefix query * Fixing algorithm/dataset filter * filtering using match * Removing addTypeFilterToQuery() * Removing console log messages
This commit is contained in:
parent
60cac45e89
commit
58781ff95f
@ -33,15 +33,6 @@ export const FilterByTypeOptions = {
|
|||||||
type FilterByTypeOptions =
|
type FilterByTypeOptions =
|
||||||
typeof FilterByTypeOptions[keyof typeof FilterByTypeOptions]
|
typeof FilterByTypeOptions[keyof typeof FilterByTypeOptions]
|
||||||
|
|
||||||
function addTypeFilterToQuery(sortTerm: string, typeFilter: string): string {
|
|
||||||
sortTerm = typeFilter
|
|
||||||
? sortTerm === ''
|
|
||||||
? `service.attributes.main.type:${typeFilter}`
|
|
||||||
: `${sortTerm} AND service.attributes.main.type:${typeFilter}`
|
|
||||||
: sortTerm
|
|
||||||
return sortTerm
|
|
||||||
}
|
|
||||||
|
|
||||||
function getSortType(sortParam: string): string {
|
function getSortType(sortParam: string): string {
|
||||||
const sortTerm =
|
const sortTerm =
|
||||||
sortParam === SortTermOptions.Created
|
sortParam === SortTermOptions.Created
|
||||||
@ -65,7 +56,6 @@ export function getSearchQuery(
|
|||||||
const sortTerm = getSortType(sort)
|
const sortTerm = getSortType(sort)
|
||||||
const sortValue = sortOrder === SortValueOptions.Ascending ? 1 : -1
|
const sortValue = sortOrder === SortValueOptions.Ascending ? 1 : -1
|
||||||
const emptySearchTerm = text === undefined || text === ''
|
const emptySearchTerm = text === undefined || text === ''
|
||||||
|
|
||||||
let searchTerm = owner
|
let searchTerm = owner
|
||||||
? `(publicKey.owner:${owner})`
|
? `(publicKey.owner:${owner})`
|
||||||
: tags
|
: tags
|
||||||
@ -77,16 +67,26 @@ export function getSearchQuery(
|
|||||||
: text || ''
|
: text || ''
|
||||||
|
|
||||||
searchTerm = searchTerm.trim()
|
searchTerm = searchTerm.trim()
|
||||||
let modifiedSearchTerm = searchTerm.split(' ').join(' OR ').trim()
|
const modifiedSearchTerm = searchTerm.split(' ').join(' OR ').trim()
|
||||||
modifiedSearchTerm = addTypeFilterToQuery(modifiedSearchTerm, serviceType)
|
const noSpaceSearchTerm = searchTerm.split(' ').join('').trim()
|
||||||
searchTerm = addTypeFilterToQuery(searchTerm, serviceType)
|
|
||||||
const prefixedSearchTerm =
|
const prefixedSearchTerm =
|
||||||
emptySearchTerm && searchTerm
|
emptySearchTerm && searchTerm
|
||||||
? searchTerm
|
? searchTerm
|
||||||
: !emptySearchTerm && searchTerm
|
: !emptySearchTerm && searchTerm
|
||||||
? '*' + searchTerm + '*'
|
? '*' + searchTerm + '*'
|
||||||
: '**'
|
: '**'
|
||||||
|
const searchFields = [
|
||||||
|
'id',
|
||||||
|
'publicKey.owner',
|
||||||
|
'dataToken',
|
||||||
|
'dataTokenInfo.name',
|
||||||
|
'dataTokenInfo.symbol',
|
||||||
|
'service.attributes.main.name^10',
|
||||||
|
'service.attributes.main.author',
|
||||||
|
'service.attributes.additionalInformation.description',
|
||||||
|
'service.attributes.additionalInformation.tags'
|
||||||
|
]
|
||||||
return {
|
return {
|
||||||
page: Number(page) || 1,
|
page: Number(page) || 1,
|
||||||
offset: Number(offset) || 21,
|
offset: Number(offset) || 21,
|
||||||
@ -99,22 +99,20 @@ export function getSearchQuery(
|
|||||||
{
|
{
|
||||||
query_string: {
|
query_string: {
|
||||||
query: `${modifiedSearchTerm}`,
|
query: `${modifiedSearchTerm}`,
|
||||||
fields: [
|
fields: searchFields,
|
||||||
'id',
|
|
||||||
'publicKey.owner',
|
|
||||||
'dataToken',
|
|
||||||
'dataTokenInfo.name',
|
|
||||||
'dataTokenInfo.symbol',
|
|
||||||
'service.attributes.main.name^10',
|
|
||||||
'service.attributes.main.author',
|
|
||||||
'service.attributes.additionalInformation.description',
|
|
||||||
'service.attributes.additionalInformation.tags'
|
|
||||||
],
|
|
||||||
minimum_should_match: '2<75%',
|
minimum_should_match: '2<75%',
|
||||||
phrase_slop: 2,
|
phrase_slop: 2,
|
||||||
boost: 5
|
boost: 5
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
query_string: {
|
||||||
|
query: `${noSpaceSearchTerm}*`,
|
||||||
|
fields: searchFields,
|
||||||
|
boost: 5,
|
||||||
|
lenient: true
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
match_phrase: {
|
match_phrase: {
|
||||||
content: {
|
content: {
|
||||||
@ -126,23 +124,21 @@ export function getSearchQuery(
|
|||||||
{
|
{
|
||||||
query_string: {
|
query_string: {
|
||||||
query: `${prefixedSearchTerm}`,
|
query: `${prefixedSearchTerm}`,
|
||||||
fields: [
|
fields: searchFields,
|
||||||
'id',
|
|
||||||
'publicKey.owner',
|
|
||||||
'dataToken',
|
|
||||||
'dataTokenInfo.name',
|
|
||||||
'dataTokenInfo.symbol',
|
|
||||||
'service.attributes.main.name',
|
|
||||||
'service.attributes.main.author',
|
|
||||||
'service.attributes.additionalInformation.description',
|
|
||||||
'service.attributes.additionalInformation.tags'
|
|
||||||
],
|
|
||||||
default_operator: 'AND'
|
default_operator: 'AND'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
match: {
|
||||||
|
'service.attributes.main.type':
|
||||||
|
serviceType === undefined
|
||||||
|
? 'dataset OR algorithm'
|
||||||
|
: `${serviceType}`
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
query_string: {
|
query_string: {
|
||||||
query: `${transformChainIdsListToQuery(chainIds)}`
|
query: `${transformChainIdsListToQuery(chainIds)}`
|
||||||
|
Loading…
Reference in New Issue
Block a user