2021-01-16 17:59:59 +02:00
|
|
|
import {LocationManager} from '../../../../../src/backend/model/database/LocationManager';
|
2019-12-14 18:27:01 +02:00
|
|
|
import {SearchManager} from '../../../../../src/backend/model/database/sql/SearchManager';
|
2019-12-10 11:44:35 +02:00
|
|
|
import {SearchResultDTO} from '../../../../../src/common/entities/SearchResultDTO';
|
|
|
|
import {Utils} from '../../../../../src/common/Utils';
|
2021-04-01 21:48:38 +02:00
|
|
|
import {DBTestHelper} from '../../../DBTestHelper';
|
2021-01-16 17:59:59 +02:00
|
|
|
import {
|
|
|
|
ANDSearchQuery,
|
|
|
|
DistanceSearch,
|
2021-02-14 13:57:05 +02:00
|
|
|
FromDateSearch,
|
|
|
|
MaxRatingSearch,
|
|
|
|
MaxResolutionSearch,
|
|
|
|
MinRatingSearch,
|
|
|
|
MinResolutionSearch,
|
2021-01-16 17:59:59 +02:00
|
|
|
OrientationSearch,
|
|
|
|
ORSearchQuery,
|
2021-05-31 16:44:37 +02:00
|
|
|
SearchListQuery,
|
2021-01-16 17:59:59 +02:00
|
|
|
SearchQueryDTO,
|
|
|
|
SearchQueryTypes,
|
2021-01-17 00:37:14 +02:00
|
|
|
SomeOfSearchQuery,
|
2021-01-16 17:59:59 +02:00
|
|
|
TextSearch,
|
2021-02-14 13:57:05 +02:00
|
|
|
TextSearchQueryMatchTypes,
|
|
|
|
ToDateSearch
|
2021-01-16 17:59:59 +02:00
|
|
|
} from '../../../../../src/common/entities/SearchQueryDTO';
|
|
|
|
import {IndexingManager} from '../../../../../src/backend/model/database/sql/IndexingManager';
|
|
|
|
import {DirectoryDTO} from '../../../../../src/common/entities/DirectoryDTO';
|
|
|
|
import {TestHelper} from './TestHelper';
|
|
|
|
import {ObjectManagers} from '../../../../../src/backend/model/ObjectManagers';
|
|
|
|
import {GalleryManager} from '../../../../../src/backend/model/database/sql/GalleryManager';
|
|
|
|
import {Connection} from 'typeorm';
|
|
|
|
import {DirectoryEntity} from '../../../../../src/backend/model/database/sql/enitites/DirectoryEntity';
|
|
|
|
import {GPSMetadata, PhotoDTO, PhotoMetadata} from '../../../../../src/common/entities/PhotoDTO';
|
|
|
|
import {VideoDTO} from '../../../../../src/common/entities/VideoDTO';
|
|
|
|
import {MediaDTO} from '../../../../../src/common/entities/MediaDTO';
|
2021-01-17 11:56:33 +02:00
|
|
|
import {AutoCompleteItem} from '../../../../../src/common/entities/AutoCompleteItem';
|
|
|
|
import {Config} from '../../../../../src/common/config/private/Config';
|
2021-05-31 16:44:37 +02:00
|
|
|
import {SearchQueryParser} from '../../../../../src/common/SearchQueryParser';
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
const deepEqualInAnyOrder = require('deep-equal-in-any-order');
|
|
|
|
const chai = require('chai');
|
|
|
|
|
|
|
|
chai.use(deepEqualInAnyOrder);
|
|
|
|
const {expect} = chai;
|
2018-01-31 03:01:16 +02:00
|
|
|
|
2019-01-27 21:36:42 +02:00
|
|
|
// to help WebStorm to handle the test cases
|
|
|
|
declare let describe: any;
|
|
|
|
declare const after: any;
|
2021-01-17 11:56:33 +02:00
|
|
|
declare const before: any;
|
2021-01-16 17:59:59 +02:00
|
|
|
const tmpDescribe = describe;
|
2021-04-01 21:48:38 +02:00
|
|
|
describe = DBTestHelper.describe(); // fake it os IDE plays nicely (recognize the test)
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
class IndexingManagerTest extends IndexingManager {
|
|
|
|
|
|
|
|
public async saveToDB(scannedDirectory: DirectoryDTO): Promise<void> {
|
|
|
|
return super.saveToDB(scannedDirectory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-31 16:44:37 +02:00
|
|
|
class SearchManagerTest extends SearchManager {
|
|
|
|
|
|
|
|
public flattenSameOfQueries(query: SearchQueryDTO): SearchQueryDTO {
|
|
|
|
return super.flattenSameOfQueries(query);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-16 17:59:59 +02:00
|
|
|
class GalleryManagerTest extends GalleryManager {
|
|
|
|
|
|
|
|
public async selectParentDir(connection: Connection, directoryName: string, directoryParent: string): Promise<DirectoryEntity> {
|
|
|
|
return super.selectParentDir(connection, directoryName, directoryParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async fillParentDir(connection: Connection, dir: DirectoryEntity): Promise<void> {
|
|
|
|
return super.fillParentDir(connection, dir);
|
|
|
|
}
|
|
|
|
}
|
2018-01-31 03:01:16 +02:00
|
|
|
|
2021-04-01 21:48:38 +02:00
|
|
|
describe('SearchManager', (sqlHelper: DBTestHelper) => {
|
2021-01-16 17:59:59 +02:00
|
|
|
describe = tmpDescribe;
|
|
|
|
/**
|
|
|
|
* dir
|
|
|
|
* |- v
|
|
|
|
* |- p
|
|
|
|
* |- p2
|
|
|
|
* |-> subDir
|
2021-04-18 15:48:35 +02:00
|
|
|
* |- pFaceLess
|
2021-01-16 17:59:59 +02:00
|
|
|
* |-> subDir2
|
|
|
|
* |- p4
|
|
|
|
*/
|
2018-01-31 03:01:16 +02:00
|
|
|
|
2021-05-23 22:26:27 +02:00
|
|
|
let dir: DirectoryDTO;
|
|
|
|
let subDir: DirectoryDTO;
|
|
|
|
let subDir2: DirectoryDTO;
|
2021-01-16 17:59:59 +02:00
|
|
|
let v: VideoDTO;
|
|
|
|
let p: PhotoDTO;
|
|
|
|
let p2: PhotoDTO;
|
2021-04-18 15:48:35 +02:00
|
|
|
let pFaceLess: PhotoDTO;
|
2021-01-16 17:59:59 +02:00
|
|
|
let p4: PhotoDTO;
|
2018-01-31 03:01:16 +02:00
|
|
|
|
|
|
|
|
2021-01-16 17:59:59 +02:00
|
|
|
const setUpTestGallery = async (): Promise<void> => {
|
2021-01-17 11:56:33 +02:00
|
|
|
const directory: DirectoryDTO = TestHelper.getDirectoryEntry();
|
2021-05-23 22:26:27 +02:00
|
|
|
subDir = TestHelper.getDirectoryEntry(directory, 'The Phantom Menace');
|
|
|
|
subDir2 = TestHelper.getDirectoryEntry(directory, 'Return of the Jedi');
|
2021-03-28 12:43:13 +02:00
|
|
|
p = TestHelper.getPhotoEntry1(directory);
|
|
|
|
p2 = TestHelper.getPhotoEntry2(directory);
|
|
|
|
p4 = TestHelper.getPhotoEntry4(subDir2);
|
2021-04-18 15:48:35 +02:00
|
|
|
const pFaceLessTmp = TestHelper.getPhotoEntry3(subDir);
|
|
|
|
delete pFaceLessTmp.metadata.faces;
|
2021-03-28 12:43:13 +02:00
|
|
|
v = TestHelper.getVideoEntry1(directory);
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-01 21:48:38 +02:00
|
|
|
dir = await DBTestHelper.persistTestDir(directory);
|
2021-05-23 22:26:27 +02:00
|
|
|
subDir = dir.directories[0];
|
|
|
|
subDir2 = dir.directories[1];
|
2021-04-18 15:48:35 +02:00
|
|
|
p = (dir.media.filter(m => m.name === p.name)[0] as any);
|
|
|
|
p2 = (dir.media.filter(m => m.name === p2.name)[0] as any);
|
|
|
|
v = (dir.media.filter(m => m.name === v.name)[0] as any);
|
|
|
|
p4 = (dir.directories[1].media[0] as any);
|
|
|
|
pFaceLess = (dir.directories[0].media[0] as any);
|
2021-01-16 17:59:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const setUpSqlDB = async () => {
|
|
|
|
await sqlHelper.initDB();
|
|
|
|
await setUpTestGallery();
|
2021-05-23 22:26:27 +02:00
|
|
|
await ObjectManagers.InitSQLManagers();
|
2018-01-31 03:01:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-01-17 11:56:33 +02:00
|
|
|
before(async () => {
|
2021-05-23 22:38:11 +02:00
|
|
|
Config.Client.Search.listDirectories = true;
|
2018-01-31 03:01:16 +02:00
|
|
|
await setUpSqlDB();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-01-27 21:36:42 +02:00
|
|
|
after(async () => {
|
|
|
|
await sqlHelper.clearDB();
|
2021-05-23 22:38:11 +02:00
|
|
|
Config.Client.Search.listDirectories = false;
|
2019-01-27 21:36:42 +02:00
|
|
|
});
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-01-17 11:56:33 +02:00
|
|
|
it('should get autocomplete', async () => {
|
|
|
|
const sm = new SearchManager();
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-01-17 11:56:33 +02: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 17:59:59 +02:00
|
|
|
|
2021-01-17 16:56:15 +02: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 11:56:33 +02:00
|
|
|
new AutoCompleteItem('death star', SearchQueryTypes.keyword)]);
|
|
|
|
|
2021-01-17 16:56:15 +02:00
|
|
|
expect((await sm.autocomplete('wars', SearchQueryTypes.any_text))).to.deep.equalInAnyOrder([
|
|
|
|
new AutoCompleteItem('star wars', SearchQueryTypes.keyword),
|
2021-01-17 11:56:33 +02:00
|
|
|
new AutoCompleteItem('wars dir', SearchQueryTypes.directory)]);
|
|
|
|
|
2021-01-17 16:56:15 +02:00
|
|
|
expect((await sm.autocomplete('arch', SearchQueryTypes.any_text))).eql([
|
|
|
|
new AutoCompleteItem('Research City', SearchQueryTypes.position)]);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
|
|
|
Config.Client.Search.AutoComplete.maxItemsPerCategory = 99999;
|
2021-01-17 16:56:15 +02:00
|
|
|
expect((await sm.autocomplete('wa', SearchQueryTypes.any_text))).to.deep.equalInAnyOrder([
|
2021-01-17 11:56:33 +02:00
|
|
|
new AutoCompleteItem('star wars', SearchQueryTypes.keyword),
|
|
|
|
new AutoCompleteItem('Anakin Skywalker', SearchQueryTypes.person),
|
|
|
|
new AutoCompleteItem('Luke Skywalker', SearchQueryTypes.person),
|
2021-01-17 16:56:15 +02:00
|
|
|
new AutoCompleteItem('wars dir', SearchQueryTypes.directory)]);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
|
|
|
Config.Client.Search.AutoComplete.maxItemsPerCategory = 1;
|
2021-01-17 16:56:15 +02:00
|
|
|
expect((await sm.autocomplete('a', SearchQueryTypes.any_text))).to.deep.equalInAnyOrder([
|
|
|
|
new AutoCompleteItem('Ajan Kloss', SearchQueryTypes.position),
|
|
|
|
new AutoCompleteItem('Amber stone', SearchQueryTypes.caption),
|
2021-01-17 11:56:33 +02:00
|
|
|
new AutoCompleteItem('star wars', SearchQueryTypes.keyword),
|
|
|
|
new AutoCompleteItem('Anakin Skywalker', SearchQueryTypes.person),
|
2021-01-17 16:56:15 +02:00
|
|
|
new AutoCompleteItem('Castilon', SearchQueryTypes.position),
|
|
|
|
new AutoCompleteItem('Devaron', SearchQueryTypes.position),
|
|
|
|
new AutoCompleteItem('The Phantom Menace', SearchQueryTypes.directory)]);
|
2021-01-17 11:56:33 +02:00
|
|
|
Config.Client.Search.AutoComplete.maxItemsPerCategory = 5;
|
|
|
|
|
2021-01-17 16:56:15 +02: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 11:56:33 +02:00
|
|
|
|
2021-01-17 16:56:15 +02:00
|
|
|
expect((await sm.autocomplete(v.name, SearchQueryTypes.any_text))).to.deep.equalInAnyOrder(
|
|
|
|
[new AutoCompleteItem(v.name, SearchQueryTypes.file_name)]);
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-01-17 11:56:33 +02:00
|
|
|
});
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
const searchifyMedia = (m: MediaDTO): MediaDTO => {
|
|
|
|
const tmpM = m.directory.media;
|
|
|
|
const tmpD = m.directory.directories;
|
2021-03-28 12:43:13 +02:00
|
|
|
const tmpP = m.directory.preview;
|
2021-01-16 17:59:59 +02:00
|
|
|
const tmpMT = m.directory.metaFile;
|
|
|
|
delete m.directory.directories;
|
|
|
|
delete m.directory.media;
|
2021-03-28 12:43:13 +02:00
|
|
|
delete m.directory.preview;
|
2021-01-16 17:59:59 +02:00
|
|
|
delete m.directory.metaFile;
|
|
|
|
const ret = Utils.clone(m);
|
|
|
|
if ((ret.metadata as PhotoMetadata).faces && !(ret.metadata as PhotoMetadata).faces.length) {
|
|
|
|
delete (ret.metadata as PhotoMetadata).faces;
|
|
|
|
}
|
|
|
|
m.directory.directories = tmpD;
|
|
|
|
m.directory.media = tmpM;
|
2021-03-28 12:43:13 +02:00
|
|
|
m.directory.preview = tmpP;
|
2021-01-16 17:59:59 +02:00
|
|
|
m.directory.metaFile = tmpMT;
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
2021-05-23 22:26:27 +02:00
|
|
|
const searchifyDir = (d: DirectoryDTO): DirectoryDTO => {
|
|
|
|
const tmpM = d.media;
|
|
|
|
const tmpD = d.directories;
|
|
|
|
const tmpP = d.preview;
|
|
|
|
const tmpMT = d.metaFile;
|
|
|
|
delete d.directories;
|
|
|
|
delete d.media;
|
|
|
|
delete d.preview;
|
|
|
|
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 17:59:59 +02:00
|
|
|
const removeDir = (result: SearchResultDTO) => {
|
|
|
|
result.media = result.media.map(m => searchifyMedia(m));
|
2021-05-23 22:26:27 +02:00
|
|
|
result.directories = result.directories.map(m => searchifyDir(m));
|
2021-01-16 17:59:59 +02:00
|
|
|
return Utils.clone(result);
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('advanced search', async () => {
|
|
|
|
|
|
|
|
it('should AND', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
let query: SearchQueryDTO = {
|
2021-01-16 17:59:59 +02:00
|
|
|
type: SearchQueryTypes.AND,
|
2021-04-18 15:48:35 +02: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 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
|
|
|
query = ({
|
2021-01-16 17:59:59 +02:00
|
|
|
type: SearchQueryTypes.AND,
|
2021-04-18 15:48:35 +02: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 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
// make sure that this shows both photos. We need this the the rest of the tests
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({text: 'a', type: SearchQueryTypes.person} as TextSearch);
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
2021-01-17 00:37:14 +02:00
|
|
|
media: [p, p2, p4],
|
2021-01-16 17:59:59 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-16 17:59:59 +02:00
|
|
|
type: SearchQueryTypes.AND,
|
2021-04-18 15:48:35 +02:00
|
|
|
list: [{
|
2021-01-16 17:59:59 +02:00
|
|
|
type: SearchQueryTypes.AND,
|
2021-04-18 15:48:35 +02: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 17:59:59 +02:00
|
|
|
]
|
2021-04-18 15:48:35 +02:00
|
|
|
} as ANDSearchQuery);
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should OR', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
let query: SearchQueryDTO = {
|
2021-01-16 17:59:59 +02:00
|
|
|
type: SearchQueryTypes.OR,
|
2021-04-18 15:48:35 +02: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 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
|
|
|
query = ({
|
2021-01-16 17:59:59 +02:00
|
|
|
type: SearchQueryTypes.OR,
|
2021-04-18 15:48:35 +02: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 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-16 17:59:59 +02:00
|
|
|
type: SearchQueryTypes.OR,
|
2021-04-18 15:48:35 +02: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 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
// make sure that this shows both photos. We need this the the rest of the tests
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({text: 'a', type: SearchQueryTypes.person} as TextSearch);
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
2021-01-17 00:37:14 +02:00
|
|
|
media: [p, p2, p4],
|
2021-01-16 17:59:59 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-16 17:59:59 +02:00
|
|
|
type: SearchQueryTypes.OR,
|
2021-04-18 15:48:35 +02:00
|
|
|
list: [{
|
2021-01-16 17:59:59 +02:00
|
|
|
type: SearchQueryTypes.OR,
|
2021-04-18 15:48:35 +02: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 17:59:59 +02:00
|
|
|
]
|
2021-04-18 15:48:35 +02:00
|
|
|
} as ORSearchQuery);
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
2021-01-17 00:37:14 +02:00
|
|
|
media: [p, p2, p4],
|
2021-01-16 17:59:59 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-16 17:59:59 +02:00
|
|
|
type: SearchQueryTypes.OR,
|
2021-04-18 15:48:35 +02:00
|
|
|
list: [{
|
2021-01-16 17:59:59 +02:00
|
|
|
type: SearchQueryTypes.OR,
|
2021-04-18 15:48:35 +02: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 17:59:59 +02:00
|
|
|
]
|
2021-04-18 15:48:35 +02:00
|
|
|
} as ORSearchQuery);
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [p, p2, pFaceLess],
|
2021-01-16 17:59:59 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2021-01-17 00:37:14 +02:00
|
|
|
|
|
|
|
it('should minimum of', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
let query: SomeOfSearchQuery = {
|
2021-01-17 00:37:14 +02:00
|
|
|
type: SearchQueryTypes.SOME_OF,
|
2021-04-18 15:48:35 +02:00
|
|
|
list: [{text: 'jpg', type: SearchQueryTypes.file_name} as TextSearch,
|
|
|
|
{text: 'mp4', type: SearchQueryTypes.file_name} as TextSearch]
|
|
|
|
} as SomeOfSearchQuery;
|
2021-01-17 00:37:14 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-17 00:37:14 +02:00
|
|
|
directories: [],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [p, p2, pFaceLess, p4, v],
|
2021-01-17 00:37:14 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 00:37:14 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-17 00:37:14 +02:00
|
|
|
type: SearchQueryTypes.SOME_OF,
|
2021-04-18 15:48:35 +02: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 00:37:14 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-17 00:37:14 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2, p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 00:37:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
query.min = 2;
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-17 00:37:14 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2, p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 00:37:14 +02:00
|
|
|
|
|
|
|
query.min = 3;
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-17 00:37:14 +02:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 00:37:14 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-17 00:37:14 +02:00
|
|
|
type: SearchQueryTypes.SOME_OF,
|
|
|
|
min: 3,
|
2021-04-18 15:48:35 +02: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 00:37:14 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-17 00:37:14 +02:00
|
|
|
directories: [],
|
2021-01-17 11:56:33 +02:00
|
|
|
media: [p, p2],
|
2021-01-17 00:37:14 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 00:37:14 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2021-01-16 17:59:59 +02:00
|
|
|
describe('should search text', async () => {
|
|
|
|
it('as any', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 15:48:35 +02: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 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [p, p2, pFaceLess, v, p4],
|
2021-01-16 17:59:59 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-23 22:26:27 +02:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2018-01-31 03:01:16 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({text: 'sw', negate: true, type: SearchQueryTypes.any_text} as TextSearch);
|
2021-01-17 00:37:14 +02:00
|
|
|
|
2021-05-23 22:26:27 +02:00
|
|
|
expect(removeDir(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-05-23 22:26:27 +02:00
|
|
|
directories: [dir, subDir, subDir2],
|
2021-01-17 00:37:14 +02:00
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-23 22:26:27 +02:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-17 00:37:14 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({text: 'Boba', type: SearchQueryTypes.any_text} as TextSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-23 22:26:27 +02:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({text: 'Boba', negate: true, type: SearchQueryTypes.any_text} as TextSearch);
|
2021-05-23 22:26:27 +02:00
|
|
|
expect(removeDir(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-05-23 22:26:27 +02:00
|
|
|
directories: [dir, subDir, subDir2],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [p2, pFaceLess, p4],
|
2021-01-17 00:37:14 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-23 22:26:27 +02:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-17 00:37:14 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({text: 'Boba', negate: true, type: SearchQueryTypes.any_text} as TextSearch);
|
2021-01-17 00:37:14 +02:00
|
|
|
// all should have faces
|
2021-01-17 11:56:33 +02:00
|
|
|
const sRet = await sm.search(query);
|
2021-04-18 15:48:35 +02:00
|
|
|
for (const item of sRet.media) {
|
|
|
|
if (item.id === pFaceLess.id) {
|
2021-01-17 00:37:14 +02:00
|
|
|
continue;
|
|
|
|
}
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-04-18 15:48:35 +02: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 00:37:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-16 17:59:59 +02:00
|
|
|
text: 'Boba',
|
|
|
|
type: SearchQueryTypes.any_text,
|
2021-01-31 13:22:56 +02:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-23 22:26:27 +02:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-16 17:59:59 +02:00
|
|
|
text: 'Boba Fett',
|
|
|
|
type: SearchQueryTypes.any_text,
|
2021-01-31 13:22:56 +02:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-23 22:26:27 +02:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('as position', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
const query = {text: 'Tatooine', type: SearchQueryTypes.position} as TextSearch;
|
2021-01-17 11:56:33 +02:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('as keyword', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
let query = {
|
2021-01-16 17:59:59 +02:00
|
|
|
text: 'kie',
|
|
|
|
type: SearchQueryTypes.keyword
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch;
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [p2, pFaceLess],
|
2021-01-16 17:59:59 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-16 17:59:59 +02:00
|
|
|
text: 'wa',
|
|
|
|
type: SearchQueryTypes.keyword
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [p, p2, pFaceLess, p4],
|
2021-01-16 17:59:59 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-16 17:59:59 +02:00
|
|
|
text: 'han',
|
|
|
|
type: SearchQueryTypes.keyword
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-17 11:56:33 +02:00
|
|
|
text: 'star wars',
|
2021-01-31 13:22:56 +02:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match,
|
2021-01-17 11:56:33 +02:00
|
|
|
type: SearchQueryTypes.keyword
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
|
|
|
directories: [],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [p, p2, pFaceLess, p4],
|
2021-01-17 11:56:33 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-17 11:56:33 +02:00
|
|
|
text: 'wookiees',
|
2021-01-31 13:22:56 +02:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match,
|
2021-01-17 11:56:33 +02:00
|
|
|
type: SearchQueryTypes.keyword
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
|
|
|
directories: [],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [pFaceLess],
|
2021-01-17 11:56:33 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-01-16 17:59:59 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('as caption', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
const query = {
|
2021-01-16 17:59:59 +02:00
|
|
|
text: 'han',
|
|
|
|
type: SearchQueryTypes.caption
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch;
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('as file_name', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
let query = {
|
2021-01-16 17:59:59 +02:00
|
|
|
text: 'sw',
|
|
|
|
type: SearchQueryTypes.file_name
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch;
|
2021-01-17 11:56:33 +02:00
|
|
|
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [p, p2, pFaceLess, v, p4],
|
2021-01-16 17:59:59 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-17 11:56:33 +02:00
|
|
|
text: 'sw4',
|
|
|
|
type: SearchQueryTypes.file_name
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search({
|
2021-01-16 17:59:59 +02:00
|
|
|
text: 'sw4',
|
|
|
|
type: SearchQueryTypes.file_name
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('as directory', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
let query = {
|
2021-01-16 17:59:59 +02:00
|
|
|
text: 'of the J',
|
|
|
|
type: SearchQueryTypes.directory
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch;
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-05-23 22:26:27 +02:00
|
|
|
expect(removeDir(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-05-23 22:26:27 +02:00
|
|
|
directories: [subDir2],
|
2021-01-16 17:59:59 +02:00
|
|
|
media: [p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-23 22:26:27 +02:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-16 17:59:59 +02:00
|
|
|
text: 'wars dir',
|
|
|
|
type: SearchQueryTypes.directory
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-05-23 22:26:27 +02:00
|
|
|
expect(removeDir(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-05-23 22:26:27 +02:00
|
|
|
directories: [dir, subDir, subDir2],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [p, p2, v, pFaceLess, p4],
|
2021-01-16 17:59:59 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-23 22:26:27 +02:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-17 11:56:33 +02:00
|
|
|
text: '/wars dir',
|
2021-01-31 13:22:56 +02:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match,
|
2021-01-17 11:56:33 +02:00
|
|
|
type: SearchQueryTypes.directory
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
|
|
|
|
2021-05-23 22:26:27 +02:00
|
|
|
expect(removeDir(await sm.search({
|
2021-01-16 17:59:59 +02:00
|
|
|
text: '/wars dir',
|
2021-01-31 13:22:56 +02:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match,
|
2021-01-16 17:59:59 +02:00
|
|
|
type: SearchQueryTypes.directory
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-05-23 22:26:27 +02:00
|
|
|
directories: [dir],
|
2021-01-16 17:59:59 +02:00
|
|
|
media: [p, p2, v],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-23 22:26:27 +02:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-16 17:59:59 +02:00
|
|
|
text: '/wars dir/Return of the Jedi',
|
2021-05-30 17:26:07 +02:00
|
|
|
// matchType: TextSearchQueryMatchTypes.like,
|
2021-01-16 17:59:59 +02:00
|
|
|
type: SearchQueryTypes.directory
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-05-23 22:26:27 +02:00
|
|
|
expect(removeDir(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-05-23 22:26:27 +02:00
|
|
|
directories: [subDir2],
|
2021-01-16 17:59:59 +02:00
|
|
|
media: [p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-23 22:26:27 +02:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-16 17:59:59 +02:00
|
|
|
text: '/wars dir/Return of the Jedi',
|
2021-01-31 13:22:56 +02:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match,
|
2021-01-16 17:59:59 +02:00
|
|
|
type: SearchQueryTypes.directory
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-05-23 22:26:27 +02:00
|
|
|
expect(removeDir(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-05-23 22:26:27 +02:00
|
|
|
directories: [subDir2],
|
2021-01-16 17:59:59 +02:00
|
|
|
media: [p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-05-23 22:26:27 +02:00
|
|
|
} as SearchResultDTO), JSON.stringify(query));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('as person', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
let query = {
|
2021-01-16 17:59:59 +02:00
|
|
|
text: 'Boba',
|
|
|
|
type: SearchQueryTypes.person
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch;
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-16 17:59:59 +02:00
|
|
|
text: 'Boba',
|
|
|
|
type: SearchQueryTypes.person,
|
2021-01-31 13:22:56 +02:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-17 11:56:33 +02:00
|
|
|
text: 'Boba Fett',
|
|
|
|
type: SearchQueryTypes.person,
|
2021-01-31 13:22:56 +02:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
expect(Utils.clone(await sm.search({
|
2021-01-16 17:59:59 +02:00
|
|
|
text: 'Boba Fett',
|
|
|
|
type: SearchQueryTypes.person,
|
2021-01-31 13:22:56 +02:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch))).to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should search date', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
let query: any = {value: 0, type: SearchQueryTypes.to_date} as ToDateSearch;
|
2021-01-17 11:56:33 +02:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-03-14 11:56:59 +02:00
|
|
|
value: p.metadata.creationDate, type: SearchQueryTypes.from_date
|
2021-04-18 15:48:35 +02:00
|
|
|
} as FromDateSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
2021-03-14 11:56:59 +02:00
|
|
|
media: [p, v],
|
2021-01-16 17:59:59 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-02-14 13:57:05 +02:00
|
|
|
value: p.metadata.creationDate,
|
2021-01-17 00:37:14 +02:00
|
|
|
negate: true,
|
2021-02-14 13:57:05 +02:00
|
|
|
type: SearchQueryTypes.from_date
|
2021-04-18 15:48:35 +02:00
|
|
|
} as FromDateSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-17 00:37:14 +02:00
|
|
|
directories: [],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [p2, pFaceLess, p4],
|
2021-01-17 00:37:14 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 00:37:14 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-02-14 13:57:05 +02:00
|
|
|
value: p.metadata.creationDate + 1000000000,
|
|
|
|
type: SearchQueryTypes.to_date
|
2021-04-18 15:48:35 +02:00
|
|
|
} as ToDateSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-02-14 13:57:05 +02:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [p, p2, pFaceLess, v, p4],
|
2021-01-16 17:59:59 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should search rating', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
let query: MinRatingSearch | MaxRatingSearch = {value: 0, type: SearchQueryTypes.max_rating} as MaxRatingSearch;
|
2021-01-17 11:56:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({value: 5, type: SearchQueryTypes.max_rating} as MaxRatingSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [p, p2, pFaceLess],
|
2021-01-16 17:59:59 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({value: 5, negate: true, type: SearchQueryTypes.max_rating} as MaxRatingSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-17 00:37:14 +02:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 00:37:14 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({value: 2, type: SearchQueryTypes.min_rating} as MinRatingSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [p2, pFaceLess],
|
2021-01-16 17:59:59 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({value: 2, negate: true, type: SearchQueryTypes.min_rating} as MinRatingSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-17 00:37:14 +02:00
|
|
|
directories: [],
|
2021-03-14 11:56:59 +02:00
|
|
|
media: [p],
|
2021-01-17 00:37:14 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should search resolution', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-02-14 13:57:05 +02:00
|
|
|
let query: MinResolutionSearch | MaxResolutionSearch =
|
2021-04-18 15:48:35 +02:00
|
|
|
{value: 0, type: SearchQueryTypes.max_resolution} as MaxResolutionSearch;
|
2021-02-14 13:57:05 +02:00
|
|
|
|
2021-01-17 11:56:33 +02:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({value: 1, type: SearchQueryTypes.max_resolution} as MaxResolutionSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p, v],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({value: 3, type: SearchQueryTypes.min_resolution} as MinResolutionSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
2021-03-14 11:56:59 +02:00
|
|
|
media: [p4],
|
2021-01-16 17:59:59 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-03-14 11:56:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({value: 3, negate: true, type: SearchQueryTypes.min_resolution} as MinResolutionSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-17 00:37:14 +02:00
|
|
|
directories: [],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [p, p2, pFaceLess, v],
|
2021-01-17 00:37:14 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-17 00:37:14 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({value: 3, negate: true, type: SearchQueryTypes.max_resolution} as MaxResolutionSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should search orientation', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
let query = {
|
2021-01-17 00:37:14 +02:00
|
|
|
landscape: false,
|
2021-01-16 17:59:59 +02:00
|
|
|
type: SearchQueryTypes.orientation
|
2021-04-18 15:48:35 +02:00
|
|
|
} as OrientationSearch;
|
2021-01-17 11:56:33 +02:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2, p4, v],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-17 00:37:14 +02:00
|
|
|
landscape: true,
|
2021-01-16 17:59:59 +02:00
|
|
|
type: SearchQueryTypes.orientation
|
2021-04-18 15:48:35 +02:00
|
|
|
} as OrientationSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [p, pFaceLess, v],
|
2021-01-16 17:59:59 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2021-04-06 11:32:31 +02:00
|
|
|
it('should search distance', async () => {
|
2021-01-16 17:59:59 +02:00
|
|
|
ObjectManagers.getInstance().LocationManager = new LocationManager();
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
|
|
|
ObjectManagers.getInstance().LocationManager.getGPSData = async (): Promise<GPSMetadata> => {
|
|
|
|
return {
|
|
|
|
longitude: 10,
|
|
|
|
latitude: 10,
|
|
|
|
altitude: 0
|
|
|
|
};
|
|
|
|
};
|
2021-01-17 11:56:33 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
let query = {
|
2021-01-16 17:59:59 +02:00
|
|
|
from: {text: 'Tatooine'},
|
|
|
|
distance: 1,
|
|
|
|
type: SearchQueryTypes.distance
|
2021-04-18 15:48:35 +02:00
|
|
|
} as DistanceSearch;
|
2021-01-17 11:56:33 +02:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-16 17:59:59 +02:00
|
|
|
from: {GPSData: {latitude: 0, longitude: 0}},
|
|
|
|
distance: 112 * 10, // number of km per degree = ~111km
|
|
|
|
type: SearchQueryTypes.distance
|
2021-04-18 15:48:35 +02:00
|
|
|
} as DistanceSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-17 00:37:14 +02:00
|
|
|
from: {GPSData: {latitude: 0, longitude: 0}},
|
|
|
|
distance: 112 * 10, // number of km per degree = ~111km
|
|
|
|
negate: true,
|
|
|
|
type: SearchQueryTypes.distance
|
2021-04-18 15:48:35 +02:00
|
|
|
} as DistanceSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-17 00:37:14 +02:00
|
|
|
directories: [],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [pFaceLess, p4],
|
2021-01-17 00:37:14 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
|
|
|
query = ({
|
2021-01-16 17:59:59 +02:00
|
|
|
from: {GPSData: {latitude: 10, longitude: 10}},
|
|
|
|
distance: 1,
|
|
|
|
type: SearchQueryTypes.distance
|
2021-04-18 15:48:35 +02:00
|
|
|
} as DistanceSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-16 17:59:59 +02:00
|
|
|
from: {GPSData: {latitude: 10, longitude: 10}},
|
|
|
|
distance: 112 * 5, // number of km per degree = ~111km
|
|
|
|
type: SearchQueryTypes.distance
|
2021-04-18 15:48:35 +02:00
|
|
|
} as DistanceSearch);
|
2021-01-17 11:56:33 +02:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-04-18 15:48:35 +02:00
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
2021-01-17 11:56:33 +02:00
|
|
|
searchQuery: query,
|
2021-01-16 17:59:59 +02:00
|
|
|
directories: [],
|
2021-04-18 15:48:35 +02:00
|
|
|
media: [p, pFaceLess, p4],
|
2021-01-16 17:59:59 +02:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
2021-04-18 15:48:35 +02:00
|
|
|
} as SearchResultDTO));
|
2021-01-16 17:59:59 +02:00
|
|
|
|
|
|
|
});
|
2018-01-31 03:01:16 +02:00
|
|
|
|
2021-05-31 16:44:37 +02:00
|
|
|
/**
|
|
|
|
* flattenSameOfQueries converts converts some-of querries to AND and OR queries
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
// its an or
|
|
|
|
const lengths = (q as SearchListQuery).list.map(l => shortestDepth(l)).sort();
|
|
|
|
|
|
|
|
if (lengths[0] !== lengths[lengths.length - 1]) {
|
|
|
|
for (const l of (q as SearchListQuery).list) {
|
|
|
|
console.log(shortestDepth(l));
|
|
|
|
console.log(parser.stringify(l));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// tslint:disable-next-line:prefer-for-of
|
|
|
|
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 17:26:07 +02: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-23 22:26:27 +02:00
|
|
|
it('search result should return directory', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-05-30 17:26:07 +02:00
|
|
|
const query = {
|
2021-05-23 22:26:27 +02:00
|
|
|
text: subDir.name,
|
|
|
|
type: SearchQueryTypes.any_text
|
|
|
|
} as TextSearch;
|
|
|
|
expect(removeDir(await sm.search(query)))
|
|
|
|
.to.deep.equalInAnyOrder(removeDir({
|
|
|
|
searchQuery: query,
|
|
|
|
directories: [subDir],
|
|
|
|
media: [pFaceLess],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
} as SearchResultDTO));
|
|
|
|
});
|
|
|
|
|
2018-01-31 03:01:16 +02:00
|
|
|
});
|
2021-01-16 17:59:59 +02:00
|
|
|
|
2021-01-17 16:56:15 +02:00
|
|
|
|
|
|
|
it('should get random photo', async () => {
|
2021-01-17 11:56:33 +02:00
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
let query = {
|
2021-01-17 16:56:15 +02:00
|
|
|
text: 'xyz',
|
|
|
|
type: SearchQueryTypes.keyword
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch;
|
2021-02-14 13:57:05 +02:00
|
|
|
|
|
|
|
// tslint:disable-next-line
|
2021-01-17 16:56:15 +02:00
|
|
|
expect(await sm.getRandomPhoto(query)).to.not.exist;
|
2018-01-31 03:01:16 +02:00
|
|
|
|
2021-04-18 15:48:35 +02:00
|
|
|
query = ({
|
2021-01-17 16:56:15 +02:00
|
|
|
text: 'wookiees',
|
2021-01-31 13:22:56 +02:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match,
|
2021-01-17 16:56:15 +02:00
|
|
|
type: SearchQueryTypes.keyword
|
2021-04-18 15:48:35 +02:00
|
|
|
} as TextSearch);
|
|
|
|
expect(Utils.clone(await sm.getRandomPhoto(query))).to.deep.equalInAnyOrder(searchifyMedia(pFaceLess));
|
2021-01-17 16:56:15 +02:00
|
|
|
});
|
2018-01-31 03:01:16 +02:00
|
|
|
|
|
|
|
});
|