2021-01-16 23:59:59 +08:00
|
|
|
import {LocationManager} from '../../../../../src/backend/model/database/LocationManager';
|
2019-12-15 00:27:01 +08:00
|
|
|
import {SearchManager} from '../../../../../src/backend/model/database/sql/SearchManager';
|
2019-12-10 17:44:35 +08:00
|
|
|
import {SearchResultDTO} from '../../../../../src/common/entities/SearchResultDTO';
|
|
|
|
import {Utils} from '../../../../../src/common/Utils';
|
2019-01-28 03:36:42 +08:00
|
|
|
import {SQLTestHelper} from '../../../SQLTestHelper';
|
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,
|
|
|
|
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';
|
|
|
|
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 17:56:33 +08:00
|
|
|
import {AutoCompleteItem} from '../../../../../src/common/entities/AutoCompleteItem';
|
|
|
|
import {Config} from '../../../../../src/common/config/private/Config';
|
2021-01-16 23:59:59 +08:00
|
|
|
|
|
|
|
const deepEqualInAnyOrder = require('deep-equal-in-any-order');
|
|
|
|
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;
|
|
|
|
describe = SQLTestHelper.describe; // fake it os IDE plays nicely (recognize the test)
|
|
|
|
|
|
|
|
|
|
|
|
class IndexingManagerTest extends IndexingManager {
|
|
|
|
|
|
|
|
public async saveToDB(scannedDirectory: DirectoryDTO): Promise<void> {
|
|
|
|
return super.saveToDB(scannedDirectory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 09:01:16 +08:00
|
|
|
|
2019-01-28 03:36:42 +08:00
|
|
|
describe('SearchManager', (sqlHelper: SQLTestHelper) => {
|
2021-01-16 23:59:59 +08:00
|
|
|
describe = tmpDescribe;
|
|
|
|
let dir: DirectoryDTO;
|
|
|
|
/**
|
|
|
|
* dir
|
|
|
|
* |- v
|
|
|
|
* |- p
|
|
|
|
* |- p2
|
|
|
|
* |-> subDir
|
|
|
|
* |- p_faceLess
|
|
|
|
* |-> subDir2
|
|
|
|
* |- p4
|
|
|
|
*/
|
2018-01-31 09:01:16 +08:00
|
|
|
|
2021-01-16 23:59:59 +08:00
|
|
|
let v: VideoDTO;
|
|
|
|
let p: PhotoDTO;
|
|
|
|
let p2: PhotoDTO;
|
|
|
|
let p_faceLess: PhotoDTO;
|
|
|
|
let p4: PhotoDTO;
|
2018-01-31 09:01:16 +08:00
|
|
|
|
|
|
|
|
2021-01-16 23:59:59 +08:00
|
|
|
const setUpTestGallery = async (): Promise<void> => {
|
2021-01-17 17:56:33 +08:00
|
|
|
const directory: DirectoryDTO = TestHelper.getDirectoryEntry();
|
2021-01-16 23:59:59 +08:00
|
|
|
const subDir = TestHelper.getDirectoryEntry(directory, 'The Phantom Menace');
|
|
|
|
const subDir2 = TestHelper.getDirectoryEntry(directory, 'Return of the Jedi');
|
2021-03-28 18:43:13 +08:00
|
|
|
p = TestHelper.getPhotoEntry1(directory);
|
|
|
|
p2 = TestHelper.getPhotoEntry2(directory);
|
|
|
|
p4 = TestHelper.getPhotoEntry4(subDir2);
|
2021-01-16 23:59:59 +08:00
|
|
|
const pFaceLess = TestHelper.getPhotoEntry3(subDir);
|
|
|
|
delete pFaceLess.metadata.faces;
|
2021-03-28 18:43:13 +08:00
|
|
|
v = TestHelper.getVideoEntry1(directory);
|
2021-01-16 23:59:59 +08:00
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
dir = await SQLTestHelper.persistTestDir(directory);
|
2021-03-28 18:43:13 +08:00
|
|
|
p = <any>dir.media.filter(m => m.name === p.name)[0];
|
|
|
|
p2 = <any>dir.media.filter(m => m.name === p2.name)[0];
|
|
|
|
v = <any>dir.media.filter(m => m.name === v.name)[0];
|
2021-01-16 23:59:59 +08:00
|
|
|
p4 = <any>dir.directories[1].media[0];
|
|
|
|
p_faceLess = <any>dir.directories[0].media[0];
|
|
|
|
};
|
|
|
|
|
|
|
|
const setUpSqlDB = async () => {
|
|
|
|
await sqlHelper.initDB();
|
|
|
|
await setUpTestGallery();
|
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();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-01-28 03:36:42 +08:00
|
|
|
after(async () => {
|
|
|
|
await sqlHelper.clearDB();
|
|
|
|
});
|
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
|
|
|
|
|
|
|
Config.Client.Search.AutoComplete.maxItemsPerCategory = 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
|
|
|
|
|
|
|
Config.Client.Search.AutoComplete.maxItemsPerCategory = 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),
|
|
|
|
new AutoCompleteItem('Amber stone', SearchQueryTypes.caption),
|
2021-01-17 17:56:33 +08:00
|
|
|
new AutoCompleteItem('star wars', SearchQueryTypes.keyword),
|
|
|
|
new AutoCompleteItem('Anakin Skywalker', SearchQueryTypes.person),
|
2021-01-17 22:56:15 +08:00
|
|
|
new AutoCompleteItem('Castilon', SearchQueryTypes.position),
|
|
|
|
new AutoCompleteItem('Devaron', SearchQueryTypes.position),
|
|
|
|
new AutoCompleteItem('The Phantom Menace', SearchQueryTypes.directory)]);
|
2021-01-17 17:56:33 +08:00
|
|
|
Config.Client.Search.AutoComplete.maxItemsPerCategory = 5;
|
|
|
|
|
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
|
|
|
|
|
|
|
const searchifyMedia = (m: MediaDTO): MediaDTO => {
|
|
|
|
const tmpM = m.directory.media;
|
|
|
|
const tmpD = m.directory.directories;
|
2021-03-28 18:43:13 +08:00
|
|
|
const tmpP = m.directory.preview;
|
2021-01-16 23:59:59 +08:00
|
|
|
const tmpMT = m.directory.metaFile;
|
|
|
|
delete m.directory.directories;
|
|
|
|
delete m.directory.media;
|
2021-03-28 18:43:13 +08:00
|
|
|
delete m.directory.preview;
|
2021-01-16 23:59:59 +08: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 18:43:13 +08:00
|
|
|
m.directory.preview = tmpP;
|
2021-01-16 23:59:59 +08:00
|
|
|
m.directory.metaFile = tmpMT;
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
const removeDir = (result: SearchResultDTO) => {
|
|
|
|
result.media = result.media.map(m => searchifyMedia(m));
|
|
|
|
return Utils.clone(result);
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('advanced search', async () => {
|
|
|
|
|
|
|
|
it('should AND', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
|
|
|
let query: SearchQueryDTO = <ANDSearchQuery>{
|
|
|
|
type: SearchQueryTypes.AND,
|
|
|
|
list: [<TextSearch>{text: p.metadata.faces[0].name, type: SearchQueryTypes.person},
|
|
|
|
<TextSearch>{text: p2.metadata.caption, type: SearchQueryTypes.caption}]
|
|
|
|
};
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
query = <ANDSearchQuery>{
|
|
|
|
type: SearchQueryTypes.AND,
|
|
|
|
list: [<TextSearch>{text: p.metadata.faces[0].name, type: SearchQueryTypes.person},
|
|
|
|
<TextSearch>{text: p.metadata.caption, type: SearchQueryTypes.caption}]
|
|
|
|
};
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(await sm.search(query)).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
// make sure that this shows both photos. We need this the the rest of the tests
|
|
|
|
query = <TextSearch>{text: 'a', type: SearchQueryTypes.person};
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
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
|
|
|
|
}));
|
|
|
|
|
|
|
|
query = <ANDSearchQuery>{
|
|
|
|
type: SearchQueryTypes.AND,
|
|
|
|
list: [<ANDSearchQuery>{
|
|
|
|
type: SearchQueryTypes.AND,
|
|
|
|
list: [<TextSearch>{text: 'a', type: SearchQueryTypes.person},
|
|
|
|
<TextSearch>{text: p.metadata.keywords[0], type: SearchQueryTypes.keyword}]
|
|
|
|
},
|
|
|
|
<TextSearch>{text: p.metadata.caption, type: SearchQueryTypes.caption}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should OR', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
|
|
|
let query: SearchQueryDTO = <ORSearchQuery>{
|
|
|
|
type: SearchQueryTypes.OR,
|
|
|
|
list: [<TextSearch>{text: 'Not a person', type: SearchQueryTypes.person},
|
|
|
|
<TextSearch>{text: 'Not a caption', type: SearchQueryTypes.caption}]
|
|
|
|
};
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
query = <ORSearchQuery>{
|
|
|
|
type: SearchQueryTypes.OR,
|
|
|
|
list: [<TextSearch>{text: p.metadata.faces[0].name, type: SearchQueryTypes.person},
|
|
|
|
<TextSearch>{text: p2.metadata.caption, type: SearchQueryTypes.caption}]
|
|
|
|
};
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
query = <ORSearchQuery>{
|
|
|
|
type: SearchQueryTypes.OR,
|
|
|
|
list: [<TextSearch>{text: p.metadata.faces[0].name, type: SearchQueryTypes.person},
|
|
|
|
<TextSearch>{text: p.metadata.caption, type: SearchQueryTypes.caption}]
|
|
|
|
};
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
// make sure that this shows both photos. We need this the the rest of the tests
|
|
|
|
query = <TextSearch>{text: 'a', type: SearchQueryTypes.person};
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
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
|
|
|
|
}));
|
|
|
|
|
|
|
|
query = <ORSearchQuery>{
|
|
|
|
type: SearchQueryTypes.OR,
|
|
|
|
list: [<ORSearchQuery>{
|
|
|
|
type: SearchQueryTypes.OR,
|
|
|
|
list: [<TextSearch>{text: 'a', type: SearchQueryTypes.person},
|
|
|
|
<TextSearch>{text: p.metadata.keywords[0], type: SearchQueryTypes.keyword}]
|
|
|
|
},
|
|
|
|
<TextSearch>{text: p.metadata.caption, type: SearchQueryTypes.caption}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
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
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
query = <ORSearchQuery>{
|
|
|
|
type: SearchQueryTypes.OR,
|
|
|
|
list: [<ORSearchQuery>{
|
|
|
|
type: SearchQueryTypes.OR,
|
|
|
|
list: [<TextSearch>{text: p.metadata.keywords[0], type: SearchQueryTypes.keyword},
|
|
|
|
<TextSearch>{text: p2.metadata.keywords[0], type: SearchQueryTypes.keyword}]
|
|
|
|
},
|
|
|
|
<TextSearch>{text: p_faceLess.metadata.caption, type: SearchQueryTypes.caption}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2, p_faceLess],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2021-01-17 06:37:14 +08:00
|
|
|
|
|
|
|
it('should minimum of', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
|
|
|
let query: SomeOfSearchQuery = <SomeOfSearchQuery>{
|
|
|
|
type: SearchQueryTypes.SOME_OF,
|
|
|
|
list: [<TextSearch>{text: 'jpg', type: SearchQueryTypes.file_name},
|
|
|
|
<TextSearch>{text: 'mp4', type: SearchQueryTypes.file_name}]
|
|
|
|
};
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2, p_faceLess, p4, v],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
query = <SomeOfSearchQuery>{
|
|
|
|
type: SearchQueryTypes.SOME_OF,
|
|
|
|
list: [<TextSearch>{text: 'R2', type: SearchQueryTypes.person},
|
|
|
|
<TextSearch>{text: 'Anakin', type: SearchQueryTypes.person},
|
|
|
|
<TextSearch>{text: 'Luke', type: SearchQueryTypes.person}]
|
|
|
|
};
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2, p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
query.min = 2;
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2, p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
query.min = 3;
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
query = <SomeOfSearchQuery>{
|
|
|
|
type: SearchQueryTypes.SOME_OF,
|
|
|
|
min: 3,
|
|
|
|
list: [<TextSearch>{text: 'sw', type: SearchQueryTypes.file_name},
|
|
|
|
<TextSearch>{text: 'R2', type: SearchQueryTypes.person},
|
|
|
|
<TextSearch>{text: 'Kamino', type: SearchQueryTypes.position},
|
|
|
|
<TextSearch>{text: 'Han', type: SearchQueryTypes.person}]
|
|
|
|
};
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
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-01-16 23:59:59 +08:00
|
|
|
describe('should search text', async () => {
|
|
|
|
it('as any', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
let query = <TextSearch>{text: 'sw', type: SearchQueryTypes.any_text};
|
|
|
|
expect(Utils.clone(await sm.search(<TextSearch>{text: 'sw', type: SearchQueryTypes.any_text})))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2, p_faceLess, v, p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
2018-01-31 09:01:16 +08:00
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
query = <TextSearch>{text: 'sw', negate: true, type: SearchQueryTypes.any_text};
|
2021-01-17 06:37:14 +08:00
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-17 06:37:14 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
query = <TextSearch>{text: 'Boba', type: SearchQueryTypes.any_text};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
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-01-17 17:56:33 +08:00
|
|
|
query = <TextSearch>{text: 'Boba', negate: true, type: SearchQueryTypes.any_text};
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-17 06:37:14 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p2, p_faceLess, p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
query = <TextSearch>{text: 'Boba', negate: true, type: SearchQueryTypes.any_text};
|
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-01-17 06:37:14 +08:00
|
|
|
for (let i = 0; i < sRet.media.length; ++i) {
|
|
|
|
if (sRet.media[i].id === p_faceLess.id) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-01-17 17:56:33 +08:00
|
|
|
|
2021-01-17 06:37:14 +08:00
|
|
|
expect((<PhotoDTO>sRet.media[i]).metadata.faces).to.be.not.an('undefined');
|
|
|
|
expect((<PhotoDTO>sRet.media[i]).metadata.faces).to.be.lengthOf.above(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
query = <TextSearch>{
|
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-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
query = <TextSearch>{
|
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-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('as position', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
const query = <TextSearch>{text: 'Tatooine', type: SearchQueryTypes.position};
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('as keyword', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
let query = <TextSearch>{
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'kie',
|
|
|
|
type: SearchQueryTypes.keyword
|
2021-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p2, p_faceLess],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
query = <TextSearch>{
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'wa',
|
|
|
|
type: SearchQueryTypes.keyword
|
2021-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2, p_faceLess, p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
query = <TextSearch>{
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'han',
|
|
|
|
type: SearchQueryTypes.keyword
|
2021-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
query = <TextSearch>{
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
|
|
|
directories: [],
|
|
|
|
media: [p, p2, p_faceLess, p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
query = <TextSearch>{
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
|
|
|
directories: [],
|
|
|
|
media: [p_faceLess],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-01-16 23:59:59 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('as caption', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
const query = <TextSearch>{
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'han',
|
|
|
|
type: SearchQueryTypes.caption
|
2021-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('as file_name', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
let query = <TextSearch>{
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'sw',
|
|
|
|
type: SearchQueryTypes.file_name
|
2021-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2, p_faceLess, v, p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
query = <TextSearch>{
|
|
|
|
text: 'sw4',
|
|
|
|
type: SearchQueryTypes.file_name
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(<TextSearch>{
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'sw4',
|
|
|
|
type: SearchQueryTypes.file_name
|
|
|
|
}))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('as directory', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
let query = <TextSearch>{
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'of the J',
|
|
|
|
type: SearchQueryTypes.directory
|
2021-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
query = <TextSearch>{
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'wars dir',
|
|
|
|
type: SearchQueryTypes.directory
|
2021-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2, v, p_faceLess, p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
query = <TextSearch>{
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(<TextSearch>{
|
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
|
|
|
|
}))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2, v],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
query = <TextSearch>{
|
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-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
query = <TextSearch>{
|
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-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('as person', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
let query = <TextSearch>{
|
2021-01-16 23:59:59 +08:00
|
|
|
text: 'Boba',
|
|
|
|
type: SearchQueryTypes.person
|
2021-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
query = <TextSearch>{
|
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-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
query = <TextSearch>{
|
|
|
|
text: 'Boba Fett',
|
|
|
|
type: SearchQueryTypes.person,
|
2021-01-31 19:22:56 +08:00
|
|
|
matchType: TextSearchQueryMatchTypes.exact_match
|
2021-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(<TextSearch>{
|
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-01-16 23:59:59 +08:00
|
|
|
}))).to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should search date', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-03-14 17:56:59 +08:00
|
|
|
let query: any = <ToDateSearch>{value: 0, type: SearchQueryTypes.to_date};
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-03-14 17:56:59 +08:00
|
|
|
query = <FromDateSearch>{
|
|
|
|
value: p.metadata.creationDate, type: SearchQueryTypes.from_date
|
2021-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
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-02-14 19:57:05 +08:00
|
|
|
query = <FromDateSearch>{
|
|
|
|
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-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-17 06:37:14 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
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: [p2, p_faceLess, p4],
|
2021-01-17 06:37:14 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-02-14 19:57:05 +08:00
|
|
|
query = <ToDateSearch>{
|
|
|
|
value: p.metadata.creationDate + 1000000000,
|
|
|
|
type: SearchQueryTypes.to_date
|
2021-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
2021-02-14 19:57:05 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2, p_faceLess, v, p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should search rating', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-03-14 17:56:59 +08:00
|
|
|
let query: MinRatingSearch | MaxRatingSearch = <MaxRatingSearch>{value: 0, type: SearchQueryTypes.max_rating};
|
2021-01-17 17:56:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-02-14 19:57:05 +08:00
|
|
|
query = <MaxRatingSearch>{value: 5, type: SearchQueryTypes.max_rating};
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2, p_faceLess],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-02-14 19:57:05 +08:00
|
|
|
query = <MaxRatingSearch>{value: 5, negate: true, type: SearchQueryTypes.max_rating};
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-17 06:37:14 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-02-14 19:57:05 +08:00
|
|
|
query = <MinRatingSearch>{value: 2, type: SearchQueryTypes.min_rating};
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
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: [p2, p_faceLess],
|
2021-01-16 23:59:59 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-02-14 19:57:05 +08:00
|
|
|
query = <MinRatingSearch>{value: 2, negate: true, type: SearchQueryTypes.min_rating};
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-17 06:37:14 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
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-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-03-14 17:56:59 +08:00
|
|
|
<MaxResolutionSearch>{value: 0, type: SearchQueryTypes.max_resolution};
|
2021-02-14 19:57:05 +08:00
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-02-14 19:57:05 +08:00
|
|
|
query = <MaxResolutionSearch>{value: 1, type: SearchQueryTypes.max_resolution};
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
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-03-14 17:56:59 +08:00
|
|
|
query = <MinResolutionSearch>{value: 3, type: SearchQueryTypes.min_resolution};
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
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-03-14 17:56:59 +08:00
|
|
|
|
|
|
|
query = <MinResolutionSearch>{value: 3, negate: true, type: SearchQueryTypes.min_resolution};
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-17 06:37:14 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
2021-03-28 18:43:13 +08:00
|
|
|
media: [p, p2, p_faceLess, v],
|
2021-01-17 06:37:14 +08:00
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-03-14 17:56:59 +08:00
|
|
|
query = <MaxResolutionSearch>{value: 3, negate: true, type: SearchQueryTypes.max_resolution};
|
2021-01-17 17:56:33 +08:00
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should search orientation', async () => {
|
|
|
|
const sm = new SearchManager();
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
let query = <OrientationSearch>{
|
2021-01-17 06:37:14 +08:00
|
|
|
landscape: false,
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.orientation
|
2021-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p2, p4, v],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
2021-01-17 17:56:33 +08:00
|
|
|
query = <OrientationSearch>{
|
2021-01-17 06:37:14 +08:00
|
|
|
landscape: true,
|
2021-01-16 23:59:59 +08:00
|
|
|
type: SearchQueryTypes.orientation
|
2021-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p_faceLess, v],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should search distance', async () => {
|
|
|
|
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 17:56:33 +08:00
|
|
|
|
|
|
|
let query = <DistanceSearch>{
|
2021-01-16 23:59:59 +08:00
|
|
|
from: {text: 'Tatooine'},
|
|
|
|
distance: 1,
|
|
|
|
type: SearchQueryTypes.distance
|
2021-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
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-01-17 17:56:33 +08:00
|
|
|
query = <DistanceSearch>{
|
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-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
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-01-17 17:56:33 +08:00
|
|
|
query = <DistanceSearch>{
|
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-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-17 06:37:14 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-17 06:37:14 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p_faceLess, p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
2021-01-17 17:56:33 +08:00
|
|
|
query = <DistanceSearch>{
|
2021-01-16 23:59:59 +08:00
|
|
|
from: {GPSData: {latitude: 10, longitude: 10}},
|
|
|
|
distance: 1,
|
|
|
|
type: SearchQueryTypes.distance
|
2021-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
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-01-17 17:56:33 +08:00
|
|
|
query = <DistanceSearch>{
|
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-01-17 17:56:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(Utils.clone(await sm.search(query)))
|
2021-01-16 23:59:59 +08:00
|
|
|
.to.deep.equalInAnyOrder(removeDir(<SearchResultDTO>{
|
2021-01-17 17:56:33 +08:00
|
|
|
searchQuery: query,
|
2021-01-16 23:59:59 +08:00
|
|
|
directories: [],
|
|
|
|
media: [p, p_faceLess, p4],
|
|
|
|
metaFile: [],
|
|
|
|
resultOverflow: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
});
|
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-01-17 22:56:15 +08:00
|
|
|
let query = <TextSearch>{
|
|
|
|
text: 'xyz',
|
|
|
|
type: SearchQueryTypes.keyword
|
|
|
|
};
|
2021-02-14 19:57:05 +08:00
|
|
|
|
|
|
|
// tslint: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-01-17 22:56:15 +08:00
|
|
|
query = <TextSearch>{
|
|
|
|
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
|
|
|
|
};
|
|
|
|
expect(Utils.clone(await sm.getRandomPhoto(query))).to.deep.equalInAnyOrder(searchifyMedia(p_faceLess));
|
|
|
|
});
|
2018-01-31 09:01:16 +08:00
|
|
|
|
|
|
|
});
|