1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-03-31 22:05:20 +02:00

Making autocomplete trigger for any positive number for km-from queries #587

This commit is contained in:
Patrik J. Braun 2023-03-23 23:07:26 +01:00
parent 9d0ea33059
commit ef75247f79

View File

@ -4,10 +4,7 @@ import { IAutoCompleteItem } from '../../../../../common/entities/AutoCompleteIt
import {GalleryCacheService} from '../cache.gallery.service'; import {GalleryCacheService} from '../cache.gallery.service';
import {SearchQueryParserService} from './search-query-parser.service'; import {SearchQueryParserService} from './search-query-parser.service';
import {BehaviorSubject} from 'rxjs'; import {BehaviorSubject} from 'rxjs';
import { import {SearchQueryTypes, TextSearchQueryTypes,} from '../../../../../common/entities/SearchQueryDTO';
SearchQueryTypes,
TextSearchQueryTypes,
} from '../../../../../common/entities/SearchQueryDTO';
import {QueryParams} from '../../../../../common/QueryParams'; import {QueryParams} from '../../../../../common/QueryParams';
import {SearchQueryParser} from '../../../../../common/SearchQueryParser'; import {SearchQueryParser} from '../../../../../common/SearchQueryParser';
@ -40,12 +37,6 @@ export class AutoCompleteService {
); );
} }
for (let i = 0; i < 10; i++) {
this.keywords.push(
i + '-' + this.searchQueryParserService.keywords.kmFrom + ':'
);
}
this.keywords.push( this.keywords.push(
this.searchQueryParserService.keywords.to + this.searchQueryParserService.keywords.to +
':' + ':' +
@ -256,13 +247,25 @@ export class AutoCompleteService {
return []; return [];
} }
} }
return this.keywords const generateMatch = (key: string) => ({
.filter((key) => key.startsWith(text.current.toLowerCase()))
.map((key) => ({
text: key, text: key,
queryHint: key, queryHint: key,
notSearchable: true, notSearchable: true,
})); });
const ret = this.keywords
.filter((key) => key.startsWith(text.current.toLowerCase()))
.map(generateMatch);
// make KmFrom sensitive to all positive distances
const starterNum = parseInt(text.current);
if (starterNum > 0) {
const key = starterNum + '-' + this.searchQueryParserService.keywords.kmFrom + ':';
if (key.startsWith(text.current.toLowerCase())) {
ret.push(generateMatch(key));
}
}
return ret;
} }
} }