Skip to content

Commit

Permalink
Hotfix/advanced search fix (#180)
Browse files Browse the repository at this point in the history
* Null checks

* Test for null
  • Loading branch information
garyluu authored Jan 25, 2018
1 parent 30c985a commit 075df42
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/app/search/search.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
</span>
</div>
</div>
<div class="alert alert-info" *ngIf="hits.length > query_size - 1 && searchService.hasNarrowedSearch(advancedSearchObject, searchTerm, hits, filters)">
<div class="alert alert-info" *ngIf="hits?.length > query_size - 1 && searchService.hasNarrowedSearch(advancedSearchObject, searchTerm, hits, filters)">
<p><strong>Notice: </strong>Your search has returned greater than {{ query_size - 1 }} results, however only {{ query_size - 1 }} results are shown.
We recommend that you narrow your search to find more relevant results.</p>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/app/search/search.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ describe('SearchService', () => {
expect(service.haveNoHits([])).toEqual(true);
expect(service.haveNoHits([{'asdf': 'asdf'}])).toEqual(false);
}));

it('should not crash on null advancedSearchObject', inject([SearchService], (service: SearchService) => {
expect(service.hasSearchText(null, null, null)).toEqual(false);
}));
});
13 changes: 9 additions & 4 deletions src/app/search/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class SearchService {
}
);

if (searchInfo.searchTerm && !searchInfo.advancedSearchObject.toAdvanceSearch) {
if (searchInfo.searchTerm && (!searchInfo.advancedSearchObject || !searchInfo.advancedSearchObject.toAdvanceSearch)) {
params.append('search', searchInfo.searchValues);
} else {
const advSearchKeys = Object.keys(searchInfo.advancedSearchObject);
Expand Down Expand Up @@ -259,9 +259,14 @@ export class SearchService {
* (though not just the searchMode, which is set by default)
*/
hasSearchText(advancedSearchObject: any, searchTerm: boolean, hits: any) {
const advSearchSet = ((advancedSearchObject.toAdvanceSearch) &&
(advancedSearchObject.ANDSplitFilter || advancedSearchObject.ANDNoSplitFilter
|| advancedSearchObject.ORFilter || advancedSearchObject.NOTFilter));
let advSearchSet;
if (!advancedSearchObject) {
advSearchSet = false;
} else {
advSearchSet = ((advancedSearchObject.toAdvanceSearch) &&
(advancedSearchObject.ANDSplitFilter || advancedSearchObject.ANDNoSplitFilter
|| advancedSearchObject.ORFilter || advancedSearchObject.NOTFilter));
}
return (this.hasResults(searchTerm, hits) || advSearchSet);
}

Expand Down

0 comments on commit 075df42

Please sign in to comment.