Skip to content

Commit

Permalink
Added arguments to doc search index.
Browse files Browse the repository at this point in the history
  • Loading branch information
imolorhe committed Jul 23, 2017
1 parent 8b9c9df commit 3e93d22
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Expand Up @@ -3,7 +3,7 @@
Search Results
</div>

<div class="doc-viewer-search-result-item" *ngFor="let result of results">
<div class="doc-viewer-search-result-item" *ngFor="let result of results" (click)="goToItem(result.name, result.type, result.cat)">
<ng-container [ngSwitch]="result.cat">
<ng-container *ngSwitchCase="'type'">
<span class="doc-viewer-search-result-cat cat-type">Type</span>
Expand All @@ -12,8 +12,11 @@
<span class="doc-viewer-search-result-cat cat-query" *ngIf="result.isQuery">{{getProperName(result.type)}}</span>
<span class="doc-viewer-search-result-cat cat-field" *ngIf="!result.isQuery">Field</span>
</ng-container>
<ng-container *ngSwitchDefault>
<span class="doc-viewer-search-result-cat cat-type">{{getProperName(result.cat)}}</span>
</ng-container>
</ng-container>
<div class="doc-viewer-search-result-item-inner" (click)="goToItem(result.name, result.type, result.cat)">
<div class="doc-viewer-search-result-item-inner">
<ng-container *ngIf="!result.isQuery">
<span *ngIf="result.type" class="doc-viewer-search-result-parent-type">{{result.type}}.</span>{{result.name}}
</ng-container>
Expand Down
30 changes: 26 additions & 4 deletions src/app/components/doc-viewer/doc-viewer/doc-viewer.component.ts
Expand Up @@ -61,15 +61,31 @@ export class DocViewerComponent implements OnChanges {

Object.keys(fields).forEach(fieldKey => {
const field = fields[fieldKey];
index = [...index, {

// For each field, create an entry in the index
const fieldIndex = {
search: field.name,
name: field.name,
description: field.description,
args: field.args,
cat: 'field',
type: type.name,
isQuery
}];
};
index = [...index, fieldIndex];

// For each argument of the field, create an entry in the index for the field,
// searchable by the argument name
if (field.args.length) {
field.args.forEach(arg => {
index = [...index, {
...fieldIndex,
search: arg.name,
}];
});
}

// If the field has a type, get indices for the type as well
if (field.type) {
index = [...index, ...getTypeIndices(field.type).filter(val => !!val)];
}
Expand All @@ -93,7 +109,13 @@ export class DocViewerComponent implements OnChanges {
}

const index = [
{ name: type.name, cat: 'type', description: type.description, isRoot }
{
search: type.name,
name: type.name,
cat: 'type',
description: type.description,
isRoot
}
];

if (fields) {
Expand All @@ -119,7 +141,7 @@ export class DocViewerComponent implements OnChanges {
searchDocs(term) {
this.docHistory.push(Object.assign({}, this.docView));
this.docView.view = 'search';
this.searchResult = this.index.filter(item => new RegExp(term, 'i').test(item.name));
this.searchResult = this.index.filter(item => new RegExp(term, 'i').test(item.search));
console.log(this.searchResult);
}

Expand Down

0 comments on commit 3e93d22

Please sign in to comment.