Comments (14)
yes it is, that's what the query
parameter is used for.
Basically you could do it like this
EasySearch.createSearchIndex('users', {
'field' : ['username'],
'collection' : Users,
'limit' : 20,
'query' : function (searchString) {
// Default query that will be used for searching
var query = EasySearch.getSearcher('mongo-db').defaultQuery(this, searchString);
// Your custom logic
query.username = { $ne: Meteor.user().username };
return query;
}
});
You get the default search operation done with the first method (defaultQuery) and modify to your needs after that.
from meteor-easy-search.
Thank you so much!
from meteor-easy-search.
Hi Matthias
seem to be having a little difficulty with this one. I tried the syntax above to no avail. and then I tried with the following syntax, further with no difference.
'query' : function (searchString) {
// Default query that will be used for searching
var query = EasySearch.getSearcher('mongo-db').defaultQuery(this, searchString);
// custom logic, using natural key : email
query.profile = {primaryemail: {$ne: Meteor.user().profile.primaryemail} };
return query;
}
any help would be great. Basically I'm wanting to search the user collection and I'm trying to exclude the current logged in user.
Cheers.
Paul
from meteor-easy-search.
Hey @Pushplaybang, can you try replacing this line:
query.profile = {primaryemail: {$ne: Meteor.user().profile.primaryemail} };
with this:
query['profile.primaryemail'] = {$ne: Meteor.user().profile.primaryemail};
I think what might be happening is that you're looking up users whose profile matches the object {primaryemail: {$ne: Meteor.user().profile.primaryemail} }
, when you really just want to lookup the field profile.primaryemail
.
from meteor-easy-search.
Great explanation @erasaur. That should solve your problem @Pushplaybang.
from meteor-easy-search.
Will give it a go and report back! thanks for the incredibly quick response.
P:)
from meteor-easy-search.
No Joy I'm afraid, heres the whole snippet that I'm using :
/* Search Index */
EasySearch.createSearchIndex('users', {
'field' : ['username',
'profile.name',
'profile.primaryemail',
'services.google.name',
'services.google.email',
], // required, searchable field(s)
"use" :"mongo-db", // Search Engine
'collection' : Meteor.users, // required, Mongo Collection
'limit' : 10, // not required, default is 10,
'query' : function (searchString) {
// Default query that will be used for searching
var query = EasySearch.getSearcher('mongo-db').defaultQuery(this, searchString);
// custom logic, using natural key : email
query['profile.primaryemail'] = {$ne: Meteor.user().profile.primaryemail};
return query;
}
});
I'm able to exclude it on the front end, which in this instance isn't terrible, but I would like to solve this to get the optimal pattern down for excluding records from search and understand what I'm doing wrong.
Thanks again.
Paul
from meteor-easy-search.
Hm.. It's hard to tell what's wrong with the query (if anything at all). Are you sure Meteor.user().profile.primaryemail
is defined?
from meteor-easy-search.
@Pushplaybang, as @erasaur mentioned, I don't think Meteor.user()
is available to use in the query
function, you can access the current user this way instead.
var user = Meteor.users.findOne(this.publishScope.userId);
from meteor-easy-search.
Hey Guys
Primary email is definitely defined, the app sets it when creating a user, I've also checked the db with robomongo, to make sure all my fields were correctly defined and populated.
I'll ry out warsamebashir answer and see what happens.
Thanks guys.
Paul
from meteor-easy-search.
So, no luck so far, could there be an issue due to the fact that I'm using this with the Meteor.users collection?
I tried warsamebashirs answer with no luck, I then replaced the dynamic value with hard ones straight from the database and still no dice.
I'm not really sure how to diagnose the problem further.
any ideas?
from meteor-easy-search.
There should be no problem with using the Meteor.users
collection. I just tested it and it works on my end. Can you provide a reproduction repo for us to look at?
from meteor-easy-search.
super weird. I presume I'm probably doing something ignorant then.
I pushed it up to github. https://github.com/Pushplaybang/chat-app
If you have a moment to have a look I'd greatly appreciate it.
from meteor-easy-search.
PS: the search stuff is in the collections.js file, everything else is reasonably easy to navigate
from meteor-easy-search.
Related Issues (20)
- Collation feature of MongoDB HOT 4
- Top-level dependency conflict when moving to Meteor 1.6.1 HOT 5
- "Match error: Expected Collection", path: "" HOT 2
- Compatibilty with Elasticsearch 6.3 HOT 1
- Does this still work with collection-helpers for composite fields? HOT 6
- "namespace is too long" HOT 2
- Documentation missing for elastic search HOT 5
- ifSearching doesn't seem to work HOT 2
- limiting the number of returned values HOT 3
- multiple index search with ElasticSearch? HOT 1
- Error in documentation for selectors HOT 1
- Is it possible to get ifSearching directly from the index? HOT 1
- facets that only show results that valid values HOT 1
- populating easy search input and getting search results on page render HOT 1
- Easy-search nested fields as props HOT 1
- Trying to access 'resultsHandle' variable before initialization. HOT 13
- After upgrade to [email protected] new Index fails with "Match error: Expected particular constructor" when using Meteor.users HOT 5
- Exclude html from search
- How to search from the start of the searchString? HOT 2
- Support for Meteor 3.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meteor-easy-search.