🕵🏼♂️ Added volume name as an additional search field to ES search
This commit is contained in:
@@ -475,7 +475,8 @@ export default class ImportService extends Service {
|
|||||||
{
|
{
|
||||||
queryObject: {
|
queryObject: {
|
||||||
issueId: issue.id,
|
issueId: issue.id,
|
||||||
issueName:
|
issueName: issueMetadata.name,
|
||||||
|
volumeName:
|
||||||
issueMetadata.volume
|
issueMetadata.volume
|
||||||
.name,
|
.name,
|
||||||
issueNumber:
|
issueNumber:
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ export default class LibraryQueueService extends Service {
|
|||||||
!isUndefined(matchesInLibrary)
|
!isUndefined(matchesInLibrary)
|
||||||
) {
|
) {
|
||||||
console.log("Matches found in library:");
|
console.log("Matches found in library:");
|
||||||
|
console.log(matchesInLibrary);
|
||||||
|
|
||||||
const foo = extend(
|
const foo = extend(
|
||||||
{ issue: job.data.queryObject.issueMetadata },
|
{ issue: job.data.queryObject.issueMetadata },
|
||||||
@@ -152,6 +153,7 @@ export default class LibraryQueueService extends Service {
|
|||||||
ctx: Context<{
|
ctx: Context<{
|
||||||
queryObject: {
|
queryObject: {
|
||||||
issueName: string;
|
issueName: string;
|
||||||
|
volumeName: string;
|
||||||
issueNumber: string;
|
issueNumber: string;
|
||||||
issueId: string;
|
issueId: string;
|
||||||
issueMetadata: object;
|
issueMetadata: object;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const client = new Client({
|
|||||||
import { DbMixin } from "../mixins/db.mixin";
|
import { DbMixin } from "../mixins/db.mixin";
|
||||||
import Comic from "../models/comic.model";
|
import Comic from "../models/comic.model";
|
||||||
import { refineQuery } from "filename-parser";
|
import { refineQuery } from "filename-parser";
|
||||||
import { filter } from "lodash";
|
import { filter, isEmpty, isNull } from "lodash";
|
||||||
|
|
||||||
console.log(client);
|
console.log(client);
|
||||||
|
|
||||||
@@ -42,31 +42,96 @@ export default class SettingsService extends Service {
|
|||||||
params: {},
|
params: {},
|
||||||
timeout: 400000,
|
timeout: 400000,
|
||||||
async handler(
|
async handler(
|
||||||
ctx: Context<{ queryObject: {
|
ctx: Context<{
|
||||||
issueName: string,
|
queryObject: {
|
||||||
issueNumber: string,
|
issueName: string;
|
||||||
} }>
|
volumeName: string;
|
||||||
|
issueNumber: string;
|
||||||
|
};
|
||||||
|
}>
|
||||||
) {
|
) {
|
||||||
console.log(ctx.params);
|
let elasticSearchQuery = {};
|
||||||
return Comic.esSearch({
|
console.log(
|
||||||
query: {
|
"Volume: ",
|
||||||
|
ctx.params.queryObject.volumeName
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
"Issue: ",
|
||||||
|
ctx.params.queryObject.issueName
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
isNull(ctx.params.queryObject.volumeName)
|
||||||
|
) {
|
||||||
|
elasticSearchQuery = {
|
||||||
match: {
|
match: {
|
||||||
"rawFileDetails.name": {
|
"rawFileDetails.name": {
|
||||||
query: ctx.params.queryObject.issueName,
|
query: ctx.params.queryObject
|
||||||
operator: "or",
|
.issueName,
|
||||||
|
operator: "and",
|
||||||
fuzziness: "AUTO",
|
fuzziness: "AUTO",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
};
|
||||||
},
|
} else if (
|
||||||
|
isNull(ctx.params.queryObject.issueName)
|
||||||
|
) {
|
||||||
|
elasticSearchQuery = {
|
||||||
|
match: {
|
||||||
|
"rawFileDetails.name": {
|
||||||
|
query: ctx.params.queryObject
|
||||||
|
.volumeName,
|
||||||
|
operator: "and",
|
||||||
|
fuzziness: "AUTO",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
elasticSearchQuery = {
|
||||||
|
bool: {
|
||||||
|
should: [
|
||||||
|
{
|
||||||
|
match_phrase: {
|
||||||
|
"rawFileDetails.name":
|
||||||
|
ctx.params
|
||||||
|
.queryObject
|
||||||
|
.issueName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
match_phrase: {
|
||||||
|
"rawFileDetails.name":
|
||||||
|
ctx.params
|
||||||
|
.queryObject
|
||||||
|
.volumeName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
console.log(elasticSearchQuery);
|
||||||
|
return Comic.esSearch({
|
||||||
|
query: elasticSearchQuery,
|
||||||
}).then(function (results) {
|
}).then(function (results) {
|
||||||
// results here
|
// results here
|
||||||
const foo = results.body.hits.hits.map((hit) => {
|
const foo = results.body.hits.hits.map(
|
||||||
const parsedFilename = refineQuery(hit._source.rawFileDetails.name);
|
(hit) => {
|
||||||
if(parsedFilename.searchParams.searchTerms.number === parseInt(ctx.params.queryObject.issueNumber, 10)) {
|
const parsedFilename = refineQuery(
|
||||||
return hit;
|
hit._source.rawFileDetails.name
|
||||||
}
|
);
|
||||||
});
|
if (
|
||||||
|
parsedFilename.searchParams
|
||||||
|
.searchTerms.number ===
|
||||||
|
parseInt(
|
||||||
|
ctx.params.queryObject
|
||||||
|
.issueNumber,
|
||||||
|
10
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return hit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
return filter(foo, null);
|
return filter(foo, null);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user