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 =
|
||||
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 {
|
||||
const sortTerm =
|
||||
sortParam === SortTermOptions.Created
|
||||
@ -65,7 +56,6 @@ export function getSearchQuery(
|
||||
const sortTerm = getSortType(sort)
|
||||
const sortValue = sortOrder === SortValueOptions.Ascending ? 1 : -1
|
||||
const emptySearchTerm = text === undefined || text === ''
|
||||
|
||||
let searchTerm = owner
|
||||
? `(publicKey.owner:${owner})`
|
||||
: tags
|
||||
@ -77,16 +67,26 @@ export function getSearchQuery(
|
||||
: text || ''
|
||||
|
||||
searchTerm = searchTerm.trim()
|
||||
let modifiedSearchTerm = searchTerm.split(' ').join(' OR ').trim()
|
||||
modifiedSearchTerm = addTypeFilterToQuery(modifiedSearchTerm, serviceType)
|
||||
searchTerm = addTypeFilterToQuery(searchTerm, serviceType)
|
||||
const modifiedSearchTerm = searchTerm.split(' ').join(' OR ').trim()
|
||||
const noSpaceSearchTerm = searchTerm.split(' ').join('').trim()
|
||||
|
||||
const prefixedSearchTerm =
|
||||
emptySearchTerm && searchTerm
|
||||
? searchTerm
|
||||
: !emptySearchTerm && 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 {
|
||||
page: Number(page) || 1,
|
||||
offset: Number(offset) || 21,
|
||||
@ -99,22 +99,20 @@ export function getSearchQuery(
|
||||
{
|
||||
query_string: {
|
||||
query: `${modifiedSearchTerm}`,
|
||||
fields: [
|
||||
'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'
|
||||
],
|
||||
fields: searchFields,
|
||||
minimum_should_match: '2<75%',
|
||||
phrase_slop: 2,
|
||||
boost: 5
|
||||
}
|
||||
},
|
||||
{
|
||||
query_string: {
|
||||
query: `${noSpaceSearchTerm}*`,
|
||||
fields: searchFields,
|
||||
boost: 5,
|
||||
lenient: true
|
||||
}
|
||||
},
|
||||
{
|
||||
match_phrase: {
|
||||
content: {
|
||||
@ -126,23 +124,21 @@ export function getSearchQuery(
|
||||
{
|
||||
query_string: {
|
||||
query: `${prefixedSearchTerm}`,
|
||||
fields: [
|
||||
'id',
|
||||
'publicKey.owner',
|
||||
'dataToken',
|
||||
'dataTokenInfo.name',
|
||||
'dataTokenInfo.symbol',
|
||||
'service.attributes.main.name',
|
||||
'service.attributes.main.author',
|
||||
'service.attributes.additionalInformation.description',
|
||||
'service.attributes.additionalInformation.tags'
|
||||
],
|
||||
fields: searchFields,
|
||||
default_operator: 'AND'
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
match: {
|
||||
'service.attributes.main.type':
|
||||
serviceType === undefined
|
||||
? 'dataset OR algorithm'
|
||||
: `${serviceType}`
|
||||
}
|
||||
},
|
||||
{
|
||||
query_string: {
|
||||
query: `${transformChainIdsListToQuery(chainIds)}`
|
||||
|
Loading…
Reference in New Issue
Block a user