matteodem / meteor-easy-search

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

Multiple keyword search #546

Closed AdrianAbba closed 7 years ago

AdrianAbba commented 7 years ago
export const Projects = new Mongo.Collection('projects');

projectIndex = new EasySearch.Index({
    collection: Projects,
    fields: ['title', 'subtitle','tags','jobs'],
    engine: new EasySearch.MongoDB({
      sort: function () {
        return { createdAt: -1 }
      },

    })
  });
Template.landingPage.helpers({
  index: function () {
    return [projectIndex];   
  },
  projectIndex: function () { return projectIndex; },

});

Single searches are working, like searching for the title, searching in tags, jobs etc. but only one keyword works. If i wanna search for a project with many keywords, like the title, tags etc. what should i do :x?

i have to use something like an logical AND`?

AdrianAbba commented 7 years ago

i did smt like this now:

selector: function(searchObject, options, aggregation) {
            var selector, tags2;

            selector = {'$and': [] }; // initialzie selector 
            console.log(searchObject);
            tags2=searchObject.tags.split(" "); // tags is now an Array

            _.each(tags2, function(tag, index) {
                selector.$and.push({tags: tag});
                selector.$and.push({title: tag});
                selector.$and.push({subtitle: tag});
                selector.$and.push({jobs: tag});

            });
            console.log(selector);
            return selector;

        }

but its not working very well.

the selector returns this:

I20161104-16:58:32.297(1)? { title: 'Modern Auto',
I20161104-16:58:32.311(1)?   subtitle: 'Modern Auto',
I20161104-16:58:32.312(1)?   tags: 'Modern Auto',
I20161104-16:58:32.314(1)?   jobs: 'Modern Auto' }
I20161104-16:58:32.320(1)? { '$and':
I20161104-16:58:32.321(1)?    [ { tags: 'Modern' },
I20161104-16:58:32.322(1)?      { title: 'Modern' },
I20161104-16:58:32.323(1)?      { subtitle: 'Modern' },
I20161104-16:58:32.325(1)?      { jobs: 'Modern' },
I20161104-16:58:32.325(1)?      { tags: 'Auto' },
I20161104-16:58:32.327(1)?      { title: 'Auto' },
I20161104-16:58:32.329(1)?      { subtitle: 'Auto' },
I20161104-16:58:32.330(1)?      { jobs: 'Auto' } ] }

the logical syntax doesnt work very well......... any ideas :D?

matteodem commented 7 years ago

Closing as it's duplicate of #546

nasuke0302 commented 5 years ago

umm dude this is #546

matteodem commented 5 years ago

Oh wow... haha.

Yeah I think this is a matter of constructing a good mongodb selector or using something like ElasticSearch which is optimized for searching.