1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

fix tag search (#1651)

This commit is contained in:
mihaisc 2022-08-12 02:38:13 -07:00 committed by GitHub
parent dc4add5c70
commit 27517faea2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 77 deletions

View File

@ -15,9 +15,7 @@ const Tag = ({ tag, noLinks }: { tag: string; noLinks?: boolean }) => {
return noLinks ? ( return noLinks ? (
<span className={styles.tag}>{tag}</span> <span className={styles.tag}>{tag}</span>
) : ( ) : (
<Link <Link href={`/search?tags=${urlEncodedTag}&sort=_score&sortOrder=desc`}>
href={`/search?tags=${urlEncodedTag}&sort=metadata.created&sortOrder=desc`}
>
<a className={styles.tag} title={tag}> <a className={styles.tag} title={tag}>
{tag} {tag}
</a> </a>

View File

@ -35,7 +35,6 @@ export function getSearchQuery(
text?: string, text?: string,
owner?: string, owner?: string,
tags?: string, tags?: string,
categories?: string,
page?: string, page?: string,
offset?: string, offset?: string,
sort?: string, sort?: string,
@ -45,83 +44,77 @@ export function getSearchQuery(
): SearchQuery { ): SearchQuery {
text = escapeESReservedChars(text) text = escapeESReservedChars(text)
const emptySearchTerm = text === undefined || text === '' const emptySearchTerm = text === undefined || text === ''
const filters: FilterTerm[] = []
let searchTerm = text || ''
let nestedQuery
if (tags) {
filters.push(getFilterTerm('metadata.tags.keyword', tags))
} else {
searchTerm = searchTerm.trim()
const modifiedSearchTerm = searchTerm.split(' ').join(' OR ').trim()
const noSpaceSearchTerm = searchTerm.split(' ').join('').trim()
let searchTerm = owner const prefixedSearchTerm =
? `(nft.owner:${owner})` emptySearchTerm && searchTerm
: tags ? searchTerm
? // eslint-disable-next-line no-useless-escape : !emptySearchTerm && searchTerm
`(metadata.tags:\"${tags}\")` ? '*' + searchTerm + '*'
: // : categories : '**'
// ? // eslint-disable-next-line no-useless-escape const searchFields = [
// `(service.attributes.additionalInformation.categories:\"${categories}\")` 'id',
text || '' 'nft.owner',
'datatokens.address',
'datatokens.name',
'datatokens.symbol',
'metadata.name^10',
'metadata.author',
'metadata.description',
'metadata.tags'
]
searchTerm = searchTerm.trim() nestedQuery = {
const modifiedSearchTerm = searchTerm.split(' ').join(' OR ').trim() must: [
const noSpaceSearchTerm = searchTerm.split(' ').join('').trim() {
bool: {
const prefixedSearchTerm = should: [
emptySearchTerm && searchTerm {
? searchTerm query_string: {
: !emptySearchTerm && searchTerm query: `${modifiedSearchTerm}`,
? '*' + searchTerm + '*' fields: searchFields,
: '**' minimum_should_match: '2<75%',
const searchFields = [ phrase_slop: 2,
'id', boost: 5
'nft.owner', }
'datatokens.address', },
'datatokens.name', {
'datatokens.symbol', query_string: {
'metadata.name^10', query: `${noSpaceSearchTerm}*`,
'metadata.author', fields: searchFields,
'metadata.description', boost: 5,
'metadata.tags' lenient: true
] }
},
const nestedQuery = { {
must: [ match_phrase: {
{ content: {
bool: { query: `${searchTerm}`,
should: [ boost: 10
{ }
query_string: { }
query: `${modifiedSearchTerm}`, },
fields: searchFields, {
minimum_should_match: '2<75%', query_string: {
phrase_slop: 2, query: `${prefixedSearchTerm}`,
boost: 5 fields: searchFields,
} default_operator: 'AND'
},
{
query_string: {
query: `${noSpaceSearchTerm}*`,
fields: searchFields,
boost: 5,
lenient: true
}
},
{
match_phrase: {
content: {
query: `${searchTerm}`,
boost: 10
} }
} }
}, ]
{ }
query_string: {
query: `${prefixedSearchTerm}`,
fields: searchFields,
default_operator: 'AND'
}
}
]
} }
} ]
] }
} }
const filters: FilterTerm[] = []
accessType !== undefined && accessType !== undefined &&
filters.push(getFilterTerm('services.type', accessType)) filters.push(getFilterTerm('services.type', accessType))
serviceType !== undefined && serviceType !== undefined &&
@ -162,7 +155,6 @@ export async function getResults(
text, text,
owner, owner,
tags, tags,
categories,
page, page,
offset, offset,
sort, sort,
@ -176,7 +168,6 @@ export async function getResults(
text, text,
owner, owner,
tags, tags,
categories,
page, page,
offset, offset,
sort, sort,