Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching by multiple fields using meteor-easy-search

Tags:

search

meteor

I'm trying to implement a search by two db fields using meteor-easy-search package, however, I can't seem to find a way of doing it. Here is the problem:

I have a schema:

{
  name: String,
  location: String
}

I have two input fields on my form:

<input type="text" name="name">
<input type="text" name="location">

EasySearch provides a way of searching only by a single value:

 EasySearch.search('people', name, .....

Is there a way I can pass an Object to search method, so I can write my own 'query' inside of EasySearch.createSearchIndex()?

Moreover, I will need to convert "location" into a geo-spiral index and search for "a name within a radius of this location"

I know this can be done directly with MongoDB or ElasticSearch, but I would like to roll with meteor-easy-search, if possible.

like image 263
Michael Khait Avatar asked Nov 10 '22 12:11

Michael Khait


1 Answers

From the meteor-easy-search documentation, you can initialize a default query in the EasySearch.createSearchIndex() call and also add several search fields, like this:

EasySearch.createSearchIndex('people', {
  'field' : ['name', 'location'],
  'collection' : People,
  'limit' : 20,
  'use' : 'elastic-search'
  'props' : {
    'anyField' : true
  },
  'query' : function (searchString, opts) {
    // Default query that is used for searching
    var query = EasySearch.getSearcher(this.use).defaultQuery(this, searchString);

    return query;
  }
});
like image 112
Val Avatar answered Nov 15 '22 05:11

Val