2021-01-16 23:59:59 +08:00
|
|
|
import {LocationManager} from '../../../../../src/backend/model/database/LocationManager';
|
2023-01-06 06:11:58 +08:00
|
|
|
import {SearchManager} from '../../../../../src/backend/model/database/SearchManager';
|
2019-12-10 17:44:35 +08:00
|
|
|
import {SearchResultDTO} from '../../../../../src/common/entities/SearchResultDTO';
|
|
|
|
import {Utils} from '../../../../../src/common/Utils';
|
2021-04-02 03:48:38 +08:00
|
|
|
import {DBTestHelper} from '../../../DBTestHelper';
|
2021-01-16 23:59:59 +08:00
|
|
|
import {
|
|
|
|
ANDSearchQuery,
|
|
|
|
DistanceSearch,
|
2021-02-14 19:57:05 +08:00
|
|
|
FromDateSearch,
|
|
|
|
MaxRatingSearch,
|
|
|
|
MaxResolutionSearch,
|
|
|
|
MinRatingSearch,
|
|
|
|
MinResolutionSearch,
|
2021-01-16 23:59:59 +08:00
|
|
|
OrientationSearch,
|
|
|
|
ORSearchQuery,
|
2021-05-31 22:44:37 +08:00
|
|
|
SearchListQuery,
|
2021-01-16 23:59:59 +08:00
|
|
|
SearchQueryDTO,
|
|
|
|
SearchQueryTypes,
|
2021-01-17 06:37:14 +08:00
|
|
|
SomeOfSearchQuery,
|
2021-01-16 23:59:59 +08:00
|
|
|
TextSearch,
|
2021-02-14 19:57:05 +08:00
|
|
|
TextSearchQueryMatchTypes,
|
|
|
|
ToDateSearch
|
2021-01-16 23:59:59 +08:00
|
|
|
} from '../../../../../src/common/entities/SearchQueryDTO';
|
2023-01-06 06:11:58 +08:00
|
|
|
import {IndexingManager} from '../../../../../src/backend/model/database/IndexingManager';
|
2021-06-28 01:33:37 +08:00
|
|
|
import {DirectoryBaseDTO, ParentDirectoryDTO, SubDirectoryDTO} from '../../../../../src/common/entities/DirectoryDTO';
|
2022-06-25 00:05:45 +08:00
|
|
|
import {TestHelper} from '../../../../TestHelper';
|
2021-01-16 23:59:59 +08:00
|
|
|
import {ObjectManagers} from '../../../../../src/backend/model/ObjectManagers';
|
2023-01-06 06:11:58 +08:00
|
|
|
import {GalleryManager} from '../../../../../src/backend/model/database/GalleryManager';
|
2021-01-16 23:59:59 +08:00
|
|
|
import {Connection} from 'typeorm';
|
|
|
|
import {GPSMetadata, PhotoDTO, PhotoMetadata} from '../../../../../src/common/entities/PhotoDTO';
|
|
|
|
import {VideoDTO} from '../../../../../src/common/entities/VideoDTO';
|
2021-01-17 17:56:33 +08:00
|
|
|
import {AutoCompleteItem} from '../../../../../src/common/entities/AutoCompleteItem';
|
|
|
|
import {Config} from '../../../../../src/common/config/private/Config';
|
2021-05-31 22:44:37 +08:00
|
|
|
import {SearchQueryParser} from '../../../../../src/common/SearchQueryParser';
|
2021-06-19 18:08:17 +08:00
|
|
|
import {FileDTO} from '../../../../../src/common/entities/FileDTO';
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2022-12-05 05:23:51 +08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
2021-01-16 23:59:59 +08:00
|
|
|
const deepEqualInAnyOrder = require('deep-equal-in-any-order');
|
2022-12-05 05:23:51 +08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
2021-01-16 23:59:59 +08:00
|
|
|
const chai = require('chai');
|
|
|
|
|
|
|
|
chai.use(deepEqualInAnyOrder);
|
|
|
|
const {expect} = chai;
|
2018-01-31 09:01:16 +08:00
|
|
|
|
2019-01-28 03:36:42 +08:00
|
|
|
// to help WebStorm to handle the test cases
|
|
|
|
declare let describe: any;
|
|
|
|
declare const after: any;
|
2021-01-17 17:56:33 +08:00
|
|
|
declare const before: any;
|
2021-01-16 23:59:59 +08:00
|
|
|
const tmpDescribe = describe;
|
2021-04-02 03:48:38 +08:00
|
|
|
describe = DBTestHelper.describe(); // fake it os IDE plays nicely (recognize the test)
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
class IndexingManagerTest extends IndexingManager {
|
|
|
|
|
2021-06-28 01:33:37 +08:00
|
|
|
public async saveToDB(scannedDirectory: ParentDirectoryDTO): Promise<void> {
|
2021-01-16 23:59:59 +08:00
|
|
|
return super.saveToDB(scannedDirectory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-31 22:44:37 +08:00
|
|
|
class SearchManagerTest extends SearchManager {
|
|
|
|
|
|
|
|
public flattenSameOfQueries(query: SearchQueryDTO): SearchQueryDTO {
|
|
|
|
return super.flattenSameOfQueries(query);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-16 23:59:59 +08:00
|
|
|
class GalleryManagerTest extends GalleryManager {
|
|
|
|
|
2022-12-05 05:23:51 +08:00
|
|
|
public async getDirIdAndTime(connection: Connection, directoryName: string, directoryParent: string) {
|
|
|
|
return super.getDirIdAndTime(connection, directoryName, directoryParent);
|
2021-01-16 23:59:59 +08:00
|
|
|
}
|
|
|
|
|
2022-12-05 05:23:51 +08:00
|
|
|
public async getParentDirFromId(connection: Connection, dir: number): Promise<ParentDirectoryDTO> {
|
|
|
|
return super.getParentDirFromId(connection, dir);
|
2021-01-16 23:59:59 +08:00
|
|
|
}
|
|
|
|
}
|
2018-01-31 09:01:16 +08:00
|
|
|
|
2021-04-02 03:48:38 +08:00
|
|
|
describe('SearchManager', (sqlHelper: DBTestHelper) => {
|
2021-01-16 23:59:59 +08:00
|
|
|
describe = tmpDescribe;
|
|
|
|
/**
|
|
|
|
* dir
|
|
|
|
* |- v
|
|
|
|
* |- p
|
|
|
|
* |- p2
|
2021-06-19 18:08:17 +08:00
|
|
|
* |- gpx
|
2021-01-16 23:59:59 +08:00
|
|
|
* |-> subDir
|
2021-04-18 21:48:35 +08:00
|
|
|
* |- pFaceLess
|
2021-01-16 23:59:59 +08:00
|
|
|
* |-> subDir2
|
|
|
|
* |- p4
|
|
|
|
*/
|
2018-01-31 09:01:16 +08:00
|
|
|
|
2021-06-28 01:33:37 +08:00
|
|
|
let dir: ParentDirectoryDTO;
|
|
|
|
let subDir: SubDirectoryDTO;
|
|
|
|
let subDir2: SubDirectoryDTO;
|
2021-01-16 23:59:59 +08:00
|
|
|
let v: VideoDTO;
|
|
|
|
let p: PhotoDTO;
|
|
|
|
let p2: PhotoDTO;
|
2021-04-18 21:48:35 +08:00
|
|
|
let pFaceLess: PhotoDTO;
|
2021-01-16 23:59:59 +08:00
|
|
|
let p4: PhotoDTO;
|
2021-06-19 18:08:17 +08:00
|
|
|
let gpx: FileDTO;
|
2018-01-31 09:01:16 +08:00
|
|
|
|
|
|
|
|
2021-01-16 23:59:59 +08:00
|
|
|
const setUpTestGallery = async (): Promise<void> => {
|
2021-06-28 01:33:37 +08:00
|
|
|
const directory: ParentDirectoryDTO = TestHelper.getDirectoryEntry();
|
2021-05-24 04:26:27 +08:00
|
|
|
subDir = TestHelper.getDirectoryEntry(directory, 'The Phantom Menace');
|
|
|
|
subDir2 = TestHelper.getDirectoryEntry(directory, 'Return of the Jedi');
|
2021-03-28 18:43:13 +08:00
|
|
|
p = TestHelper.getPhotoEntry1(directory);
|
|
|
|
p2 = TestHelper.getPhotoEntry2(directory);
|
2021-06-19 18:08:17 +08:00
|
|
|
v = TestHelper.getVideoEntry1(directory);
|
|
|
|
gpx = TestHelper.getRandomizedGPXEntry(directory);
|
2021-03-28 18:43:13 +08:00
|
|
|
p4 = TestHelper.getPhotoEntry4(subDir2);
|
2021-04-18 21:48:35 +08:00
|
|
|
const pFaceLessTmp = TestHelper.getPhotoEntry3(subDir);
|
|
|
|
delete pFaceLessTmp.metadata.faces;
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-02 03:48:38 +08:00
|
|
|
dir = await DBTestHelper.persistTestDir(directory);
|
2021-06-19 18:08:17 +08:00
|
|
|
|
2021-05-24 04:26:27 +08:00
|
|
|
subDir = dir.directories[0];
|
|
|
|
subDir2 = dir.directories[1];
|
2021-04-18 21:48:35 +08:00
|
|
|
p = (dir.media.filter(m => m.name === p.name)[0] as any);
|
2022-12-05 05:23:51 +08:00
|
|
|
p.directory = dir;
|
2021-04-18 21:48:35 +08:00
|
|
|
p2 = (dir.media.filter(m => m.name === p2.name)[0] as any);
|
2022-12-05 05:23:51 +08:00
|
|
|
p2.directory = dir;
|
2021-06-19 18:08:17 +08:00
|
|
|
gpx = (dir.metaFile[0] as any);
|
2022-12-05 05:23:51 +08:00
|
|
|
gpx.directory = dir;
|
2021-04-18 21:48:35 +08:00
|
|
|
v = (dir.media.filter(m => m.name === v.name)[0] as any);
|
2022-12-05 05:23:51 +08:00
|
|
|
v.directory = dir;
|
2021-04-18 21:48:35 +08:00
|
|
|
p4 = (dir.directories[1].media[0] as any);
|
2022-12-05 05:23:51 +08:00
|
|
|
p4.directory = dir.directories[1];
|
2021-04-18 21:48:35 +08:00
|
|
|
pFaceLess = (dir.directories[0].media[0] as any);
|
2022-12-05 05:23:51 +08:00
|
|
|
pFaceLess.directory = dir.directories[0];
|
2021-01-16 23:59:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const setUpSqlDB = async () => {
|
|
|
|
await sqlHelper.initDB();
|
|
|
|
await setUpTestGallery();
|
2021-05-24 04:26:27 +08:00
|
|
|
await ObjectManagers.InitSQLManagers();
|
2018-01-31 09:01:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
before(async () => {
|
2018-01-31 09:01:16 +08:00
|
|
|
await setUpSqlDB();
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Search.listDirectories = true;
|
|
|
|
Config.Search.listMetafiles = false;
|
2018-01-31 09:01:16 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-01-28 03:36:42 +08:00
|
|
|
after(async () => {
|
|
|
|
await sqlHelper.clearDB();
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Search.listDirectories = false;
|
|
|
|
Config.Search.listMetafiles = false;
|
2019-01-28 03:36:42 +08:00
|
|
|
});
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
it('should get autocomplete', async () => {
|
|
|
|
const sm = new SearchManager();
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
const cmp = (a: AutoCompleteItem, b: AutoCompleteItem) => {
|
|
|
|
if (a.text === b.text) {
|
|
|
|
return a.type - b.type;
|
|
|
|
}
|
|
|
|
return a.text.localeCompare(b.text);
|
|
|
|
};
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-01-17 22:56:15 +08:00
|
|
|
expect((await sm.autocomplete('tat', SearchQueryTypes.any_text))).to.deep.equalInAnyOrder([
|
|
|
|
new AutoCompleteItem('Tatooine', SearchQueryTypes.position)]);
|
|
|
|
expect((await sm.autocomplete('star', SearchQueryTypes.any_text))).to.deep.equalInAnyOrder([
|
|
|
|
new AutoCompleteItem('star wars', SearchQueryTypes.keyword),
|
2021-01-17 17:56:33 +08:00
|
|
|
new AutoCompleteItem('death star', SearchQueryTypes.keyword)]);
|
|
|
|
|
2021-01-17 22:56:15 +08:00
|
|
|
expect((await sm.autocomplete('wars', SearchQueryTypes.any_text))).to.deep.equalInAnyOrder([
|
|
|
|
new AutoCompleteItem('star wars', SearchQueryTypes.keyword),
|
2021-01-17 17:56:33 +08:00
|
|
|
new AutoCompleteItem('wars dir', SearchQueryTypes.directory)]);
|
|
|
|
|
2021-01-17 22:56:15 +08:00
|
|
|
expect((await sm.autocomplete('arch', SearchQueryTypes.any_text))).eql([
|
|
|
|
new AutoCompleteItem('Research City', SearchQueryTypes.position)]);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Search.AutoComplete.targetItemsPerCategory = 99999;
|
2021-01-17 22:56:15 +08:00
|
|
|
expect((await sm.autocomplete('wa', SearchQueryTypes.any_text))).to.deep.equalInAnyOrder([
|
2021-01-17 17:56:33 +08:00
|
|
|
new AutoCompleteItem('star wars', SearchQueryTypes.keyword),
|
|
|
|
new AutoCompleteItem('Anakin Skywalker', SearchQueryTypes.person),
|
|
|
|
new AutoCompleteItem('Luke Skywalker', SearchQueryTypes.person),
|
2021-01-17 22:56:15 +08:00
|
|
|
new AutoCompleteItem('wars dir', SearchQueryTypes.directory)]);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Search.AutoComplete.targetItemsPerCategory = 1;
|
2021-01-17 22:56:15 +08:00
|
|
|
expect((await sm.autocomplete('a', SearchQueryTypes.any_text))).to.deep.equalInAnyOrder([
|
|
|
|
new AutoCompleteItem('Ajan Kloss', SearchQueryTypes.position),
|
2022-02-22 21:12:33 +08:00
|
|
|
new AutoCompleteItem('Tipoca City', SearchQueryTypes.position),
|
2021-01-17 22:56:15 +08:00
|
|
|
new AutoCompleteItem('Amber stone', SearchQueryTypes.caption),
|
2022-02-22 21:12:33 +08:00
|
|
|
new AutoCompleteItem('Millennium falcon', SearchQueryTypes.caption),
|
2021-01-17 17:56:33 +08:00
|
|
|
new AutoCompleteItem('star wars', SearchQueryTypes.keyword),
|
|
|
|
new AutoCompleteItem('Anakin Skywalker', SearchQueryTypes.person),
|
2022-02-22 21:12:33 +08:00
|
|
|
new AutoCompleteItem('Obivan Kenobi', SearchQueryTypes.person),
|
2021-01-17 22:56:15 +08:00
|
|
|
new AutoCompleteItem('Castilon', SearchQueryTypes.position),
|
|
|
|
new AutoCompleteItem('Devaron', SearchQueryTypes.position),
|
2022-02-22 21:12:33 +08:00
|
|
|
new AutoCompleteItem('Jedha', SearchQueryTypes.position),
|
|
|
|
new AutoCompleteItem('wars dir', SearchQueryTypes.directory),
|
2021-01-17 22:56:15 +08:00
|
|
|
new AutoCompleteItem('The Phantom Menace', SearchQueryTypes.directory)]);
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Search.AutoComplete.targetItemsPerCategory = 5;
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-01-17 22:56:15 +08:00
|
|
|
expect((await sm.autocomplete('sw', SearchQueryTypes.any_text))).to.deep.equalInAnyOrder([
|
|
|
|
new AutoCompleteItem('sw1.jpg', SearchQueryTypes.file_name),
|
|
|
|
new AutoCompleteItem('sw2.jpg', SearchQueryTypes.file_name),
|
|
|
|
new AutoCompleteItem('sw3.jpg', SearchQueryTypes.file_name),
|
|
|
|
new AutoCompleteItem('sw4.jpg', SearchQueryTypes.file_name),
|
|
|
|
new AutoCompleteItem(v.name, SearchQueryTypes.file_name)]);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-01-17 22:56:15 +08:00
|
|
|
expect((await sm.autocomplete(v.name, SearchQueryTypes.any_text))).to.deep.equalInAnyOrder(
|
|
|
|
[new AutoCompleteItem(v.name, SearchQueryTypes.file_name)]);
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
});
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-06-19 18:08:17 +08:00
|
|
|
const searchifyMedia = <T extends FileDTO | PhotoDTO>(m: T): T => {
|
2021-06-28 01:33:37 +08:00
|
|
|
const tmpDir: DirectoryBaseDTO = m.directory as DirectoryBaseDTO;
|
|
|
|
const tmpM = tmpDir.media;
|
|
|
|
const tmpD = tmpDir.directories;
|
|
|
|
const tmpP = tmpDir.preview;
|
|
|
|
const tmpMT = tmpDir.metaFile;
|
|
|
|
delete tmpDir.directories;
|
|
|
|
delete tmpDir.media;
|
|
|
|
delete tmpDir.preview;
|
2022-01-15 03:57:20 +08:00
|
|
|
delete tmpDir.validPreview;
|
2021-06-28 01:33:37 +08:00
|
|
|
delete tmpDir.metaFile;
|
2021-01-16 23:59:59 +08:00
|
|
|
const ret = Utils.clone(m);
|
2021-06-28 01:33:37 +08:00
|
|
|
delete (ret.directory as DirectoryBaseDTO).lastScanned;
|
|
|
|
delete (ret.directory as DirectoryBaseDTO).lastModified;
|
|
|
|
delete (ret.directory as DirectoryBaseDTO).mediaCount;
|
2021-06-19 18:08:17 +08:00
|
|
|
if ((ret as PhotoDTO).metadata &&
|
|
|
|
((ret as PhotoDTO).metadata as PhotoMetadata).faces && !((ret as PhotoDTO).metadata as PhotoMetadata).faces.length) {
|
|
|
|
delete ((ret as PhotoDTO).metadata as PhotoMetadata).faces;
|
2021-01-16 23:59:59 +08:00
|
|
|
}
|
2021-06-28 01:33:37 +08:00
|
|
|
tmpDir.directories = tmpD;
|
|
|
|
tmpDir.media = tmpM;
|
|
|
|
tmpDir.preview = tmpP;
|
|
|
|
tmpDir.metaFile = tmpMT;
|
2021-01-16 23:59:59 +08:00
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
2021-06-28 01:33:37 +08:00
|
|
|
const searchifyDir = (d: DirectoryBaseDTO): DirectoryBaseDTO => {
|
2021-05-24 04:26:27 +08:00
|
|
|
const tmpM = d.media;
|
|
|
|
const tmpD = d.directories;
|
|
|
|
const tmpP = d.preview;
|
|
|
|
const tmpMT = d.metaFile;
|
|
|
|
delete d.directories;
|
|
|
|
delete d.media;
|
|
|
|
delete d.metaFile;
|
|
|
|
const ret = Utils.clone(d);
|
|
|
|
d.directories = tmpD;
|
|
|
|
d.media = tmpM;
|
|
|
|
d.preview = tmpP;
|
|
|
|
d.metaFile = tmpMT;
|
|
|
|
ret.isPartial = true;
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
2021-01-16 23:59:59 +08:00
|
|
|
const removeDir = (result: SearchResultDTO) => {
|
|
|
|
result.media = result.media.map(m => searchifyMedia(m));
|
2021-06-19 18:08:17 +08:00
|
|
|
result.metaFile = result.metaFile.map(m => searchifyMedia(m));
|
2021-06-28 01:33:37 +08:00
|
|
|
result.directories = result.directories.map(m => searchifyDir(m) as SubDirectoryDTO);
|
2021-01-16 23:59:59 +08:00
|
|
|
return Utils.clone(result);
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('advanced search', async () => {
|
2021-06-19 18:08:17 +08:00
|
|
|
afterEach(async () => {
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Search.listDirectories = false;
|
|
|
|
Config.Search.listMetafiles = false;
|
2021-06-19 18:08:17 +08:00
|
|
|
});
|
|
|
|
afterEach(async () => {
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Search.listDirectories = false;
|
|
|
|
Config.Search.listMetafiles = false;
|
2021-06-19 18:08:17 +08:00
|
|
|
});
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
it('should AND', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
let query: SearchQueryDTO = {
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.AND,
|
2021-04-18 21:48:35 +08:00
|
|
|
list: [{text: p.metadata.faces[0].name, type: SearchQueryTypes.person} as TextSearch,
|
|
|
|
{text: p2.metadata.caption, type: SearchQueryTypes.caption} as TextSearch]
|
|
|
|
} as ANDSearchQuery;
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
|
|
|
query = ({
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.AND,
|
2021-04-18 21:48:35 +08:00
|
|
|
list: [{text: p.metadata.faces[0].name, type: SearchQueryTypes.person} as TextSearch,
|
|
|
|
{text: p.metadata.caption, type: SearchQueryTypes.caption} as TextSearch]
|
|
|
|
} as ANDSearchQuery);
|
|
|
|
expect(await sm.search(query)).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
// make sure that this shows both photos. We need this the the rest of the tests
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({text: 'a', type: SearchQueryTypes.person} as TextSearch);
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
2021-01-17 06:37:14 +08:00
|
|
|
media: [p, p2, p4],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.AND,
|
2021-04-18 21:48:35 +08:00
|
|
|
list: [{
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.AND,
|
2021-04-18 21:48:35 +08:00
|
|
|
list: [{text: 'a', type: SearchQueryTypes.person} as TextSearch,
|
|
|
|
{text: p.metadata.keywords[0], type: SearchQueryTypes.keyword} as TextSearch]
|
|
|
|
} as ANDSearchQuery,
|
|
|
|
{text: p.metadata.caption, type: SearchQueryTypes.caption} as TextSearch
|
2021-01-16 23:59:59 +08:00
|
|
|
]
|
2021-04-18 21:48:35 +08:00
|
|
|
} as ANDSearchQuery);
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should OR', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
let query: SearchQueryDTO = {
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.OR,
|
2021-04-18 21:48:35 +08:00
|
|
|
list: [{text: 'Not a person', type: SearchQueryTypes.person} as TextSearch,
|
|
|
|
{text: 'Not a caption', type: SearchQueryTypes.caption} as TextSearch]
|
|
|
|
} as ORSearchQuery;
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
|
|
|
query = ({
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.OR,
|
2021-04-18 21:48:35 +08:00
|
|
|
list: [{text: p.metadata.faces[0].name, type: SearchQueryTypes.person} as TextSearch,
|
|
|
|
{text: p2.metadata.caption, type: SearchQueryTypes.caption} as TextSearch]
|
|
|
|
} as ORSearchQuery);
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.OR,
|
2021-04-18 21:48:35 +08:00
|
|
|
list: [{text: p.metadata.faces[0].name, type: SearchQueryTypes.person} as TextSearch,
|
|
|
|
{text: p.metadata.caption, type: SearchQueryTypes.caption} as TextSearch]
|
|
|
|
} as ORSearchQuery);
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
// make sure that this shows both photos. We need this the the rest of the tests
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({text: 'a', type: SearchQueryTypes.person} as TextSearch);
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
2021-01-17 06:37:14 +08:00
|
|
|
media: [p, p2, p4],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.OR,
|
2021-04-18 21:48:35 +08:00
|
|
|
list: [{
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.OR,
|
2021-04-18 21:48:35 +08:00
|
|
|
list: [{text: 'a', type: SearchQueryTypes.person} as TextSearch,
|
|
|
|
{text: p.metadata.keywords[0], type: SearchQueryTypes.keyword} as TextSearch]
|
|
|
|
} as ORSearchQuery,
|
|
|
|
{text: p.metadata.caption, type: SearchQueryTypes.caption} as TextSearch
|
2021-01-16 23:59:59 +08:00
|
|
|
]
|
2021-04-18 21:48:35 +08:00
|
|
|
} as ORSearchQuery);
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
2021-01-17 06:37:14 +08:00
|
|
|
media: [p, p2, p4],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.OR,
|
2021-04-18 21:48:35 +08:00
|
|
|
list: [{
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.OR,
|
2021-04-18 21:48:35 +08:00
|
|
|
list: [{text: p.metadata.keywords[0], type: SearchQueryTypes.keyword} as TextSearch,
|
|
|
|
{text: p2.metadata.keywords[0], type: SearchQueryTypes.keyword} as TextSearch]
|
|
|
|
} as ORSearchQuery,
|
|
|
|
{text: pFaceLess.metadata.caption, type: SearchQueryTypes.caption} as TextSearch
|
2021-01-16 23:59:59 +08:00
|
|
|
]
|
2021-04-18 21:48:35 +08:00
|
|
|
} as ORSearchQuery);
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [p, p2, pFaceLess],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2021-01-17 06:37:14 +08:00
|
|
|
|
|
|
|
it('should minimum of', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
let query: SomeOfSearchQuery = {
|
2021-01-17 06:37:14 +08:00
|
|
|
type: SearchQueryTypes.SOME_OF,
|
2021-04-18 21:48:35 +08:00
|
|
|
list: [{text: 'jpg', type: SearchQueryTypes.file_name} as TextSearch,
|
|
|
|
{text: 'mp4', type: SearchQueryTypes.file_name} as TextSearch]
|
|
|
|
} as SomeOfSearchQuery;
|
2021-01-17 06:37:14 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [p, p2, pFaceLess, p4, v],
|
2021-01-17 06:37:14 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 06:37:14 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-17 06:37:14 +08:00
|
|
|
type: SearchQueryTypes.SOME_OF,
|
2021-04-18 21:48:35 +08:00
|
|
|
list: [{text: 'R2', type: SearchQueryTypes.person} as TextSearch,
|
|
|
|
{text: 'Anakin', type: SearchQueryTypes.person} as TextSearch,
|
|
|
|
{text: 'Luke', type: SearchQueryTypes.person} as TextSearch]
|
|
|
|
} as SomeOfSearchQuery);
|
2021-01-17 06:37:14 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2, p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 06:37:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
query.min = 2;
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2, p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 06:37:14 +08:00
|
|
|
|
|
|
|
query.min = 3;
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 06:37:14 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-17 06:37:14 +08:00
|
|
|
type: SearchQueryTypes.SOME_OF,
|
|
|
|
min: 3,
|
2021-04-18 21:48:35 +08:00
|
|
|
list: [{text: 'sw', type: SearchQueryTypes.file_name} as TextSearch,
|
|
|
|
{text: 'R2', type: SearchQueryTypes.person} as TextSearch,
|
|
|
|
{text: 'Kamino', type: SearchQueryTypes.position} as TextSearch,
|
|
|
|
{text: 'Han', type: SearchQueryTypes.person} as TextSearch]
|
|
|
|
} as SomeOfSearchQuery);
|
2021-01-17 06:37:14 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
2021-01-17 17:56:33 +08:00
|
|
|
media: [p, p2],
|
2021-01-17 06:37:14 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 06:37:14 +08:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2021-01-16 23:59:59 +08:00
|
|
|
describe('should search text', async () => {
|
|
|
|
it('as any', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
let query = {text: 'sw', type: SearchQueryTypes.any_text} as TextSearch;
|
|
|
|
expect(Utils.clone(await sm.search({text: 'sw', type: SearchQueryTypes.any_text} as TextSearch)))
|
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [p, p2, pFaceLess, v, p4],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-24 04:26:27 +08:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2018-01-31 09:01:16 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({text: 'sw', negate: true, type: SearchQueryTypes.any_text} as TextSearch);
|
2021-01-17 06:37:14 +08:00
|
|
|
|
2021-05-24 04:26:27 +08:00
|
|
|
expect(removeDir(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-06-19 18:08:17 +08:00
|
|
|
directories: [],
|
2021-01-17 06:37:14 +08:00
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-24 04:26:27 +08:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-17 06:37:14 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({text: 'Boba', type: SearchQueryTypes.any_text} as TextSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-24 04:26:27 +08:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({text: 'Boba', negate: true, type: SearchQueryTypes.any_text} as TextSearch);
|
2021-05-24 04:26:27 +08:00
|
|
|
expect(removeDir(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-06-19 18:08:17 +08:00
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [p2, pFaceLess, p4],
|
2021-01-17 06:37:14 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-24 04:26:27 +08:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-17 06:37:14 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({text: 'Boba', negate: true, type: SearchQueryTypes.any_text} as TextSearch);
|
2021-01-17 06:37:14 +08:00
|
|
|
// all should have faces
|
2021-01-17 17:56:33 +08:00
|
|
|
const sRet = await sm.search(query);
|
2021-04-18 21:48:35 +08:00
|
|
|
for (const item of sRet.media) {
|
|
|
|
if (item.id === pFaceLess.id) {
|
2021-01-17 06:37:14 +08:00
|
|
|
continue;
|
|
|
|
}
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect((item as PhotoDTO).metadata.faces).to.be.not.an('undefined');
|
|
|
|
expect((item as PhotoDTO).metadata.faces).to.be.lengthOf.above(1);
|
2021-01-17 06:37:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'Boba',
|
|
|
|
type: SearchQueryTypes.any_text,
|
2021-01-31 19:22:56 +08:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-24 04:26:27 +08:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'Boba Fett',
|
|
|
|
type: SearchQueryTypes.any_text,
|
2021-01-31 19:22:56 +08:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-24 04:26:27 +08:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('as position', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
const query = {text: 'Tatooine', type: SearchQueryTypes.position} as TextSearch;
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('as keyword', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
let query = {
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'kie',
|
|
|
|
type: SearchQueryTypes.keyword
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch;
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [p2, pFaceLess],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'wa',
|
|
|
|
type: SearchQueryTypes.keyword
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [p, p2, pFaceLess, p4],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'han',
|
|
|
|
type: SearchQueryTypes.keyword
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-17 17:56:33 +08:00
|
|
|
text: 'star wars',
|
2021-01-31 19:22:56 +08:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match,
|
2021-01-17 17:56:33 +08:00
|
|
|
type: SearchQueryTypes.keyword
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [p, p2, pFaceLess, p4],
|
2021-01-17 17:56:33 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-17 17:56:33 +08:00
|
|
|
text: 'wookiees',
|
2021-01-31 19:22:56 +08:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match,
|
2021-01-17 17:56:33 +08:00
|
|
|
type: SearchQueryTypes.keyword
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [pFaceLess],
|
2021-01-17 17:56:33 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-01-16 23:59:59 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('as caption', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
const query = {
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'han',
|
|
|
|
type: SearchQueryTypes.caption
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch;
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('as file_name', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
let query = {
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'sw',
|
|
|
|
type: SearchQueryTypes.file_name
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch;
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [p, p2, pFaceLess, v, p4],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-17 17:56:33 +08:00
|
|
|
text: 'sw4',
|
|
|
|
type: SearchQueryTypes.file_name
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search({
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'sw4',
|
|
|
|
type: SearchQueryTypes.file_name
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('as directory', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
let query = {
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'of the J',
|
|
|
|
type: SearchQueryTypes.directory
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch;
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-05-24 04:26:27 +08:00
|
|
|
expect(removeDir(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-06-19 18:08:17 +08:00
|
|
|
directories: [],
|
2021-01-16 23:59:59 +08:00
|
|
|
media: [p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-24 04:26:27 +08:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'wars dir',
|
|
|
|
type: SearchQueryTypes.directory
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-05-24 04:26:27 +08:00
|
|
|
expect(removeDir(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-06-19 18:08:17 +08:00
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [p, p2, v, pFaceLess, p4],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-24 04:26:27 +08:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-17 17:56:33 +08:00
|
|
|
text: '/wars dir',
|
2021-01-31 19:22:56 +08:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match,
|
2021-01-17 17:56:33 +08:00
|
|
|
type: SearchQueryTypes.directory
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
|
2021-05-24 04:26:27 +08:00
|
|
|
expect(removeDir(await sm.search({
|
2021-01-16 23:59:59 +08:00
|
|
|
text: '/wars dir',
|
2021-01-31 19:22:56 +08:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match,
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.directory
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-06-19 18:08:17 +08:00
|
|
|
directories: [],
|
2021-01-16 23:59:59 +08:00
|
|
|
media: [p, p2, v],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-24 04:26:27 +08:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-16 23:59:59 +08:00
|
|
|
text: '/wars dir/Return of the Jedi',
|
2021-05-30 23:26:07 +08:00
|
|
|
// matchType: TextSearchQueryMatchTypes.like,
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.directory
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-05-24 04:26:27 +08:00
|
|
|
expect(removeDir(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-06-19 18:08:17 +08:00
|
|
|
directories: [],
|
2021-01-16 23:59:59 +08:00
|
|
|
media: [p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-24 04:26:27 +08:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-16 23:59:59 +08:00
|
|
|
text: '/wars dir/Return of the Jedi',
|
2021-01-31 19:22:56 +08:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match,
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.directory
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-05-24 04:26:27 +08:00
|
|
|
expect(removeDir(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-06-19 18:08:17 +08:00
|
|
|
directories: [],
|
2021-01-16 23:59:59 +08:00
|
|
|
media: [p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-24 04:26:27 +08:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('as person', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
let query = {
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'Boba',
|
|
|
|
type: SearchQueryTypes.person
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch;
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'Boba',
|
|
|
|
type: SearchQueryTypes.person,
|
2021-01-31 19:22:56 +08:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-17 17:56:33 +08:00
|
|
|
text: 'Boba Fett',
|
|
|
|
type: SearchQueryTypes.person,
|
2021-01-31 19:22:56 +08:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
expect(Utils.clone(await sm.search({
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'Boba Fett',
|
|
|
|
type: SearchQueryTypes.person,
|
2021-01-31 19:22:56 +08:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should search date', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
let query: any = {value: 0, type: SearchQueryTypes.to_date} as ToDateSearch;
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-03-14 17:56:59 +08:00
|
|
|
value: p.metadata.creationDate, type: SearchQueryTypes.from_date
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FromDateSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
2021-03-14 17:56:59 +08:00
|
|
|
media: [p, v],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-02-14 19:57:05 +08:00
|
|
|
value: p.metadata.creationDate,
|
2021-01-17 06:37:14 +08:00
|
|
|
negate: true,
|
2021-02-14 19:57:05 +08:00
|
|
|
type: SearchQueryTypes.from_date
|
2021-04-18 21:48:35 +08:00
|
|
|
} as FromDateSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [p2, pFaceLess, p4],
|
2021-01-17 06:37:14 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 06:37:14 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-02-14 19:57:05 +08:00
|
|
|
value: p.metadata.creationDate + 1000000000,
|
|
|
|
type: SearchQueryTypes.to_date
|
2021-04-18 21:48:35 +08:00
|
|
|
} as ToDateSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-02-14 19:57:05 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [p, p2, pFaceLess, v, p4],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should search rating', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
let query: MinRatingSearch | MaxRatingSearch = {value: 0, type: SearchQueryTypes.max_rating} as MaxRatingSearch;
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({value: 5, type: SearchQueryTypes.max_rating} as MaxRatingSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [p, p2, pFaceLess],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({value: 5, negate: true, type: SearchQueryTypes.max_rating} as MaxRatingSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 06:37:14 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({value: 2, type: SearchQueryTypes.min_rating} as MinRatingSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [p2, pFaceLess],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({value: 2, negate: true, type: SearchQueryTypes.min_rating} as MinRatingSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
2021-03-14 17:56:59 +08:00
|
|
|
media: [p],
|
2021-01-17 06:37:14 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should search resolution', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-02-14 19:57:05 +08:00
|
|
|
let query: MinResolutionSearch | MaxResolutionSearch =
|
2021-04-18 21:48:35 +08:00
|
|
|
{value: 0, type: SearchQueryTypes.max_resolution} as MaxResolutionSearch;
|
2021-02-14 19:57:05 +08:00
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({value: 1, type: SearchQueryTypes.max_resolution} as MaxResolutionSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, v],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({value: 3, type: SearchQueryTypes.min_resolution} as MinResolutionSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
2021-03-14 17:56:59 +08:00
|
|
|
media: [p4],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-03-14 17:56:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({value: 3, negate: true, type: SearchQueryTypes.min_resolution} as MinResolutionSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [p, p2, pFaceLess, v],
|
2021-01-17 06:37:14 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 06:37:14 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({value: 3, negate: true, type: SearchQueryTypes.max_resolution} as MaxResolutionSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should search orientation', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
let query = {
|
2021-01-17 06:37:14 +08:00
|
|
|
landscape: false,
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.orientation
|
2021-04-18 21:48:35 +08:00
|
|
|
} as OrientationSearch;
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
2022-06-25 00:05:45 +08:00
|
|
|
media: [p, p2, p4],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-17 06:37:14 +08:00
|
|
|
landscape: true,
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.orientation
|
2021-04-18 21:48:35 +08:00
|
|
|
} as OrientationSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [p, pFaceLess, v],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2021-04-06 17:32:31 +08:00
|
|
|
it('should search distance', async () => {
|
2021-01-16 23:59:59 +08:00
|
|
|
ObjectManagers.getInstance().LocationManager = new LocationManager();
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
|
|
|
ObjectManagers.getInstance().LocationManager.getGPSData = async (): Promise<GPSMetadata> => {
|
|
|
|
return {
|
|
|
|
longitude: 10,
|
2022-03-26 04:51:42 +08:00
|
|
|
latitude: 10
|
2021-01-16 23:59:59 +08:00
|
|
|
};
|
|
|
|
};
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
let query = {
|
2021-01-16 23:59:59 +08:00
|
|
|
from: {text: 'Tatooine'},
|
|
|
|
distance: 1,
|
|
|
|
type: SearchQueryTypes.distance
|
2021-04-18 21:48:35 +08:00
|
|
|
} as DistanceSearch;
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-16 23:59:59 +08:00
|
|
|
from: {GPSData: {latitude: 0, longitude: 0}},
|
|
|
|
distance: 112 * 10, // number of km per degree = ~111km
|
|
|
|
type: SearchQueryTypes.distance
|
2021-04-18 21:48:35 +08:00
|
|
|
} as DistanceSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-17 06:37:14 +08:00
|
|
|
from: {GPSData: {latitude: 0, longitude: 0}},
|
|
|
|
distance: 112 * 10, // number of km per degree = ~111km
|
|
|
|
negate: true,
|
|
|
|
type: SearchQueryTypes.distance
|
2021-04-18 21:48:35 +08:00
|
|
|
} as DistanceSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [pFaceLess, p4],
|
2021-01-17 06:37:14 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
|
|
|
query = ({
|
2021-01-16 23:59:59 +08:00
|
|
|
from: {GPSData: {latitude: 10, longitude: 10}},
|
|
|
|
distance: 1,
|
|
|
|
type: SearchQueryTypes.distance
|
2021-04-18 21:48:35 +08:00
|
|
|
} as DistanceSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-16 23:59:59 +08:00
|
|
|
from: {GPSData: {latitude: 10, longitude: 10}},
|
|
|
|
distance: 112 * 5, // number of km per degree = ~111km
|
|
|
|
type: SearchQueryTypes.distance
|
2021-04-18 21:48:35 +08:00
|
|
|
} as DistanceSearch);
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 21:48:35 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
2021-04-18 21:48:35 +08:00
|
|
|
media: [p, pFaceLess, p4],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 21:48:35 +08:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
});
|
2018-01-31 09:01:16 +08:00
|
|
|
|
2021-05-31 22:44:37 +08:00
|
|
|
/**
|
2022-12-05 05:23:51 +08:00
|
|
|
* flattenSameOfQueries converts some-of queries to AND and OR queries
|
2021-05-31 22:44:37 +08:00
|
|
|
* E.g.:
|
|
|
|
* 2-of:(A B C) to (A and (B or C)) or (B and C)
|
|
|
|
* this tests makes sure that all queries has at least 2 constraints
|
|
|
|
*/
|
|
|
|
(it('should flatter SOME_OF query', () => {
|
|
|
|
const sm = new SearchManagerTest();
|
|
|
|
const parser = new SearchQueryParser();
|
|
|
|
const alphabet = 'abcdefghijklmnopqrstu';
|
|
|
|
|
|
|
|
|
|
|
|
const shortestDepth = (q: SearchQueryDTO): number => {
|
|
|
|
let depth = 0;
|
|
|
|
if ((q as SearchListQuery).list) {
|
|
|
|
if (q.type === SearchQueryTypes.AND) {
|
|
|
|
for (const l of (q as SearchListQuery).list) {
|
|
|
|
depth += shortestDepth(l);
|
|
|
|
}
|
|
|
|
return depth;
|
|
|
|
}
|
2022-12-05 05:23:51 +08:00
|
|
|
// it's an OR
|
2021-05-31 22:44:37 +08:00
|
|
|
const lengths = (q as SearchListQuery).list.map(l => shortestDepth(l)).sort();
|
|
|
|
return lengths[0];
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
const checkBoolLogic = (q: SearchQueryDTO) => {
|
|
|
|
if ((q as SearchListQuery).list) {
|
|
|
|
expect((q as SearchListQuery).list).to.not.equal(1);
|
|
|
|
for (const l of (q as SearchListQuery).list) {
|
|
|
|
checkBoolLogic(l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-04-05 01:37:31 +08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
2021-05-31 22:44:37 +08:00
|
|
|
for (let i = 1; i < alphabet.length / 2; ++i) {
|
|
|
|
const query: SomeOfSearchQuery = {
|
|
|
|
type: SearchQueryTypes.SOME_OF,
|
|
|
|
min: i,
|
|
|
|
//
|
|
|
|
list: alphabet.split('').map(t => ({
|
|
|
|
type: SearchQueryTypes.file_name,
|
|
|
|
text: t
|
|
|
|
} as TextSearch))
|
|
|
|
};
|
|
|
|
const q = sm.flattenSameOfQueries(query);
|
|
|
|
expect(shortestDepth(q)).to.equal(i, parser.stringify(query) + '\n' + parser.stringify(q));
|
|
|
|
checkBoolLogic(q);
|
|
|
|
}
|
|
|
|
}) as any).timeout(20000);
|
|
|
|
|
|
|
|
(it('should execute complex SOME_OF query', async () => {
|
2021-05-30 23:26:07 +08:00
|
|
|
const sm = new SearchManager();
|
|
|
|
|
|
|
|
const query: SomeOfSearchQuery = {
|
|
|
|
type: SearchQueryTypes.SOME_OF,
|
|
|
|
min: 5,
|
|
|
|
//
|
|
|
|
list: 'abcdefghijklmnopqrstu'.split('').map(t => ({
|
|
|
|
type: SearchQueryTypes.file_name,
|
|
|
|
text: t
|
|
|
|
} as TextSearch))
|
|
|
|
};
|
|
|
|
expect(removeDir(await sm.search(query)))
|
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
|
|
|
searchQuery: query,
|
|
|
|
directories: [],
|
|
|
|
media: [v],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
} as SearchResultDTO));
|
|
|
|
}) as any).timeout(40000);
|
|
|
|
|
2021-05-24 04:26:27 +08:00
|
|
|
it('search result should return directory', async () => {
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Search.listDirectories = true;
|
2021-05-24 04:26:27 +08:00
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2022-01-19 03:38:13 +08:00
|
|
|
const cloned = Utils.clone(searchifyDir(subDir));
|
|
|
|
cloned.validPreview = true;
|
|
|
|
cloned.preview = {
|
|
|
|
directory: {
|
|
|
|
name: subDir.name,
|
|
|
|
path: subDir.path
|
|
|
|
},
|
2022-03-26 18:55:15 +08:00
|
|
|
name: pFaceLess.name
|
2022-01-19 03:38:13 +08:00
|
|
|
} as any;
|
2021-05-30 23:26:07 +08:00
|
|
|
const query = {
|
2021-05-24 04:26:27 +08:00
|
|
|
text: subDir.name,
|
|
|
|
type: SearchQueryTypes.any_text
|
|
|
|
} as TextSearch;
|
|
|
|
expect(removeDir(await sm.search(query)))
|
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
|
|
|
searchQuery: query,
|
2022-01-19 03:38:13 +08:00
|
|
|
directories: [cloned],
|
2021-05-24 04:26:27 +08:00
|
|
|
media: [pFaceLess],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
} as SearchResultDTO));
|
|
|
|
});
|
2021-06-19 18:08:17 +08:00
|
|
|
it('search result should return meta files', async () => {
|
2022-12-29 02:12:18 +08:00
|
|
|
Config.Search.listMetafiles = true;
|
2021-06-19 18:08:17 +08:00
|
|
|
const sm = new SearchManager();
|
|
|
|
|
|
|
|
const query = {
|
|
|
|
text: dir.name,
|
|
|
|
type: SearchQueryTypes.any_text,
|
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match
|
|
|
|
} as TextSearch;
|
|
|
|
expect(removeDir(await sm.search(query)))
|
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
|
|
|
searchQuery: query,
|
|
|
|
directories: [],
|
|
|
|
media: [p, p2, v],
|
|
|
|
metaFile: [gpx],
|
|
|
|
resultOverflow: false
|
|
|
|
} as SearchResultDTO));
|
|
|
|
});
|
2021-05-24 04:26:27 +08:00
|
|
|
|
2018-01-31 09:01:16 +08:00
|
|
|
});
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-01-17 22:56:15 +08:00
|
|
|
|
|
|
|
it('should get random photo', async () => {
|
2021-01-17 17:56:33 +08:00
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
let query = {
|
2021-01-17 22:56:15 +08:00
|
|
|
text: 'xyz',
|
|
|
|
type: SearchQueryTypes.keyword
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch;
|
2021-02-14 19:57:05 +08:00
|
|
|
|
2022-04-05 01:37:31 +08:00
|
|
|
// eslint-disable-next-line
|
2021-01-17 22:56:15 +08:00
|
|
|
expect(await sm.getRandomPhoto(query)).to.not.exist;
|
2018-01-31 09:01:16 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
query = ({
|
2021-01-17 22:56:15 +08:00
|
|
|
text: 'wookiees',
|
2021-01-31 19:22:56 +08:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match,
|
2021-01-17 22:56:15 +08:00
|
|
|
type: SearchQueryTypes.keyword
|
2021-04-18 21:48:35 +08:00
|
|
|
} as TextSearch);
|
|
|
|
expect(Utils.clone(await sm.getRandomPhoto(query))).to.deep.equalInAnyOrder(searchifyMedia(pFaceLess));
|
2021-01-17 22:56:15 +08:00
|
|
|
});
|
2018-01-31 09:01:16 +08:00
|
|
|
|
|
|
|
});
|