Hello,
I recently decided to use elasticSearch in my app. Which has changed a lot of things at the server and the client.
In order to display “projects” , I get an array of objects, which is no longer a mongo cursor. So I 'm not able to use query.observe () on my result like before.
Server, before elasticSearch :
Meteor.publish('projects', function(slider, search) {
// console.log(slider + ' ' + search);
var options = {
//something
};
var regExp = buildRegExp(search);
var selector = {
//something
};
return Projects.find(selector, options);
});
Then I used query.observe () to display items on a map :
Tracker.autorun(function() {
var query = Projects.find();
query.observe({
added: function(document) {
//something
},
removed: function(oldDocument) {
//something
}
});
});
Now, with elasticSearch, i create a SearchSource on the server (i’m using search-source extension) :
SearchSource.defineSource('projects', function(searchText, options) {
Meteor._sleepForMs(1000);
var words = searchText.trim().split(" ");
var lastWord = words[words.length -1];
var slider = options.slider;
var query = {
"bool": {
"must": [
{
"bool": {
"should": [
{"match": {"name": {"query": searchText}}},
{"prefix": {"name": lastWord}},
{"match": {"architect": {"query": searchText}}},
{"prefix": {"architect": lastWord}},
{"fuzzy": { "name" : searchText }},
{"fuzzy": { "architect" : searchText }}
]
}
}
],
"should": [
{"match_phrase_prefix": {"name": {"query": searchText, slop: 5}}},
{"match_phrase_prefix": {"architect": {"query": searchText, slop: 5}}}
]
}
};
var result = EsClient.search({
index: "meteor",
type: "projects",
body: {
query: query
}
});
var data = result.hits.hits.map(function(doc) {
var source = _.clone(doc._source);
source._score = doc._score;
source._id = doc._id; // <- add this line
return source;
});
// getting the metadata
var metadata = {
total: result.hits.total,
took: result.took
};
// return both data and metadata
return {
data: data,
metadata: metadata
};
});
Then, now… how can I display my projects reactivly on a map ?
With search-source, i can get the projects on the client with :
var projectsArray = ProjectSearch.getData();
Which returns this kind of array :
http://img15.hostingpics.net/pics/625588objects.jpg
Is there a way to continue using query.observe () on this type of result ? How else do ?