2014-12-10 69 views
0

我用下面的包在我的項目 - https://github.com/matteodem/meteor-easy-search流星簡易搜索包裝定製蒙戈選擇查詢

有沒有人使用它,並能夠爲查詢參數設置自定義蒙戈選擇?排行榜的例子對我來說不是很清楚。我需要能夠流星用戶ID傳遞到:

EasySearch.createSearchIndex('producers', { 
    'collection': Producers, 
    'field': ['name', 'producerIdNumber', 'blocksCount', 'totalHectares', 'totalArea'], 
    'limit': 8, 
    'use' : 'mongo-db', 
    'sort': function() { 
     return { 'created': -1, 'name': -1 }; 
    }, 
    'query': function() { 
     var selector = {}; 
     return selector 
    } 
}); 

如何傳遞或得到流星用戶ID? EasySearch.createSearchIndex函數在服務器和客戶端上運行。

回答

1

我沒有你的問題的答案 - 但我可能能指出你在正確的方向。如果您使用meteor-accounts包,並且您需要將用戶ID從Meteor.users()集合中提取出來 - 您首先必須發佈您的用戶。

在服務器的代碼 - >

Meteor.publish(null, function() { 
    return Meteor.users.find({}, { 
    fields: { 
     username: 1, 
     profile: 1 
    } 
    }); 
}); 

在客戶端上,你應該能夠返回Meteor.users.find()或findOne()來獲取一個用戶ID。不是完整的答案,但可能有所幫助?

0

我能做到這一點,像這樣

'query': function(searchString, opts) { 
     // Default query that will be used for the mongo-db selector 
     var query = EasySearch.getSearcher(this.use).defaultQuery(this, searchString); 

     if (this.props.formName != '') { 
      query.formName = this.props.formName; 
     } 

     if (this.props.producerId != '') { 
      query.producerId = this.props.producerId; 
     } 

     if (this.props.blockUnitCodeSubCode != '') { 
      query.blockUnitCodeSubCode = this.props.blockUnitCodeSubCode; 
     } 

     if (this.props.created.length != 0) { 
      query.created = {$gte:new Date(this.props.created[0]), $lt:new Date(this.props.created[1])}; 
     }