Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception while invoking method 'search.source' Error: Match error: Failed Match.OneOf or Match.Optional validation #47

Open
achirkof opened this issue Nov 17, 2015 · 2 comments

Comments

@achirkof
Copy link

Hello. I'm trying to implement this package but have an error:

Exception while invoking method 'search.source' Error: Match error: Failed Match.OneOf or Match.Optional validation
    at check (packages/check/match.js:33:1)
    at [object Object]._.extend._getFindOptions (packages/mongo/collection.js:248:1)
    at [object Object]._.extend.find (packages/mongo/collection.js:284:1)
    at [object Object].<anonymous> (server/search-source.js:7:1)
    at [object Object].getSourceData (packages/meteorhacks_search-source/lib/server.js:65:1)
    at [object Object].Meteor.methods.search.source (packages/meteorhacks_search-source/lib/server.js:18:1)
    at maybeAuditArgumentChecks (livedata_server.js:1698:12)
    at livedata_server.js:708:19
    at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
    at livedata_server.js:706:40
Sanitized and reported to the client as: Match failed [400]

Here is my code.
Client

var options = {
    keepHistory: 1000 * 60 * 5,
    localSearch: true
};
var fields = ['exerciseName', 'exerciseDesc'];

ExercisesSearch = new SearchSource('exercises', fields, options);

Server

SearchSource.defineSource('exercises', function(searchText, options) {
    //var options = {sort: {isoScore: -1}, limit: 20};

    if(searchText) {
        var regExp = buildRegExp(searchText);
        var selector = {exerciseName: regExp, exerciseDesc: regExp};
        return Exercises.find(selector, options).fetch();
    } else {
        return Exercises.find({}, options).fetch();
    }
});

function buildRegExp(searchText) {
    var words = searchText.trim().split(/[ \-\:]+/);
    var exps = _.map(words, function(word) {
        return "(?=.*" + word + ")";
    });
    var fullExp = exps.join('') + ".+";
    return new RegExp(fullExp, "i");
}
@achirkof
Copy link
Author

The problem is in options parameter here:

        return Exercises.find(selector, options).fetch();
    } else {
        return Exercises.find({}, options).fetch();

I don't really know why, but when I remove it everything working fine.

@vladejs
Copy link

vladejs commented Nov 19, 2015

you are passing on options variable a property that hasn't the expected type.

It happened to me when i was passing a limit parameter within my helper method of type string instead of an integer.

Put a console.log(options,selector) on your server method to identify what variable has it's wrong data type. In my case the query looked like:

cursor = Collection.find(selector, {limit : '' })

where limit should be an integer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants