Skip to content

Commit

Permalink
fix(Search): Change mapping of flattened dataset
Browse files Browse the repository at this point in the history
When flattening the dataset for indexing map a field's displayName
to its value using the path array rather than using the displayName.
This handles cases where the displayName is being used to actually
change the name to something semantically meaningfulrather than as
a way to alias dot notation.
Fixes IQTLabs#300.
  • Loading branch information
rashley-iqt committed May 9, 2019
1 parent 012bfaa commit 596121b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/epics/index-dataset-epic.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { mergeMap, map } from 'rxjs/operators';

import { configurationFor } from "domain/dataset";

const getValue = require("get-value");
const lunr = require("lunr");

const BUILD_INDICES = "BUILD_INDICES";
Expand Down Expand Up @@ -73,8 +72,8 @@ const flattenDataset = (ds, cfg) => {
for(var f in cfg.fields){
var field = cfg.fields[f];

var name = field.displayName
item[name] = getValue(ds[key], field.displayName);
var name = field.displayName.toLowerCase();
item[name] = getValueByPath(ds[key], field.path);
}
flattened.push(item);
}
Expand All @@ -85,7 +84,7 @@ const generateIndex = (payload) => {
let indices = [];
Object.keys(payload.datasets).forEach((owner) => {
const dataset = payload.datasets[owner].dataset;
const configuration = !isNil(payload.datasets[owner].configuration) && !isEmpty(payload.datasets[owner].configuration)
const configuration = !isNil(payload.datasets[owner].configuration) && !isEmpty(payload.datasets[owner].configuration)
? payload.datasets[owner].configuration : configurationFor(dataset);
var flat = flattenDataset(dataset, configuration);
const idx = lunr(function () {
Expand All @@ -103,6 +102,19 @@ const generateIndex = (payload) => {
return indices;
};

const getValueByPath = (object, path) => {
if(object && path.length > 0){
let current = object[path[0]];
for(var i = 1; i < path.length; i++){
current = current[path[i]]
}
return current;
}
else{
return null;
}
}

export default indexDatasetEpic;

export { buildIndices, searchReducer, getSearchIndex, removeSearchIndex, getSearchIndices, setSearchResults, getSearchResults, getQueryString };
2 changes: 1 addition & 1 deletion src/features/dataset-controls/DatasetControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ if (host.indexOf(':') > -1) {

var POSEIDON_DATASET = {
name: "Poseidon Network",
url: "http://"+hostname+":"+port+"/v1/network"
url: "http://"+hostname+":5000/v1/network"
};

Modal.setAppElement('#root');
Expand Down

0 comments on commit 596121b

Please sign in to comment.