gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 21:39:22 27 4
gpt4 key购买 nike

我正在尝试使用 meteor-easy-search 实现两个数据库字段的搜索
包,但是,我似乎找不到这样做的方法。这是问题所在:

我有一个架构:

{
name: String,
location: String
}

我的表单上有两个输入字段:
<input type="text" name="name">
<input type="text" name="location">

EasySearch 提供了一种仅通过单个值进行搜索的方法:
 EasySearch.search('people', name, .....

有没有办法可以将对象传递给搜索方法,以便我可以在 EasySearch.createSearchIndex() 中编写自己的“查询”?

此外,我需要将“位置”转换为地理螺旋索引并搜索“该位置半径范围内的名称”

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

最佳答案

来自 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;
}
});

关于使用meteor-easy-search按多个字段进行搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30496210/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com