mirror of
https://github.com/bpatrik/pigallery2.git
synced 2025-01-04 03:49:28 +02:00
improving person name case special support
This commit is contained in:
parent
f34e934597
commit
bc875c2e96
@ -53,7 +53,7 @@ export class PersonManager implements IPersonManager {
|
|||||||
queryStr += ':n' + i + ' COLLATE utf8_general_ci';
|
queryStr += ':n' + i + ' COLLATE utf8_general_ci';
|
||||||
namesObj['n' + i] = n;
|
namesObj['n' + i] = n;
|
||||||
});
|
});
|
||||||
const rawAndEntities = await (connection
|
const query: SelectQueryBuilder<MediaEntity> = await (connection
|
||||||
.getRepository(MediaEntity)
|
.getRepository(MediaEntity)
|
||||||
.createQueryBuilder('media') as SelectQueryBuilder<MediaEntity>)
|
.createQueryBuilder('media') as SelectQueryBuilder<MediaEntity>)
|
||||||
.select(['media.name', 'media.id', 'person.name', 'directory.name',
|
.select(['media.name', 'media.id', 'person.name', 'directory.name',
|
||||||
@ -61,10 +61,15 @@ export class PersonManager implements IPersonManager {
|
|||||||
.leftJoin('media.directory', 'directory')
|
.leftJoin('media.directory', 'directory')
|
||||||
.leftJoinAndSelect('media.metadata.faces', 'faces')
|
.leftJoinAndSelect('media.metadata.faces', 'faces')
|
||||||
.leftJoin('faces.person', 'person')
|
.leftJoin('faces.person', 'person')
|
||||||
.groupBy('person.name, media.name, media.id, directory.name, faces.id')
|
.groupBy('person.name, media.name, media.id, directory.name, faces.id');
|
||||||
.orWhere(`lower(person.name) IN (:...names)`, {names: names.map(n => n.toLowerCase())}).getRawAndEntities();
|
// 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) {
|
for (let i = 0; i < rawAndEntities.raw.length; ++i) {
|
||||||
this.samplePhotos[rawAndEntities.raw[i].person_name.toLowerCase()] =
|
this.samplePhotos[rawAndEntities.raw[i].person_name.toLowerCase()] =
|
||||||
Utils.clone(rawAndEntities.entities.find(m => m.name === rawAndEntities.raw[i].media_name));
|
Utils.clone(rawAndEntities.entities.find(m => m.name === rawAndEntities.raw[i].media_name));
|
||||||
|
@ -5,7 +5,7 @@ import {ColumnOptions} from 'typeorm/decorator/options/ColumnOptions';
|
|||||||
export class ColumnCharsetCS implements ColumnOptions {
|
export class ColumnCharsetCS implements ColumnOptions {
|
||||||
|
|
||||||
public get charset(): string {
|
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 {
|
public get collation(): string {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import {Column, Entity, Index, OneToMany, PrimaryGeneratedColumn, Unique} from 'typeorm';
|
import {Column, Entity, Index, OneToMany, PrimaryGeneratedColumn, Unique} from 'typeorm';
|
||||||
import {FaceRegionEntry} from './FaceRegionEntry';
|
import {FaceRegionEntry} from './FaceRegionEntry';
|
||||||
import {PersonDTO} from '../../../../../common/entities/PersonDTO';
|
import {PersonDTO} from '../../../../../common/entities/PersonDTO';
|
||||||
|
import {columnCharsetCS} from './EntityUtils';
|
||||||
|
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
@ -11,7 +12,7 @@ export class PersonEntry implements PersonDTO {
|
|||||||
@PrimaryGeneratedColumn({unsigned: true})
|
@PrimaryGeneratedColumn({unsigned: true})
|
||||||
id: number;
|
id: number;
|
||||||
|
|
||||||
@Column()
|
@Column(columnCharsetCS)
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@Column('int', {unsigned: true, default: 0})
|
@Column('int', {unsigned: true, default: 0})
|
||||||
|
@ -106,6 +106,7 @@ describe('PersonManager', (sqlHelper: SQLTestHelper) => {
|
|||||||
delete map[k];
|
delete map[k];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(await pm.getSamplePhotos(p.metadata.faces.map(f => f.name.toLowerCase()))).to.deep.equal(map);
|
expect(await pm.getSamplePhotos(p.metadata.faces.map(f => f.name.toLowerCase()))).to.deep.equal(map);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -109,14 +109,17 @@ export class TestHelper {
|
|||||||
box: {height: 10, width: 10, left: 10, top: 10},
|
box: {height: 10, width: 10, left: 10, top: 10},
|
||||||
name: 'Boba Fett'
|
name: 'Boba Fett'
|
||||||
}, <FaceRegion>{
|
}, <FaceRegion>{
|
||||||
box: {height: 10, width: 10, left: 101, top: 101},
|
box: {height: 10, width: 10, left: 102, top: 102},
|
||||||
name: 'Luke Skywalker'
|
name: 'Luke Skywalker'
|
||||||
}, <FaceRegion>{
|
}, <FaceRegion>{
|
||||||
box: {height: 10, width: 10, left: 101, top: 101},
|
box: {height: 10, width: 10, left: 103, top: 103},
|
||||||
name: 'Han Solo'
|
name: 'Han Solo'
|
||||||
}, <FaceRegion>{
|
}, <FaceRegion>{
|
||||||
box: {height: 10, width: 10, left: 101, top: 101},
|
box: {height: 10, width: 10, left: 104, top: 104},
|
||||||
name: 'Unkle Ben'
|
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[];
|
}] as any[];
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user