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 {
|
||||
PrimaryTitle: { $regex: RegExp };
|
||||
TitleType: {$in: string[]};
|
||||
$text: { $search: string },
|
||||
TitleType: string;
|
||||
StartYear?: string;
|
||||
}
|
||||
@@ -26,20 +26,11 @@ export class MongoRepository implements IMongoRepository {
|
||||
}
|
||||
|
||||
async getImdbId(title: string, category: string, year?: string | number) : Promise<string | null> {
|
||||
const seriesTypes : string[] = ['tvSeries'];
|
||||
const movieTypes : string[] = ['movie', 'tvMovie'];
|
||||
const titleType: string = category === TorrentType.Series ? 'tvSeries' : 'movie';
|
||||
|
||||
let titleTypes: string[] = [];
|
||||
|
||||
if (category === TorrentType.Series) {
|
||||
titleTypes = seriesTypes;
|
||||
} else if (category === TorrentType.Movie) {
|
||||
titleTypes = movieTypes;
|
||||
}
|
||||
|
||||
const query: IMongoMetadataQuery = {
|
||||
PrimaryTitle: { $regex: new RegExp(title, 'i') },
|
||||
TitleType: {$in: titleTypes}
|
||||
$text: { $search: title },
|
||||
TitleType: titleType,
|
||||
};
|
||||
|
||||
if (year) {
|
||||
@@ -47,7 +38,7 @@ export class MongoRepository implements IMongoRepository {
|
||||
}
|
||||
|
||||
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;
|
||||
} catch (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');
|
||||
}, 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 () => {
|
||||
await mongoRepository.connect();
|
||||
const result = await mongoRepository.getImdbId('Star Wars: Episode VI - Return of the Jedi', TorrentType.Movie, 1983);
|
||||
|
||||
Reference in New Issue
Block a user