2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
import { Filter, Value} from '../../searchPages/searchUtils/searchHelperClasses.class';
|
2023-12-06 12:53:06 +01:00
|
|
|
import { SearchFields} from '../../utils/properties/searchFields';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
export class RefineResultsUtils {
|
|
|
|
|
|
|
|
|
2019-07-15 18:11:07 +02:00
|
|
|
public static parse (data, fields:string[], entityType:string, usedBy: string="search"):Filter[] {
|
2017-12-19 13:53:46 +01:00
|
|
|
// var data = this.json.refineReuslts;
|
|
|
|
|
|
|
|
var searchFields:SearchFields = new SearchFields();
|
|
|
|
var filters:Filter[] = [];
|
2020-01-31 16:12:51 +01:00
|
|
|
if(data && fields){
|
2017-12-19 13:53:46 +01:00
|
|
|
for(let j=0; j<fields.length; j++) {
|
|
|
|
|
|
|
|
var filter:Filter = new Filter();
|
2022-05-30 11:44:39 +02:00
|
|
|
let fieldInfo = searchFields.getField(fields[j],entityType);
|
|
|
|
filter.title = fieldInfo?fieldInfo.name:"UNDEFINED";
|
2017-12-19 13:53:46 +01:00
|
|
|
filter.filterId = fields[j];
|
|
|
|
filter.originalFilterId = fields[j];
|
2022-05-30 11:44:39 +02:00
|
|
|
filter.filterType = fieldInfo?fieldInfo.filterType:"checkbox";
|
|
|
|
filter.type = fieldInfo?fieldInfo.type:"keyword";
|
2019-09-12 12:30:48 +02:00
|
|
|
filter.filterOperator = searchFields.getFieldOperator(fields[j]);
|
2020-07-14 17:18:14 +02:00
|
|
|
filter.radioValue = "";
|
2020-02-17 15:19:14 +01:00
|
|
|
//console.info("filter.title: "+filter.title+" filter.filterType: "+filter.filterType);
|
2019-07-15 18:11:07 +02:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
let field = data[fields[j]];
|
|
|
|
if(field){
|
|
|
|
for(let i=0; i<field.length; i++) {
|
|
|
|
var value:Value = new Value();
|
|
|
|
value.name = field[i].name;
|
|
|
|
value.name =this.removePartAfterCharacters(value,"||");
|
|
|
|
value.number = field[i].count;
|
|
|
|
value.id = field[i].id;
|
|
|
|
if(RefineResultsUtils.includeValue(value)){
|
|
|
|
filter.values.push(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2020-02-17 15:19:14 +01:00
|
|
|
|
|
|
|
filters.push(filter);
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filters;
|
|
|
|
}
|
|
|
|
private static includeValue (field):boolean {
|
2020-10-20 16:47:54 +02:00
|
|
|
if( !field || !field.name || field.name == "unidentified" || field.name == "Undetermined" ){
|
2017-12-19 13:53:46 +01:00
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
private static removePartAfterCharacters(field, characters):string {
|
|
|
|
if( field.name.indexOf(characters) !=-1){
|
|
|
|
return field.name.split(characters)[0];
|
|
|
|
|
|
|
|
}
|
|
|
|
return field.name;
|
|
|
|
}
|
|
|
|
public static inParenthesisThePartAfterCharacters(field, characters):string {
|
|
|
|
if( field.name.indexOf(characters) !=-1){
|
|
|
|
return field.name.split(characters)[0]+" ("+field.name.split(characters)[1]+")";
|
|
|
|
|
|
|
|
}
|
|
|
|
return field.name;
|
|
|
|
}
|
2020-02-04 14:27:42 +01:00
|
|
|
public static keepPartAfterCharacters(name, characters):string {
|
|
|
|
if( name.indexOf(characters) !=-1){
|
|
|
|
return name.split(characters)[1];
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|