Skip to content

Commit

Permalink
Fixed search issue - always return all records
Browse files Browse the repository at this point in the history
  • Loading branch information
chuanlin2018 committed May 16, 2024
1 parent 10858c1 commit 0f513a0
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 47 deletions.
30 changes: 29 additions & 1 deletion angular/src/app/adv-search/adv-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit, Aft

this.searchFieldsListService.watchFields(
(fields) =>{
this.fields = (fields as SelectItem[]);
this.fields = this.toFieldItems(fields);
}
);
}
Expand Down Expand Up @@ -579,4 +579,32 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit, Aft
this.searchQueryService.saveQueries(this.queries);
op.hide();
}

/**
* Advanced Search fields dropdown
*/
toFieldItems(fields: any[]): SelectItem[] {
// let items: SelectItem[] = [];
// items.push({ label: this.ALL, value: 'searchphrase' });
let fieldItems: SelectItem[] = [];
for (let field of fields) {
if (_.includes(field.tags, 'searchable')) {
let dup = false;
//For some reason, the filter function does not work for fields. Have to use this loop...
for(let item of fieldItems){
if(item.label == field.label && item.value == field.name.replace('component.', 'components.')){
dup = true;
break;
}
}

if(!dup){
fieldItems.push({ label: field.label, value: field.name.replace('component.', 'components.') });
}
}
};
fieldItems = _.sortBy(fieldItems, ['label', 'value']);

return fieldItems;
}
}
2 changes: 1 addition & 1 deletion angular/src/app/search-panel/search-panel.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h3 *ngIf="title" class="title">{{title}}</h3>
<div class="inner-addon left-addon background-white search-box" >
<i class="glyphicon faa faa-search" style="cursor: pointer;z-index: 999 !important;float: left;" (click)="hideAllHelp();search(searchValue,searchTaxonomyKey)"></i>
<div>
<p-autoComplete p-fluid #audocomp [inputStyle]="inputStyle" (onFocus)="clearText()"
<p-autoComplete p-fluid #audocomp [inputStyle]="inputStyle" (onFocus)="selectAll()"
(onBlur)="addPlaceholder()" [placeholder]="placeholder" [(ngModel)]="searchValue"
inputId="searchinput" name="searchinput"
 (keyup.enter)="audocomp.handleDropdownClick();search(searchValue,searchTaxonomyKey)"
