I am using matteodem:easy-search and I am trying to limit the results to a specific email address.
Here is my code to create the index
OpportunitiesIndex = new EasySearch.Index({
collection: Opportunities,
fields: ['brand','name','city','description','user'],
engine: new EasySearch.MongoTextIndex({
selector: function (searchObject, options, aggregation) {
// retrieve the default selector
selector = this.defaultConfiguration().selector(searchObject, options, aggregation);
selector.user = "Kenny4444@hotmail.com";
console.log(selector.user);
console.log(selector);
return selector;
}
}),
name: 'myAwesomeIndex',
permission: (options) => {
return true; // always return true or false here
}
});
Here is my client code:
"click .search": function(event) {
event.preventDefault();
Tracker.autorun(function () {
cursor = OpportunitiesIndex.search("Cost"); // search all docs that contain "Marie" in the name or score field
console.log(cursor.fetch()); // log found documents with default search limit
console.log(cursor.count()); // log count of all found documents
});
}
When i call the search function it returns nothing. If i take the selector out of the index creation it will return values just fine (just not filtered by email). I was looking at the output of the selector and its printing out the following:
db.opportunities.find({ '$text': { '$search': 'Cost' }, user: 'Kenny4444@hotmail.com' }
I typed that into a mongo shell and it returned no results.
But the following worked just fine in Mongo
db.opportunities.find({ , user: 'Kenny4444@hotmail.com','$text': { '$search': 'Cost' } })
Any way anyone can see to get these switched around so that this will work?
Thanks!
@matteodem