Skip to content

Commit 2315cb7

Browse files
authored
Merge pull request #1101 from metabrainz/fix-search-autocomplete
Fix search entity type
2 parents 3ebe184 + 387cb4c commit 2315cb7

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/common/helpers/search.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ function sanitizeEntityType(type) {
5151
}
5252

5353
export type IndexableEntities = EntityTypeString | 'Editor' | 'Collection' | 'Area';
54+
export type IndexableEntitiesOrAll = IndexableEntities | 'allEntities';
5455
const commonProperties = ['bbid', 'id', 'name', 'type', 'disambiguation'];
5556

5657
const indexMappings = {
@@ -334,7 +335,7 @@ async function _processEntityListForBulk(entityList) {
334335
await Promise.all(indexOperations);
335336
}
336337

337-
export async function autocomplete(orm, query, type, size = 42) {
338+
export async function autocomplete(orm:ORM, query:string, type:IndexableEntitiesOrAll | IndexableEntities[], size = 42) {
338339
let queryBody = null;
339340

340341
if (commonUtils.isValidBBID(query)) {

src/server/routes/search.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ router.get('/', async (req, res, next) => {
105105
router.get('/search', (req, res) => {
106106
const {orm} = req.app.locals;
107107
const query = req.query.q;
108-
const type = req.query.type?.toString() || 'allEntities';
108+
const type = req.query.type as search.IndexableEntitiesOrAll ?? 'allEntities';
109109

110110
const {size, from} = req.query;
111111

@@ -120,8 +120,8 @@ router.get('/search', (req, res) => {
120120
*/
121121
router.get('/autocomplete', (req, res) => {
122122
const {orm} = req.app.locals;
123-
const query = req.query.q;
124-
const type = req.query.type?.toString() || 'allEntities';
123+
const query = req.query.q.toString();
124+
const type = req.query.type as search.IndexableEntitiesOrAll ?? 'allEntities';
125125
const size = Number(req.query.size) || 42;
126126

127127
const searchPromise = search.autocomplete(orm, query, type, size);

0 commit comments

Comments
 (0)