Code Monkey home page Code Monkey logo

Comments (14)

matteodem avatar matteodem commented on May 17, 2024

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.

MatthiasEckhart avatar MatthiasEckhart commented on May 17, 2024

Thank you so much!

from meteor-easy-search.

Pushplaybang avatar Pushplaybang commented on May 17, 2024

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.

erasaur avatar erasaur commented on May 17, 2024

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.

MatthiasEckhart avatar MatthiasEckhart commented on May 17, 2024

Great explanation @erasaur. That should solve your problem @Pushplaybang.

from meteor-easy-search.

Pushplaybang avatar Pushplaybang commented on May 17, 2024

Will give it a go and report back! thanks for the incredibly quick response.

P:)

from meteor-easy-search.

Pushplaybang avatar Pushplaybang commented on May 17, 2024

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.

erasaur avatar erasaur commented on May 17, 2024

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.

wbashir avatar wbashir commented on May 17, 2024

@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.

Pushplaybang avatar Pushplaybang commented on May 17, 2024

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.

Pushplaybang avatar Pushplaybang commented on May 17, 2024

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.

erasaur avatar erasaur commented on May 17, 2024

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.

Pushplaybang avatar Pushplaybang commented on May 17, 2024

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.

Pushplaybang avatar Pushplaybang commented on May 17, 2024

PS: the search stuff is in the collections.js file, everything else is reasonably easy to navigate

from meteor-easy-search.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.