zoukankan      html  css  js  c++  java
  • 对应第一篇文章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});
          }

    静态方法中没有此方法;

    此为问题

    坚持下去就能成功
  • 相关阅读:
    PostgreSQL数据损坏与checksum
    go get命令无响应解决方法
    vscode离线安装插件
    windows搭建Go语言环境
    centos7安装zabbix 5.0
    搭建人生重开模拟器
    博客园增加打赏
    记一次halo报错
    VM operation inconsistent with current state
    nextcloud安装onlyoffice
  • 原文地址:https://www.cnblogs.com/suoking/p/4911284.html
Copyright © 2011-2022 走看看