algoliasearch-client-javascript
algoliasearch-client-javascript copied to clipboard
Typeahead attributeName to obj.value mapping
instead of setting the value of obj (obj.value) equal to the first match, would it make more sense to allow an argument in the constructor to explicitly the set the mapping between the propertyName and the object.value so that the order in which the object attributes are created in the index does not determine how the object.value <--> attributeName mapping is determined?
// Method used by Typeahead.js.
get: function(query, processRemoteData, that, cb, suggestions) {
self = this;
this.search(query, function(success, content) {
if (success) {
for (var i = 0; i < content.hits.length; ++i) {
// Add an attribute value with the first string
var obj = content.hits[i];
var found = false;
if (typeof obj.value === 'undefined') {
for (var propertyName in obj) {
if (!found && obj.hasOwnProperty(propertyName) && typeof obj[propertyName] === 'string') {
obj.value = obj[propertyName];
found = true;
}
}
}
suggestions.push(that._transformDatum(obj));
}
cb && cb(suggestions);
}
}, self.typeAheadArgs);
return true;
},
Yes you are right. I have just added a new parameter in getTypeaheadTransport function to specify the propertyName to use.