mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
small hotfix to use fuzzy text lookups and actually utilise the compound index.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
export interface IMongoMetadataQuery {
|
export interface IMongoMetadataQuery {
|
||||||
PrimaryTitle: { $regex: RegExp };
|
$text: { $search: string },
|
||||||
TitleType: {$in: string[]};
|
TitleType: string;
|
||||||
StartYear?: string;
|
StartYear?: string;
|
||||||
}
|
}
|
||||||
@@ -26,20 +26,11 @@ export class MongoRepository implements IMongoRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getImdbId(title: string, category: string, year?: string | number) : Promise<string | null> {
|
async getImdbId(title: string, category: string, year?: string | number) : Promise<string | null> {
|
||||||
const seriesTypes : string[] = ['tvSeries'];
|
const titleType: string = category === TorrentType.Series ? 'tvSeries' : 'movie';
|
||||||
const movieTypes : string[] = ['movie', 'tvMovie'];
|
|
||||||
|
|
||||||
let titleTypes: string[] = [];
|
|
||||||
|
|
||||||
if (category === TorrentType.Series) {
|
|
||||||
titleTypes = seriesTypes;
|
|
||||||
} else if (category === TorrentType.Movie) {
|
|
||||||
titleTypes = movieTypes;
|
|
||||||
}
|
|
||||||
|
|
||||||
const query: IMongoMetadataQuery = {
|
const query: IMongoMetadataQuery = {
|
||||||
PrimaryTitle: { $regex: new RegExp(title, 'i') },
|
$text: { $search: title },
|
||||||
TitleType: {$in: titleTypes}
|
TitleType: titleType,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (year) {
|
if (year) {
|
||||||
@@ -47,7 +38,7 @@ export class MongoRepository implements IMongoRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await ImdbEntryModel.findOne(query, '_id').maxTimeMS(30000);
|
const result = await ImdbEntryModel.findOne(query, '_id', {score: {$meta: "textScore" }}).sort({score: {$meta: "textScore"}}).limit(10).maxTimeMS(30000);
|
||||||
return result ? result._id : null;
|
return result ? result._id : null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.error('Query exceeded the 30 seconds time limit', error);
|
this.logger.error('Query exceeded the 30 seconds time limit', error);
|
||||||
|
|||||||
@@ -72,6 +72,12 @@ xdescribe('MongoRepository Tests - Manual Tests against real cluster. Skipped by
|
|||||||
expect(result).toBe('tt0084726');
|
expect(result).toBe('tt0084726');
|
||||||
}, 30000);
|
}, 30000);
|
||||||
|
|
||||||
|
it('should get Tom and Jerry imdbId correctly', async () => {
|
||||||
|
await mongoRepository.connect();
|
||||||
|
const result = await mongoRepository.getImdbId('Tom and Jerry Tales', TorrentType.Series);
|
||||||
|
expect(result).toBe('tt0780438');
|
||||||
|
}, 30000);
|
||||||
|
|
||||||
it('should get Return of the Jedi correctly', async () => {
|
it('should get Return of the Jedi correctly', async () => {
|
||||||
await mongoRepository.connect();
|
await mongoRepository.connect();
|
||||||
const result = await mongoRepository.getImdbId('Star Wars: Episode VI - Return of the Jedi', TorrentType.Movie, 1983);
|
const result = await mongoRepository.getImdbId('Star Wars: Episode VI - Return of the Jedi', TorrentType.Movie, 1983);
|
||||||
|
|||||||
Reference in New Issue
Block a user