Expand Down
6 changes: 2 additions & 4 deletions angular/src/app/search-panel/search-panel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,10 @@ export class SearchPanelComponent implements OnInit {
/**
* Clear the search text box
*/
clearText() {
selectAll() {
var field = (<HTMLInputElement>document.getElementById('searchinput'));

if (!Boolean(this._searchValue.trim())) {
field.value = ' ';
}
field.select();
}

/**
Expand Down
1 change: 0 additions & 1 deletion angular/src/app/search/filters/filters.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ export class FiltersComponent implements OnInit, AfterViewInit {
(fields) => {
if(fields.length > 0){
this.toSortItems(fields);
this.queryAndSearch();
}
}
)
Expand Down
13 changes: 9 additions & 4 deletions angular/src/app/search/results/results.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ export class ResultsComponent implements OnInit {

this.searchFieldsListService.watchFields(
(fields) => {
this.filterableFields = this.toSortItems(fields);

//Convert to a query then search
this.searchSubscription = this.search(null, 1, this.itemsPerPage);
if(fields && fields.length > 0) {
this.filterableFields = this.toSortItems(fields);
}
}
)
}
Expand Down Expand Up @@ -106,9 +105,15 @@ export class ResultsComponent implements OnInit {
this.searchSubscription = this.search(null, null, this.itemsPerPage);
}));

this.searchSubscription = this.search(null, 1, this.itemsPerPage);

this.inited = true;
}

ngAfterViewInit(): void {
// this.searchSubscription = this.search(null, 1, this.itemsPerPage);
}

/**
* On destroy, unsubscribe all subscriptions
*/
Expand Down
8 changes: 4 additions & 4 deletions angular/src/app/shared/config-service/config.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ describe('AppConfig', () => {

service.getRemoteConfig().subscribe(
(conf) => {
expect(conf["SERVERBASE"]).toEqual("http://data.nist.gov");
expect(conf["RMMAPI"]).toEqual("http://data.nist.gov/rmm/");
expect(conf["SERVERBASE"]).toEqual("https://data.nist.gov");
expect(conf["RMMAPI"]).toEqual("https://data.nist.gov/rmm/");
expect(conf["SDPAPI"]).toEqual("http://localhost:5555/");
expect(conf.GACODE).toEqual("not-set");
expect(conf.APPVERSION).toEqual("1.3.0");
Expand All @@ -59,8 +59,8 @@ describe('AppConfig', () => {
service.loadRemoteConfig();
service.getConfig().subscribe(
(conf) => {
expect(conf["SERVERBASE"]).toEqual("http://data.nist.gov");
expect(conf["RMMAPI"]).toEqual("http://data.nist.gov/rmm/");
expect(conf["SERVERBASE"]).toEqual("https://data.nist.gov");
expect(conf["RMMAPI"]).toEqual("https://data.nist.gov/rmm/");
expect(conf["SDPAPI"]).toEqual("http://localhost:5555/");
expect(conf.GACODE).toEqual("not-set");
expect(conf.APPVERSION).toEqual("1.3.0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ export class RealSearchService implements SearchService{
url = 'records?';

if(searchPhraseValue)
url += "&" + searchPhraseValue.trim();
url += searchPhraseValue.trim();
// url += "&" + searchPhraseValue.trim();

if(sortOrder){
url += '&sort.asc=' + sortOrder;
Expand Down Expand Up @@ -160,6 +161,7 @@ export class RealSearchService implements SearchService{
url += '&include=ediid,description,title,keyword,topic.tag,contactPoint,components,@type,doi,landingPage&exclude=_id';
}

console.log("Calling back end==============:", url);
return this.appConfig.getConfig().pipe(
rxjsop.mergeMap((conf) => {
return this.http.get(conf.RMMAPI + url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class SearchfieldsListService {
next: (conf) => {
this.get(conf.RMMAPI + 'records/fields').subscribe({
next: (res) => {
this.setFields(this.toFieldItems(res));
this.setFields(res);
},
error: (err) => {
console.error(err);
Expand All @@ -83,32 +83,4 @@ export class SearchfieldsListService {
}
})
}

/**
* Advanced Search fields dropdown
*/
toFieldItems(fields: any[]): SelectItem[] {
// let items: SelectItem[] = [];
// items.push({ label: this.ALL, value: 'searchphrase' });
let fieldItems: SelectItem[] = [];
for (let field of fields) {
if (_.includes(field.tags, 'searchable')) {
let dup = false;
//For some reason, the filter function does not work for fields. Have to use this loop...
for(let item of fieldItems){
if(item.label == field.label && item.value == field.name.replace('component.', 'components.')){
dup = true;
break;
}
}

if(!dup){
fieldItems.push({ label: field.label, value: field.name.replace('component.', 'components.') });
}
}
};
fieldItems = _.sortBy(fieldItems, ['label', 'value']);

return fieldItems;
}
}
4 changes: 2 additions & 2 deletions angular/src/assets/environment.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"SERVERBASE": "http://data.nist.gov/",
"RMMAPI": "http://data.nist.gov/rmm/",
"SERVERBASE": "https://data.nist.gov/",
"RMMAPI": "https://data.nist.gov/rmm/",
"SDPAPI": "http://localhost:5555/",
"PDRAPI": "http://localhost:4200/od/id/",
"DISTAPI": "http://data.nist.gov/od/ds/",
Expand Down

0 comments on commit 0f513a0

Please sign in to comment.