return facetData;
}
- fetchCcvms(): Promise<any> {
+ fetchCcvms(): Promise<void> {
- // XXX Putting the elastic initialization call here since
- // the call is assumed to be run at page load time.
- // TODO: migrate our fetch calls to generic init call.
-
- return this.elastic.init().then(ok => {
-
- if (Object.keys(this.ccvmMap).length) {
- return Promise.resolve();
- }
+ if (Object.keys(this.ccvmMap).length) {
+ return Promise.resolve();
+ }
- return this.pcrud.search('ccvm',
+ return new Promise((resolve, reject) => {
+ this.pcrud.search('ccvm',
{ctype : CATALOG_CCVM_FILTERS}, {},
{atomic: true, anonymous: true}
- ).toPromise().then(list => this.compileCcvms(list));
+ ).subscribe(list => {
+ this.compileCcvms(list);
+ resolve();
+ });
});
}
@Injectable()
export class ElasticService {
- bibFields: IdlObject[] = [];
-
constructor(
private idl: IdlService,
private net: NetService,
private pcrud: PcrudService
) {}
- init(): Promise<any> {
-
- if (this.bibFields.length > 0) {
- return Promise.resolve();
- }
-
- return this.pcrud.search('ebf', {search_field: 't'})
- .pipe(tap(field => this.bibFields.push(field)))
- .toPromise();
- }
-
// Returns true if Elastic can provide search results.
canSearch(ctx: CatalogSearchContext): boolean {
if ( ctx.termSearch.isSearchable() &&
!ctx.termSearch.groupByMetarecord &&
!ctx.termSearch.fromMetarecord &&
- !ctx.termSearch.hasBrowseEntry) {
- return true;
+ !ctx.termSearch.hasBrowseEntry) {
+ return true;
}
if (ctx.identSearch.isSearchable()
search.sort(new Sort(parts[0], parts[1] ? 'desc' : 'asc'));
} else {
-
+
// Sort by match score by default.
search.sort(new Sort('_score', 'desc'));
}
query.type('most_fields');
boolNode.mustNot(query);
return;
- }
- // Under the covers, searches on a field class are OR searches
- // across all fields within the class. Unlike MultiMatch
- // searches (above) where this can be accomplished with field
- // name wildcards, term/prefix searches require explicit field
- // names.
- const shoulds: Query[] = [];
-
- this.getSearchFieldsForClass(fieldClass).forEach(field => {
- const fieldName = `${fieldClass}|${field.name()}`;
- if (matchOp === 'exact') {
- query = new TermQuery(fieldName, value);
- } else if (matchOp === 'starts') {
- query = new PrefixQuery(fieldName, value);
- }
-
- shoulds.push(query);
- });
-
- // Wrap the 'shoulds' in a 'must' so that at least one of
- // the shoulds must match for the group to match.
- boolNode.must(new BoolQuery().should(shoulds));
- }
+ // "exact" and "starts" searches use term searches instead
+ // of full-text searches.
+ case 'exact':
+ query = new TermQuery(fieldClass, value);
+ boolNode.must(query);
+ return;
- getSearchFieldsForClass(fieldClass: string): any[] {
- return this.bibFields.filter(f => (
- f.search_field() === 't' &&
- f.search_group() === fieldClass
- ));
+ case 'starts':
+ query = new PrefixQuery(fieldClass, value);
+ boolNode.must(query);
+ return;
+ }
}
}