-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #248 from hotwax/241_product_keyword_search
Improved: product keyword search to search on sku, upc, productName, internalName, productId, groupId, groupName, and productCategoryNames fields (#241).
- Loading branch information
Showing
5 changed files
with
60 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const prepareProductQuery = (params: any) => { | ||
const viewSize = params.viewSize ? params.viewSize : process.env.VUE_APP_VIEW_SIZE; | ||
const viewIndex = params.viewIndex ? params.viewIndex : 0; | ||
|
||
const payload = { | ||
"json": { | ||
"params": { | ||
"rows": viewSize, | ||
"q.op": "AND", | ||
"start": viewIndex * viewSize | ||
}, | ||
"query": "(*:*)", | ||
"filter": [`docType: ${params.docType ? params.docType : 'PRODUCT'}`] | ||
} | ||
} as any | ||
|
||
if (params.queryString) { | ||
payload.json.query = `*${params.queryString}* OR "${params.queryString}"^100` | ||
payload.json.params['qf'] = params.queryFields ? params.queryFields : "sku^100 upc^100 productName^50 internalName^40 productId groupId groupName productCategoryNames" | ||
payload.json.params['defType'] = "edismax" | ||
} | ||
|
||
// checking that if the params has filters, and then adding the filter values in the payload filter | ||
// for each key present in the params filters | ||
if (params.filters) { | ||
Object.keys(params.filters).map((key: any) => { | ||
const filterValue = params.filters[key].value; | ||
|
||
if (Array.isArray(filterValue)) { | ||
const filterOperator = params.filters[key].op ? params.filters[key].op : 'OR'; | ||
payload.json.filter += ` AND ${key}: (${filterValue.join(' ' + filterOperator + ' ')})` | ||
} else { | ||
payload.json.filter += ` AND ${key}: ${filterValue}` | ||
} | ||
}) | ||
} | ||
|
||
if (params.facet) { | ||
payload.json['facet'] = params.facet | ||
} | ||
|
||
return payload | ||
} | ||
|
||
export { prepareProductQuery } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters