mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
fixing search and tests
This commit is contained in:
parent
c828d29dbc
commit
4a7e91ceb3
@ -150,15 +150,19 @@ export class GalleryManager implements IGalleryManager, ISQLGalleryManager {
|
|||||||
const media: MediaEntity[] = currentDir.media;
|
const media: MediaEntity[] = currentDir.media;
|
||||||
delete currentDir.media;
|
delete currentDir.media;
|
||||||
currentDir = await directoryRepository.save(currentDir);
|
currentDir = await directoryRepository.save(currentDir);
|
||||||
media.forEach(m => m.directory = currentDir);
|
if (media) {
|
||||||
currentDir.media = await this.saveMedia(connection, media);
|
media.forEach(m => m.directory = currentDir);
|
||||||
|
currentDir.media = await this.saveMedia(connection, media);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const media = scannedDirectory.media;
|
const media = scannedDirectory.media;
|
||||||
delete scannedDirectory.media;
|
delete scannedDirectory.media;
|
||||||
(<DirectoryEntity>scannedDirectory).lastScanned = scannedDirectory.lastScanned;
|
(<DirectoryEntity>scannedDirectory).lastScanned = scannedDirectory.lastScanned;
|
||||||
currentDir = await directoryRepository.save(<DirectoryEntity>scannedDirectory);
|
currentDir = await directoryRepository.save(<DirectoryEntity>scannedDirectory);
|
||||||
media.forEach(m => m.directory = currentDir);
|
if (media) {
|
||||||
currentDir.media = await this.saveMedia(connection, media);
|
media.forEach(m => m.directory = currentDir);
|
||||||
|
currentDir.media = await this.saveMedia(connection, media);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const childDirectories = await directoryRepository.createQueryBuilder('directory')
|
const childDirectories = await directoryRepository.createQueryBuilder('directory')
|
||||||
|
@ -40,7 +40,7 @@ export class SQLConnection {
|
|||||||
VersionEntity
|
VersionEntity
|
||||||
];
|
];
|
||||||
options.synchronize = false;
|
options.synchronize = false;
|
||||||
// options.logging = "all";
|
// options.logging = 'all';
|
||||||
this.connection = await createConnection(options);
|
this.connection = await createConnection(options);
|
||||||
await SQLConnection.schemeSync(this.connection);
|
await SQLConnection.schemeSync(this.connection);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import {SearchResultDTO} from '../../../common/entities/SearchResultDTO';
|
|||||||
import {SQLConnection} from './SQLConnection';
|
import {SQLConnection} from './SQLConnection';
|
||||||
import {PhotoEntity} from './enitites/PhotoEntity';
|
import {PhotoEntity} from './enitites/PhotoEntity';
|
||||||
import {DirectoryEntity} from './enitites/DirectoryEntity';
|
import {DirectoryEntity} from './enitites/DirectoryEntity';
|
||||||
|
import {MediaEntity} from './enitites/MediaEntity';
|
||||||
|
|
||||||
export class SearchManager implements ISearchManager {
|
export class SearchManager implements ISearchManager {
|
||||||
|
|
||||||
@ -24,32 +25,32 @@ export class SearchManager implements ISearchManager {
|
|||||||
|
|
||||||
const connection = await SQLConnection.getConnection();
|
const connection = await SQLConnection.getConnection();
|
||||||
|
|
||||||
let result: Array<AutoCompleteItem> = [];
|
let result: AutoCompleteItem[] = [];
|
||||||
const photoRepository = connection.getRepository(PhotoEntity);
|
const photoRepository = connection.getRepository(PhotoEntity);
|
||||||
|
const mediaRepository = connection.getRepository(MediaEntity);
|
||||||
const directoryRepository = connection.getRepository(DirectoryEntity);
|
const directoryRepository = connection.getRepository(DirectoryEntity);
|
||||||
|
|
||||||
|
|
||||||
(await photoRepository
|
(await photoRepository
|
||||||
.createQueryBuilder('media')
|
.createQueryBuilder('photo')
|
||||||
.select('DISTINCT(media.metadata.keywords)')
|
.select('DISTINCT(photo.metadata.keywords)')
|
||||||
.where('media.metadata.keywords LIKE :text COLLATE utf8_general_ci', {text: '%' + text + '%'})
|
.where('photo.metadata.keywords LIKE :text COLLATE utf8_general_ci', {text: '%' + text + '%'})
|
||||||
.limit(5)
|
.limit(5)
|
||||||
.getRawMany())
|
.getRawMany())
|
||||||
.map(r => <Array<string>>r.metadataKeywords.split(','))
|
.map(r => <Array<string>>(<string>r.metadataKeywords).split(','))
|
||||||
.forEach(keywords => {
|
.forEach(keywords => {
|
||||||
result = result.concat(this.encapsulateAutoComplete(keywords
|
result = result.concat(this.encapsulateAutoComplete(keywords
|
||||||
.filter(k => k.toLowerCase().indexOf(text.toLowerCase()) !== -1), SearchTypes.keyword));
|
.filter(k => k.toLowerCase().indexOf(text.toLowerCase()) !== -1), SearchTypes.keyword));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
(await photoRepository
|
(await photoRepository
|
||||||
.createQueryBuilder('media')
|
.createQueryBuilder('photo')
|
||||||
.select('media.metadata.positionData.country as country,' +
|
.select('photo.metadata.positionData.country as country, ' +
|
||||||
'mediao.metadata.positionData.state as state, media.metadata.positionData.city as city')
|
'photo.metadata.positionData.state as state, photo.metadata.positionData.city as city')
|
||||||
.where('media.metadata.positionData.country LIKE :text COLLATE utf8_general_ci', {text: '%' + text + '%'})
|
.where('photo.metadata.positionData.country LIKE :text COLLATE utf8_general_ci', {text: '%' + text + '%'})
|
||||||
.orWhere('media.metadata.positionData.state LIKE :text COLLATE utf8_general_ci', {text: '%' + text + '%'})
|
.orWhere('photo.metadata.positionData.state LIKE :text COLLATE utf8_general_ci', {text: '%' + text + '%'})
|
||||||
.orWhere('media.metadata.positionData.city LIKE :text COLLATE utf8_general_ci', {text: '%' + text + '%'})
|
.orWhere('photo.metadata.positionData.city LIKE :text COLLATE utf8_general_ci', {text: '%' + text + '%'})
|
||||||
.groupBy('media.metadata.positionData.country, media.metadata.positionData.state, media.metadata.positionData.city')
|
.groupBy('photo.metadata.positionData.country, photo.metadata.positionData.state, photo.metadata.positionData.city')
|
||||||
.limit(5)
|
.limit(5)
|
||||||
.getRawMany())
|
.getRawMany())
|
||||||
.filter(pm => !!pm)
|
.filter(pm => !!pm)
|
||||||
@ -59,7 +60,7 @@ export class SearchManager implements ISearchManager {
|
|||||||
.filter(p => p.toLowerCase().indexOf(text.toLowerCase()) !== -1), SearchTypes.position));
|
.filter(p => p.toLowerCase().indexOf(text.toLowerCase()) !== -1), SearchTypes.position));
|
||||||
});
|
});
|
||||||
|
|
||||||
result = result.concat(this.encapsulateAutoComplete((await photoRepository
|
result = result.concat(this.encapsulateAutoComplete((await mediaRepository
|
||||||
.createQueryBuilder('media')
|
.createQueryBuilder('media')
|
||||||
.select('DISTINCT(media.name)')
|
.select('DISTINCT(media.name)')
|
||||||
.where('media.name LIKE :text COLLATE utf8_general_ci', {text: '%' + text + '%'})
|
.where('media.name LIKE :text COLLATE utf8_general_ci', {text: '%' + text + '%'})
|
||||||
|
@ -55,7 +55,7 @@ export class PositionMetaDataEntity implements PositionMetaData {
|
|||||||
|
|
||||||
|
|
||||||
export class PhotoMetadataEntity extends MediaMetadataEntity implements PhotoMetadata {
|
export class PhotoMetadataEntity extends MediaMetadataEntity implements PhotoMetadata {
|
||||||
|
/*
|
||||||
@Column('simple-array')
|
@Column('simple-array')
|
||||||
keywords: string[];
|
keywords: string[];
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ export class PhotoMetadataEntity extends MediaMetadataEntity implements PhotoMet
|
|||||||
|
|
||||||
@Column('tinyint', {default: OrientationTypes.TOP_LEFT})
|
@Column('tinyint', {default: OrientationTypes.TOP_LEFT})
|
||||||
orientation: OrientationTypes;
|
orientation: OrientationTypes;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ export class DiskMangerWorker {
|
|||||||
metadata.creationDate = <number> (iptcData.date_time ? iptcData.date_time.getTime() : metadata.creationDate);
|
metadata.creationDate = <number> (iptcData.date_time ? iptcData.date_time.getTime() : metadata.creationDate);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Logger.debug(LOG_TAG, 'Error parsing iptc data', fullPath, err);
|
// Logger.debug(LOG_TAG, "Error parsing iptc data", fullPath, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata.creationDate = metadata.creationDate || 0;
|
metadata.creationDate = metadata.creationDate || 0;
|
||||||
|
@ -16,6 +16,8 @@ import {AutoCompleteItem, SearchTypes} from '../../../../../common/entities/Auto
|
|||||||
import {SearchResultDTO} from '../../../../../common/entities/SearchResultDTO';
|
import {SearchResultDTO} from '../../../../../common/entities/SearchResultDTO';
|
||||||
import {DirectoryEntity} from '../../../../../backend/model/sql/enitites/DirectoryEntity';
|
import {DirectoryEntity} from '../../../../../backend/model/sql/enitites/DirectoryEntity';
|
||||||
import {MediaDimensionEntity} from '../../../../../backend/model/sql/enitites/MediaEntity';
|
import {MediaDimensionEntity} from '../../../../../backend/model/sql/enitites/MediaEntity';
|
||||||
|
import {OrientationTypes} from 'ts-exif-parser';
|
||||||
|
import {Utils} from '../../../../../common/Utils';
|
||||||
|
|
||||||
describe('SearchManager', () => {
|
describe('SearchManager', () => {
|
||||||
|
|
||||||
@ -57,6 +59,11 @@ describe('SearchManager', () => {
|
|||||||
m.size = sd;
|
m.size = sd;
|
||||||
m.creationDate = Date.now();
|
m.creationDate = Date.now();
|
||||||
m.fileSize = 123456789;
|
m.fileSize = 123456789;
|
||||||
|
m.orientation = OrientationTypes.TOP_LEFT;
|
||||||
|
|
||||||
|
// TODO: remove when typeorm is fixed
|
||||||
|
m.duration = null;
|
||||||
|
m.bitRate = null;
|
||||||
|
|
||||||
|
|
||||||
const d = new PhotoEntity();
|
const d = new PhotoEntity();
|
||||||
@ -155,85 +162,86 @@ describe('SearchManager', () => {
|
|||||||
it('should search', async () => {
|
it('should search', async () => {
|
||||||
const sm = new SearchManager();
|
const sm = new SearchManager();
|
||||||
|
|
||||||
expect((await sm.search('sw', null))).to.deep.equal(<SearchResultDTO>{
|
|
||||||
|
expect(Utils.clone(await sm.search('sw', null))).to.deep.equal(Utils.clone(<SearchResultDTO>{
|
||||||
searchText: 'sw',
|
searchText: 'sw',
|
||||||
searchType: null,
|
searchType: null,
|
||||||
directories: [],
|
directories: [],
|
||||||
media: [p, p2],
|
media: [p, p2],
|
||||||
resultOverflow: false
|
resultOverflow: false
|
||||||
});
|
}));
|
||||||
|
|
||||||
expect((await sm.search('Tatooine', SearchTypes.position))).to.deep.equal(<SearchResultDTO>{
|
expect(Utils.clone(await sm.search('Tatooine', SearchTypes.position))).to.deep.equal(Utils.clone(<SearchResultDTO>{
|
||||||
searchText: 'Tatooine',
|
searchText: 'Tatooine',
|
||||||
searchType: SearchTypes.position,
|
searchType: SearchTypes.position,
|
||||||
directories: [],
|
directories: [],
|
||||||
media: [p],
|
media: [p],
|
||||||
resultOverflow: false
|
resultOverflow: false
|
||||||
});
|
}));
|
||||||
|
|
||||||
expect((await sm.search('ortm', SearchTypes.keyword))).to.deep.equal(<SearchResultDTO>{
|
expect(Utils.clone(await sm.search('ortm', SearchTypes.keyword))).to.deep.equal(Utils.clone(<SearchResultDTO>{
|
||||||
searchText: 'ortm',
|
searchText: 'ortm',
|
||||||
searchType: SearchTypes.keyword,
|
searchType: SearchTypes.keyword,
|
||||||
directories: [],
|
directories: [],
|
||||||
media: [p2],
|
media: [p2],
|
||||||
resultOverflow: false
|
resultOverflow: false
|
||||||
});
|
}));
|
||||||
|
|
||||||
expect((await sm.search('ortm', SearchTypes.keyword))).to.deep.equal(<SearchResultDTO>{
|
expect(Utils.clone(await sm.search('ortm', SearchTypes.keyword))).to.deep.equal(Utils.clone(<SearchResultDTO>{
|
||||||
searchText: 'ortm',
|
searchText: 'ortm',
|
||||||
searchType: SearchTypes.keyword,
|
searchType: SearchTypes.keyword,
|
||||||
directories: [],
|
directories: [],
|
||||||
media: [p2],
|
media: [p2],
|
||||||
resultOverflow: false
|
resultOverflow: false
|
||||||
});
|
}));
|
||||||
|
|
||||||
expect((await sm.search('wa', SearchTypes.keyword))).to.deep.equal(<SearchResultDTO>{
|
expect(Utils.clone(await sm.search('wa', SearchTypes.keyword))).to.deep.equal(Utils.clone(<SearchResultDTO>{
|
||||||
searchText: 'wa',
|
searchText: 'wa',
|
||||||
searchType: SearchTypes.keyword,
|
searchType: SearchTypes.keyword,
|
||||||
directories: [dir],
|
directories: [dir],
|
||||||
media: [p, p2],
|
media: [p, p2],
|
||||||
resultOverflow: false
|
resultOverflow: false
|
||||||
});
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should instant search', async () => {
|
it('should instant search', async () => {
|
||||||
const sm = new SearchManager();
|
const sm = new SearchManager();
|
||||||
|
|
||||||
expect((await sm.instantSearch('sw'))).to.deep.equal({
|
expect(Utils.clone(await sm.instantSearch('sw'))).to.deep.equal(Utils.clone({
|
||||||
searchText: 'sw',
|
searchText: 'sw',
|
||||||
directories: [],
|
directories: [],
|
||||||
photos: [p, p2],
|
media: [p, p2],
|
||||||
resultOverflow: false
|
resultOverflow: false
|
||||||
});
|
}));
|
||||||
|
|
||||||
expect((await sm.instantSearch('Tatooine'))).to.deep.equal({
|
expect(Utils.clone(await sm.instantSearch('Tatooine'))).to.deep.equal(Utils.clone({
|
||||||
searchText: 'Tatooine',
|
searchText: 'Tatooine',
|
||||||
directories: [],
|
directories: [],
|
||||||
photos: [p],
|
media: [p],
|
||||||
resultOverflow: false
|
resultOverflow: false
|
||||||
});
|
}));
|
||||||
|
|
||||||
expect((await sm.instantSearch('ortm'))).to.deep.equal({
|
expect(Utils.clone(await sm.instantSearch('ortm'))).to.deep.equal(Utils.clone({
|
||||||
searchText: 'ortm',
|
searchText: 'ortm',
|
||||||
directories: [],
|
directories: [],
|
||||||
photos: [p2],
|
media: [p2],
|
||||||
resultOverflow: false
|
resultOverflow: false
|
||||||
});
|
}));
|
||||||
|
|
||||||
expect((await sm.instantSearch('ortm'))).to.deep.equal({
|
expect(Utils.clone(await sm.instantSearch('ortm'))).to.deep.equal(Utils.clone({
|
||||||
searchText: 'ortm',
|
searchText: 'ortm',
|
||||||
directories: [],
|
directories: [],
|
||||||
photos: [p2],
|
media: [p2],
|
||||||
resultOverflow: false
|
resultOverflow: false
|
||||||
});
|
}));
|
||||||
|
|
||||||
expect((await sm.instantSearch('wa'))).to.deep.equal({
|
expect(Utils.clone(await sm.instantSearch('wa'))).to.deep.equal(Utils.clone({
|
||||||
searchText: 'wa',
|
searchText: 'wa',
|
||||||
directories: [dir],
|
directories: [dir],
|
||||||
photos: [p, p2],
|
media: [p, p2],
|
||||||
resultOverflow: false
|
resultOverflow: false
|
||||||
});
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user