Mongodb 在Meteor中实现全局搜索(在多个集合中搜索)的最佳方法是什么
我需要添加全局搜索,这将在一些集合中搜索,例如客户、订单、项目。。。把所有的答案都放在一张单子上 我已经看过EasySearch和meteorhacks:SearchSource,但它们当时只支持一个集合中的搜索Mongodb 在Meteor中实现全局搜索(在多个集合中搜索)的最佳方法是什么,mongodb,meteor,Mongodb,Meteor,我需要添加全局搜索,这将在一些集合中搜索,例如客户、订单、项目。。。把所有的答案都放在一张单子上 我已经看过EasySearch和meteorhacks:SearchSource,但它们当时只支持一个集合中的搜索 有人已经解决了这个问题吗?什么是最好的开始方式?经过几天的研究,我终于发现EasySearch提供了对多个收藏的搜索,它只是隐藏在文档中 所需要的是: EasySearch.createSearchIndex('collection1', { 'field' : ['name']
有人已经解决了这个问题吗?什么是最好的开始方式?经过几天的研究,我终于发现EasySearch提供了对多个收藏的搜索,它只是隐藏在文档中 所需要的是:
EasySearch.createSearchIndex('collection1', {
'field' : ['name'],
'collection' : Collection1,
'use' : 'minimongo',
'limit' : 20,
});
EasySearch.createSearchIndex('collection2', {
'field' : ['name', 'text'],
'collection' : Collection2,
'use' : 'minimongo',
'limit' : 20,
});
Template.yourTemplate.indexes = ['players', 'cars'];
HTML
HTML
for循环不起作用吗?不确定您试图完成什么,但是合并多个结果数组应该不会太难。您到底想对数据做什么?可能有很多好的选择,但很难说。在所有要搜索的密钥中,您是否有一些通用密钥?或者您正在寻找全文搜索?可能我的主要观点是询问是否有人已经为同时在多个集合中搜索实现了一些好的解决方案,就像EasySearch软件包为在一个集合中搜索所做的那样。也可能有人已经用我提到的软件包做了,因为他们有很好的建议。当然,我可以使用ElasticSearch或Mongos own search实现我自己的搜索,但是如果有人已经创建了own,为什么还要创建own呢?我无法在多个索引上进行搜索,而且我认为API已经改变了,例如,它现在是EasySearch.Input而不是esInput。我得到的只是一个错误:没有收到索引或索引数组:[object object],[object object][invalid configuration]。我已经读过关于这个问题的讨论,但无法理解这一点。使用indexes=索引只会给我一个不同的错误!有人可以发布一个使用新API的工作示例吗?我刚刚添加了一个更新的示例,它适用于我最新的EasySearch更改。我认为{{>EasySearch indexes=indexes attributes=attributes}}}需要是{>EasySearch.Input indexes=indexes attributes=attributes}?它应该是Collection1Index=new EasySearch.Index,而不是Collection1Index=EasySearch.Index
<div class="search-input">
<!-- indexes is a javascript array which holds 'players' and 'cars' -->
{{> esInput index=indexes placeholder="Search..." }}
</div>
<div class="results-wrapper">
{{#esEach index="players"}}
{{> player}}
{{/esEach}}
{{#esEach index="cars"}}
{{> car}}
{{/esEach}}
</div>
Collection1Index = EasySearch.Index({
'collection': Collection1,
'fields': ['name', 'description'],
'engine': new EasySearch.MongoDB()
});
Collection2Index = EasySearch.Index({
'collection': Collection2,
'fields': ['name', 'text'],
'engine': new EasySearch.MongoDB()
});
Template.yourTemplate.helpers ({
indexes: function() { return [Collection1Index, Collection2Index] }
attributes: function() { return {placeholder: "Search clients, orders and suppliers...", class: 'form-control'} }
Collection1Index: function () { return Collection1Index }
Collection2Index: function () { return Collection2Index }
});
<div class="search-input">
{{> EasySearch.Input indexes=indexes attributes=attributes }}
</div>
<div class="results-wrapper">
{{#EasySearch.Each index=Collection1Index}}
{{> player}}
{{/EasySearch.Each}}
{{#EasySearch.Each index=Collection2Index}}
{{> car}}
{{/EasySearch.Each}}
</div>