matteodem / meteor-easy-search

Easy-to-use search for Meteor with Blaze Components
MIT License
437 stars 68 forks source link

Getting single search box to search multiple fields #490

Closed jasonnmark closed 8 years ago

jasonnmark commented 8 years ago

I'm using easy search on the following schema

Contacts = new Mongo.Collection('contacts'),
  ContactsIndex = new EasySearch.Index({
    collection: Contacts,
    fields: ['firstName','lastName'],
    engine: new EasySearch.Minimongo()
  });
    firstName: {
        optional: true,
        type: String      
    },

    lastName: {
        optional: true,
        type: String
    },

I want to find the contact named Jason Mark. If I search on "Jason" it finds it, if I search on "Mark" it finds it, but if I search on both it doesn't. I tried making a new combined field to search on but if it doesn't stay up to date. If I update the first name then the last name becomes "undefined" and vice versa.

    seachOnMe: {
        type: String,
        optional: true,
        autoValue: function() {
                return this.field("firstName").value + ' ' + this.field("lastName").value;
        }
},

I feel like I'm probably missing something simple... please advise.

matteodem commented 8 years ago

There's multiple ways how to handle this:

I'll add a task to add a recipe on what to do with composite fields, hopefully that'll be also of help.