使用meteor-easy-search通过多个字段进行搜索

时间:2015-05-28 02:26:53

标签: search meteor

我尝试使用meteor-easy-search通过两个数据库字段实现搜索 但是,我似乎无法找到一种方法。这是问题所在:

我有一个架构:

{
  name: String,
  location: String
}

我的表单上有两个输入字段:

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

EasySearch提供了一种仅通过单一值搜索的方式:

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

有没有办法将Object传递给搜索方法,所以我可以编写自己的查询&#39;在EasySearch.createSearchIndex()里面?

此外,我需要转换&#34; location&#34;进入地理螺旋索引并搜索&#34;该位置半径范围内的名称&#34;

我知道这可以直接使用MongoDB或ElasticSearch完成,但如果可能的话,我想使用meteor-easy-search进行滚动。

1 个答案:

答案 0 :(得分:1)

meteor-easy-search documentation中,您可以在EasySearch.createSearchIndex()调用中初始化默认查询,还可以添加多个搜索字段,如下所示:

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;
  }
});
相关问题