🔧 Added a search filter for volumes

This commit is contained in:
2022-04-11 14:19:16 -07:00
parent abc579a8fb
commit e0791c1939

View File

@@ -71,29 +71,56 @@ export default class SettingsService extends Service {
size: number; size: number;
from: number; from: number;
}; };
type: string;
}> }>
) => { ) => {
try { try {
console.log(ctx.params); console.log(ctx.params);
const { query, pagination } = ctx.params; const { query, pagination } = ctx.params;
let eSQuery = {}; let eSQuery = {};
if (isEmpty(query)) { switch (ctx.params.type) {
Object.assign(eSQuery, { case "all":
match_all: {}, Object.assign(eSQuery, {
}); match_all: {},
} else { });
Object.assign(eSQuery, { break;
multi_match: {
fields: [ case "volumeName":
"rawFileDetails.name", Object.assign(eSQuery, {
"sourcedMetadata.comicvine.name", multi_match: {
"sourcedMetadata.comicvine.volumeInformation.name", fields: [
], "rawFileDetails.name",
query: query.volumeName, "sourcedMetadata.comicvine.name",
}, "sourcedMetadata.comicvine.volumeInformation.name",
}); ],
query: query.volumeName,
},
});
break;
case "wanted":
Object.assign(eSQuery, {
bool: {
must: {
term: {
"acquisition.wanted":
true,
},
},
},
});
break;
case "volumes":
Object.assign(eSQuery, {
exists: {
field: "sourcedMetadata.comicvine.volumeInformation"
}
});
break;
} }
console.log(query); console.log("Searching ElasticSearch index with this query -> ");
console.log(
JSON.stringify(eSQuery, null, 2)
);
const result = await eSClient.search( const result = await eSClient.search(
{ {
index: "comics", index: "comics",
@@ -107,7 +134,12 @@ export default class SettingsService extends Service {
return result; return result;
} catch (error) { } catch (error) {
return new Errors.MoleculerClientError("Failed to return data", 404, "ElasticSearch error", error); return new Errors.MoleculerClientError(
"Failed to return data",
404,
"ElasticSearch error",
error
);
} }
}, },
}, },