对应第一篇文章api的编写

 1 router.get('/api/tags/search/:list/:key/:page', function(req, res) {
 2     if(_.isEmpty(req.params.key)) {
 3       res.json({items:null});
 4     } else {
 5       var key = urlencode.decode(req.params.key);
 6 
 7       var page = parseInt(req.params.page);
 8       if(!page) page = 0;
 9 
10       var filter = {};
11 
12       if(req.params.list != 'all')
13         filter = {term: {list: req.params.list}};
14 
15       Tag.search({
16         filtered: {
17           query: {query_string: {query:key}},
18           filter: filter
19         }
20       }, {from: page * 40, size: 40}, function (err, results) {
21         var items = results ? results.hits.hits : [];
22         var total = results ? results.hits.total : 0;
23 
24         res.json({items: items, total:total});
25       });
26     }
27   });

search()方法不知道从哪里来的,这个方法接受了三个参数:

1、

1 filtered: {
2           query: {query_string: {query:key}},
3           filter: filter
4         }

2、

{from: page * 40, size: 40}

3、

function (err, results) {
        var items = results ? results.hits.hits : [];
        var total = results ? results.hits.total : 0;

        res.json({items: items, total:total});
      }

静态方法中没有此方法;

此为问题

posted @ 2015-10-26 15:09  挥刀  阅读(155)  评论(0编辑  收藏  举报