1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-01-02 03:37:54 +02:00

improving person name case special support

This commit is contained in:
Patrik J. Braun 2020-01-01 23:24:22 +01:00
parent f34e934597
commit bc875c2e96
5 changed files with 19 additions and 9 deletions

View File

@ -53,7 +53,7 @@ export class PersonManager implements IPersonManager {
queryStr += ':n' + i + ' COLLATE utf8_general_ci';
namesObj['n' + i] = n;
});
const rawAndEntities = await (connection
const query: SelectQueryBuilder<MediaEntity> = await (connection
.getRepository(MediaEntity)
.createQueryBuilder('media') as SelectQueryBuilder<MediaEntity>)
.select(['media.name', 'media.id', 'person.name', 'directory.name',
@ -61,10 +61,15 @@ export class PersonManager implements IPersonManager {
.leftJoin('media.directory', 'directory')
.leftJoinAndSelect('media.metadata.faces', 'faces')
.leftJoin('faces.person', 'person')
.groupBy('person.name, media.name, media.id, directory.name, faces.id')
.orWhere(`lower(person.name) IN (:...names)`, {names: names.map(n => n.toLowerCase())}).getRawAndEntities();
.groupBy('person.name, media.name, media.id, directory.name, faces.id');
// TODO: improve it. SQLITE does not support case-insensitive special characters like ÁÉÚŐ
for (let i = 0; i < names.length; ++i) {
const opt: any = {};
opt['n' + i] = names[i];
query.orWhere(`person.name LIKE :n${i} COLLATE utf8_general_ci`, opt);
}
const rawAndEntities = await query.getRawAndEntities();
for (let i = 0; i < rawAndEntities.raw.length; ++i) {
this.samplePhotos[rawAndEntities.raw[i].person_name.toLowerCase()] =
Utils.clone(rawAndEntities.entities.find(m => m.name === rawAndEntities.raw[i].media_name));

View File

@ -5,7 +5,7 @@ import {ColumnOptions} from 'typeorm/decorator/options/ColumnOptions';
export class ColumnCharsetCS implements ColumnOptions {
public get charset(): string {
return Config.Server.Database.type === ServerConfig.DatabaseType.mysql ? 'utf8' : null;
return Config.Server.Database.type === ServerConfig.DatabaseType.mysql ? 'utf8' : 'utf8';
}
public get collation(): string {

View File

@ -1,6 +1,7 @@
import {Column, Entity, Index, OneToMany, PrimaryGeneratedColumn, Unique} from 'typeorm';
import {FaceRegionEntry} from './FaceRegionEntry';
import {PersonDTO} from '../../../../../common/entities/PersonDTO';
import {columnCharsetCS} from './EntityUtils';
@Entity()
@ -11,7 +12,7 @@ export class PersonEntry implements PersonDTO {
@PrimaryGeneratedColumn({unsigned: true})
id: number;
@Column()
@Column(columnCharsetCS)
name: string;
@Column('int', {unsigned: true, default: 0})

View File

@ -106,6 +106,7 @@ describe('PersonManager', (sqlHelper: SQLTestHelper) => {
delete map[k];
}
}
expect(await pm.getSamplePhotos(p.metadata.faces.map(f => f.name.toLowerCase()))).to.deep.equal(map);
});

View File

@ -109,14 +109,17 @@ export class TestHelper {
box: {height: 10, width: 10, left: 10, top: 10},
name: 'Boba Fett'
}, <FaceRegion>{
box: {height: 10, width: 10, left: 101, top: 101},
box: {height: 10, width: 10, left: 102, top: 102},
name: 'Luke Skywalker'
}, <FaceRegion>{
box: {height: 10, width: 10, left: 101, top: 101},
box: {height: 10, width: 10, left: 103, top: 103},
name: 'Han Solo'
}, <FaceRegion>{
box: {height: 10, width: 10, left: 101, top: 101},
box: {height: 10, width: 10, left: 104, top: 104},
name: 'Unkle Ben'
}, <FaceRegion>{
box: {height: 10, width: 10, left: 105, top: 105},
name: 'Arvíztűrő Tükörfúrógép'
}] as any[];
return p;
}