1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-03-29 21:56:58 +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

@ -1,15 +1,12 @@
import { Injectable } from '@angular/core'; import {Injectable} from '@angular/core';
import { NetworkService } from '../../../model/network/network.service'; import {NetworkService} from '../../../model/network/network.service';
import { IAutoCompleteItem } from '../../../../../common/entities/AutoCompleteItem'; import {IAutoCompleteItem} from '../../../../../common/entities/AutoCompleteItem';
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, import {QueryParams} from '../../../../../common/QueryParams';
TextSearchQueryTypes, import {SearchQueryParser} from '../../../../../common/SearchQueryParser';
} from '../../../../../common/entities/SearchQueryDTO';
import { QueryParams } from '../../../../../common/QueryParams';
import { SearchQueryParser } from '../../../../../common/SearchQueryParser';
@Injectable() @Injectable()
export class AutoCompleteService { export class AutoCompleteService {
@ -40,42 +37,36 @@ 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 +
':' + ':' +
SearchQueryParser.stringifyText(new Date().getFullYear().toString()) SearchQueryParser.stringifyText(new Date().getFullYear().toString())
); );
this.keywords.push( this.keywords.push(
this.searchQueryParserService.keywords.to + this.searchQueryParserService.keywords.to +
':' + ':' +
SearchQueryParser.stringifyText( SearchQueryParser.stringifyText(
SearchQueryParser.stringifyDate(Date.now()) SearchQueryParser.stringifyDate(Date.now())
) )
); );
this.keywords.push( this.keywords.push(
this.searchQueryParserService.keywords.from + this.searchQueryParserService.keywords.from +
':' + ':' +
SearchQueryParser.stringifyText(new Date().getFullYear().toString()) SearchQueryParser.stringifyText(new Date().getFullYear().toString())
); );
this.keywords.push( this.keywords.push(
this.searchQueryParserService.keywords.from + this.searchQueryParserService.keywords.from +
':' + ':' +
SearchQueryParser.stringifyText( SearchQueryParser.stringifyText(
SearchQueryParser.stringifyDate(Date.now()) SearchQueryParser.stringifyDate(Date.now())
) )
); );
TextSearchQueryTypes.forEach((t) => { TextSearchQueryTypes.forEach((t) => {
this.textSearchKeywordsMap[ this.textSearchKeywordsMap[
(this.searchQueryParserService.keywords as any)[SearchQueryTypes[t]] (this.searchQueryParserService.keywords as any)[SearchQueryTypes[t]]
] = t; ] = t;
}); });
} }
@ -173,7 +164,7 @@ export class AutoCompleteService {
searchToken: string searchToken: string
): RenderableAutoCompleteItem { ): RenderableAutoCompleteItem {
if (!item.type) { if (!item.type) {
return { text: item.text, queryHint: item.text }; return {text: item.text, queryHint: item.text};
} }
if ( if (
(TextSearchQueryTypes.includes(item.type) || (TextSearchQueryTypes.includes(item.type) ||
@ -183,7 +174,7 @@ export class AutoCompleteService {
let queryHint = let queryHint =
(this.searchQueryParserService.keywords as any)[ (this.searchQueryParserService.keywords as any)[
SearchQueryTypes[item.type] SearchQueryTypes[item.type]
] + ] +
':"' + ':"' +
item.text + item.text +
'"'; '"';
@ -256,13 +247,25 @@ export class AutoCompleteService {
return []; return [];
} }
} }
return this.keywords const generateMatch = (key: string) => ({
text: key,
queryHint: key,
notSearchable: true,
});
const ret = this.keywords
.filter((key) => key.startsWith(text.current.toLowerCase())) .filter((key) => key.startsWith(text.current.toLowerCase()))
.map((key) => ({ .map(generateMatch);
text: key,
queryHint: key, // make KmFrom sensitive to all positive distances
notSearchable: true, 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;
} }
} }