🔎 Elasticsearch endpoints for you know, search
This commit is contained in:
@@ -2,6 +2,13 @@ const mongoose = require("mongoose");
|
||||
var mexp = require("mongoose-elasticsearch-xp").v7;
|
||||
const paginate = require("mongoose-paginate-v2");
|
||||
const { Client } = require("@elastic/elasticsearch");
|
||||
import ComicVineMetadataSchema from "./comicvine.metadata.model";
|
||||
import { mongoosastic } from "mongoosastic-ts";
|
||||
import {
|
||||
MongoosasticDocument,
|
||||
MongoosasticModel,
|
||||
MongoosasticPluginOpts,
|
||||
} from "mongoosastic-ts/dist/types";
|
||||
|
||||
export const eSClient = new Client({
|
||||
node: "http://localhost:9200",
|
||||
@@ -11,6 +18,23 @@ export const eSClient = new Client({
|
||||
},
|
||||
});
|
||||
|
||||
const RawFileDetailsSchema = mongoose.Schema({
|
||||
_id: false,
|
||||
name: String,
|
||||
filePath: String,
|
||||
fileSize: Number,
|
||||
extension: String,
|
||||
containedIn: String,
|
||||
pageCount: Number,
|
||||
cover: {
|
||||
filePath: String,
|
||||
stats: Object,
|
||||
},
|
||||
calibreMetadata: {
|
||||
coverWriteResult: String,
|
||||
},
|
||||
});
|
||||
|
||||
const ComicSchema = mongoose.Schema(
|
||||
{
|
||||
importStatus: {
|
||||
@@ -25,36 +49,25 @@ const ComicSchema = mongoose.Schema(
|
||||
},
|
||||
sourcedMetadata: {
|
||||
comicInfo: { type: mongoose.Schema.Types.Mixed, default: {} },
|
||||
comicvine: { type: mongoose.Schema.Types.Mixed, default: {} },
|
||||
comicvine: {
|
||||
type: ComicVineMetadataSchema,
|
||||
es_indexed: true,
|
||||
default: {},
|
||||
},
|
||||
shortboxed: {},
|
||||
gcd: {},
|
||||
},
|
||||
rawFileDetails: {
|
||||
name: { type: String, es_indexed: true },
|
||||
filePath: String,
|
||||
fileSize: Number,
|
||||
extension: String,
|
||||
containedIn: String,
|
||||
pageCount: Number,
|
||||
cover: {
|
||||
filePath: String,
|
||||
stats: Object,
|
||||
},
|
||||
calibreMetadata: {
|
||||
coverWriteResult: String,
|
||||
},
|
||||
},
|
||||
rawFileDetails: { type: RawFileDetailsSchema, es_indexed: true },
|
||||
inferredMetadata: {
|
||||
issue: {
|
||||
name: String,
|
||||
name: { type: String, es_indexed: true },
|
||||
number: {
|
||||
type: Number,
|
||||
es_indexed: true,
|
||||
required: false,
|
||||
default: 0,
|
||||
},
|
||||
year: String,
|
||||
subtitle: String,
|
||||
subtitle: { type: String, es_indexed: true },
|
||||
},
|
||||
},
|
||||
acquisition: {
|
||||
@@ -75,9 +88,22 @@ const ComicSchema = mongoose.Schema(
|
||||
{ timestamps: true, minimize: false }
|
||||
);
|
||||
|
||||
ComicSchema.plugin(mexp, {
|
||||
client: eSClient,
|
||||
ComicSchema.plugin(mongoosastic, {
|
||||
esClient: eSClient,
|
||||
});
|
||||
ComicSchema.plugin(paginate);
|
||||
const Comic = mongoose.model("Comic", ComicSchema);
|
||||
|
||||
const Comic = mongoose.model("Comic", ComicSchema),
|
||||
stream = Comic.synchronize();
|
||||
let count = 0;
|
||||
|
||||
stream.on("data", function (err, doc) {
|
||||
count++;
|
||||
});
|
||||
stream.on("close", function () {
|
||||
console.log("indexed " + count + " documents!");
|
||||
});
|
||||
stream.on("error", function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
export default Comic;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const mongoose = require("mongoose");
|
||||
const Things = mongoose.Schema({
|
||||
_id: false,
|
||||
api_detail_url: String,
|
||||
id: Number,
|
||||
name: String,
|
||||
@@ -7,13 +8,15 @@ const Things = mongoose.Schema({
|
||||
count: String,
|
||||
});
|
||||
const Issue = mongoose.Schema({
|
||||
_id: false,
|
||||
api_detail_url: String,
|
||||
id: Number,
|
||||
name: String,
|
||||
issue_number: String,
|
||||
});
|
||||
const VolumeInformation = mongoose.Schema({
|
||||
aliases: Array,
|
||||
_id: false,
|
||||
aliases: [],
|
||||
api_detail_url: String,
|
||||
characters: [Things],
|
||||
concepts: [Things],
|
||||
@@ -60,7 +63,8 @@ const VolumeInformation = mongoose.Schema({
|
||||
start_year: String,
|
||||
});
|
||||
|
||||
const ComicVineMetadata = mongoose.Schema({
|
||||
const ComicVineMetadataSchema = mongoose.Schema({
|
||||
_id: false,
|
||||
aliases: [String],
|
||||
api_detail_url: String,
|
||||
cover_date: String,
|
||||
@@ -75,4 +79,4 @@ const ComicVineMetadata = mongoose.Schema({
|
||||
volumeInformation: VolumeInformation,
|
||||
});
|
||||
|
||||
export default ComicVineMetadata;
|
||||
export default ComicVineMetadataSchema;
|
||||
|
||||
Reference in New Issue
Block a user