add: request + response interface changes
This commit is contained in:
@@ -73,9 +73,10 @@ class SearchService extends BaseService {
|
||||
* Used to search for a document in an index
|
||||
* @param indexName {string} - the index name
|
||||
* @param query {string} - the search query
|
||||
* @param options {object} - any options passed to the request object other than the query and indexName
|
||||
* e.g. pagination options, filtering options, etc
|
||||
* @return {Promise<{object}>} - returns response from search engine provider
|
||||
* @param options {{ paginationOptions: { limit: number, offset: number }, filter: string, additionalOptions: any}}
|
||||
* - any options passed to the request object other than the query and indexName
|
||||
* - additionalOptions contain any provider specific options
|
||||
* @return {Promise<{ hits: any[]; [k: string]: any; }>} returns response from search engine provider
|
||||
*/
|
||||
search(indexName, query, options) {
|
||||
throw Error("search must be overridden by a child class")
|
||||
|
||||
@@ -39,7 +39,10 @@ class MeiliSearchService extends SearchService {
|
||||
}
|
||||
|
||||
search(indexName, query, options) {
|
||||
return this.client_.index(indexName).search(query, options)
|
||||
const { paginationOptions, filter, additionalOptions } = options
|
||||
return this.client_
|
||||
.index(indexName)
|
||||
.search(query, { filter, ...paginationOptions, ...additionalOptions })
|
||||
}
|
||||
|
||||
updateSettings(indexName, settings) {
|
||||
|
||||
@@ -5,6 +5,9 @@ export default async (req, res) => {
|
||||
const schema = Validator.object()
|
||||
.keys({
|
||||
q: Validator.string().required(),
|
||||
offset: Validator.number().optional(),
|
||||
limit: Validator.number().optional(),
|
||||
filter: Validator.any(),
|
||||
})
|
||||
.options({ allowUnknown: true })
|
||||
|
||||
@@ -14,15 +17,16 @@ export default async (req, res) => {
|
||||
}
|
||||
|
||||
try {
|
||||
const { q, ...options } = value
|
||||
const { q, offset, limit, filter, ...options } = value
|
||||
const paginationOptions = { offset, limit }
|
||||
|
||||
const searchService = req.scope.resolve("searchService")
|
||||
|
||||
const results = await searchService.search(
|
||||
ProductService.IndexName,
|
||||
q,
|
||||
options
|
||||
)
|
||||
const results = await searchService.search(ProductService.IndexName, q, {
|
||||
paginationOptions,
|
||||
filter,
|
||||
additionalOptions: options,
|
||||
})
|
||||
|
||||
res.status(200).send(results)
|
||||
} catch (error) {
|
||||
|
||||
@@ -53,7 +53,7 @@ class DefaultSearchService extends SearchService {
|
||||
this.logger_.warn(
|
||||
"This is an empty method: search must be overridden a the child class"
|
||||
)
|
||||
return []
|
||||
return { hits: [] }
|
||||
}
|
||||
|
||||
updateSettings(indexName, settings) {
|
||||
|
||||
Reference in New Issue
Block a user