草庐IT

Elasticsearch 核心技术(九):搜索结果处理(分页、排序、指定返回字段、去重、高亮显示)

水滴技术 2023-10-10 原文

❤️ 博客主页:水滴技术
🚀 支持水滴:点赞👍 + 收藏⭐ + 留言💬
🌸 订阅专栏:大数据核心技术从入门到精通

文章目录


大家好,我是水滴~~

本篇主要讲述 Elasticsearch 关于搜索结果的处理,主要内容有:分页查询、结果排序、指定返回字段、去重、高亮显示等。

一、分页

Elasticsearch 对所有查询都进行了分页,默认返回前 10 条数据。如果想要查询更多的数据,就需要使用分页参数了。Elasticsearch 提供了两个参数 fromsize 来控制分页结果。

  • from 表示从第几条数据开始查询,默认值为 0

  • size 表示返回数据量大小,默认值为 10

注:分页也有一定的限制,不能查询 from + size 超过 10000 的数据。

1.1 示例:查询第 1 页,每页大小为 5

GET /mt_product/_search
{
 "query": {
   "match_all": {}
 },
 "from": 0,
 "size": 5
}

查询结果:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 12,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "id" : 1,
          "name" : "招牌海苔单人餐",
          "tags" : [
            "寿司"
          ],
          "price" : 9.9,
          "sales" : 1000,
          "score" : 4.7,
          "store_id" : 1,
          "store_name" : "M多寿司",
          "create_time" : "2023-01-18 08:01:00"
        }
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "id" : 2,
          "name" : "1-2人招牌双拼套餐",
          "tags" : [
            "寿司"
          ],
          "price" : 18.9,
          "sales" : 1200,
          "score" : 4.8,
          "store_id" : 1,
          "store_name" : "M多寿司",
          "create_time" : "2023-01-18 08:02:00"
        }
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 1.0,
        "_source" : {
          "id" : 3,
          "name" : "三文鱼寿司",
          "tags" : [
            "寿司,鱼肉"
          ],
          "price" : 16.9,
          "sales" : 820,
          "score" : 4.9,
          "store_id" : 2,
          "store_name" : "爱食寿司",
          "create_time" : "2023-01-18 08:03:00"
        }
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "4",
        "_score" : 1.0,
        "_source" : {
          "id" : 4,
          "name" : "极上全品寿司套餐",
          "tags" : [
            "寿司"
          ],
          "price" : 25,
          "sales" : 1500,
          "score" : 4.6,
          "store_id" : 2,
          "store_name" : "爱食寿司",
          "create_time" : "2023-01-18 08:04:00"
        }
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "5",
        "_score" : 1.0,
        "_source" : {
          "id" : 5,
          "name" : "劲脆鸡腿汉堡",
          "tags" : [
            "汉堡,鸡肉"
          ],
          "price" : 21.5,
          "sales" : 200,
          "score" : 4.5,
          "store_id" : 3,
          "store_name" : "肯德基",
          "create_time" : "2023-01-18 08:05:00"
        }
      }
    ]
  }
}

1.2 示例:查询第 2 页,每页大小为 5

GET /mt_product/_search
{
 "query": {
   "match_all": {}
 },
 "from": 5,
 "size": 5
}

查询结果:

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 12,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "6",
        "_score" : 1.0,
        "_source" : {
          "id" : 6,
          "name" : "香辣鸡腿汉堡",
          "tags" : [
            "汉堡,鸡肉"
          ],
          "price" : 21.5,
          "sales" : 98,
          "score" : 4.4,
          "store_id" : 3,
          "store_name" : "肯德基",
          "create_time" : "2023-01-18 08:06:00"
        }
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "7",
        "_score" : 1.0,
        "_source" : {
          "id" : 7,
          "name" : "20块香辣鸡翅",
          "tags" : [
            "鸡肉"
          ],
          "price" : 99,
          "sales" : 5,
          "score" : 4.8,
          "store_id" : 3,
          "store_name" : "肯德基",
          "create_time" : "2023-01-18 08:07:00"
        }
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "8",
        "_score" : 1.0,
        "_source" : {
          "id" : 8,
          "name" : "3层芝士年堡套餐",
          "tags" : [
            "汉堡"
          ],
          "price" : 29,
          "sales" : 4000,
          "score" : 4.9,
          "store_id" : 4,
          "store_name" : "汉堡王",
          "create_time" : "2023-01-18 08:08:00"
        }
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "9",
        "_score" : 1.0,
        "_source" : {
          "id" : 9,
          "name" : "霸道小酥鸡+薯霸王",
          "tags" : [
            "汉堡,鸡肉"
          ],
          "price" : 19,
          "sales" : 300,
          "score" : 4.2,
          "store_id" : 4,
          "store_name" : "汉堡王",
          "create_time" : "2023-01-18 08:09:00"
        }
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "10",
        "_score" : 1.0,
        "_source" : {
          "id" : 10,
          "name" : "双层原味板烧鸡腿麦满分四件套",
          "tags" : [
            "汉堡,鸡肉"
          ],
          "price" : 29,
          "sales" : 3000,
          "score" : 4.8,
          "store_id" : 5,
          "store_name" : "麦当劳",
          "create_time" : "2023-01-18 08:10:00"
        }
      }
    ]
  }
}

1.3 示例:查询第 3 页,每页大小为 5

GET /mt_product/_search
{
 "query": {
   "match_all": {}
 },
 "from": 10,
 "size": 5
}

查询结果:

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 12,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "11",
        "_score" : 1.0,
        "_source" : {
          "id" : 11,
          "name" : "火腿扒麦满分组合",
          "tags" : [
            "汉堡"
          ],
          "price" : 8,
          "sales" : 100000,
          "score" : 4.9,
          "store_id" : 5,
          "store_name" : "麦当劳",
          "create_time" : "2023-01-18 08:11:00"
        }
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "12",
        "_score" : 1.0,
        "_source" : {
          "id" : 12,
          "name" : "原味板烧鸡腿麦满组件",
          "tags" : [
            "汉堡,鸡肉"
          ],
          "price" : 9.9,
          "sales" : 140000,
          "score" : 4.9,
          "store_id" : 5,
          "store_name" : "麦当劳",
          "create_time" : "2023-01-18 08:12:00"
        }
      }
    ]
  }
}

二、排序

Elasticsearch 支持按指定的字段进行排序,使用 sort 参数来设置排序,排序字段也可以是多个。排序选项中正序使用 asc,倒序使用 desc

2.1 示例:按 id 正序排序

GET /mt_product/_search
{
 "query": {
   "match_all": {}
 },
 "size": 3,
 "sort": [
   {
     "id": {
       "order": "asc"
     }
   }
 ]
}

查询结果:

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 12,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : null,
        "_source" : {
          "id" : 1,
          "name" : "招牌海苔单人餐",
          "tags" : [
            "寿司"
          ],
          "price" : 9.9,
          "sales" : 1000,
          "score" : 4.7,
          "store_id" : 1,
          "store_name" : "M多寿司",
          "create_time" : "2023-01-18 08:01:00"
        },
        "sort" : [
          1
        ]
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : null,
        "_source" : {
          "id" : 2,
          "name" : "1-2人招牌双拼套餐",
          "tags" : [
            "寿司"
          ],
          "price" : 18.9,
          "sales" : 1200,
          "score" : 4.8,
          "store_id" : 1,
          "store_name" : "M多寿司",
          "create_time" : "2023-01-18 08:02:00"
        },
        "sort" : [
          2
        ]
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : null,
        "_source" : {
          "id" : 3,
          "name" : "三文鱼寿司",
          "tags" : [
            "寿司,鱼肉"
          ],
          "price" : 16.9,
          "sales" : 820,
          "score" : 4.9,
          "store_id" : 2,
          "store_name" : "爱食寿司",
          "create_time" : "2023-01-18 08:03:00"
        },
        "sort" : [
          3
        ]
      }
    ]
  }
}

2.2 示例:按 id 倒序排序

GET /mt_product/_search
{
 "query": {
   "match_all": {}
 },
 "size": 3,
 "sort": [
   {
     "id": {
       "order": "desc"
     }
   }
 ]
}

查询结果:

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 12,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "12",
        "_score" : null,
        "_source" : {
          "id" : 12,
          "name" : "原味板烧鸡腿麦满组件",
          "tags" : [
            "汉堡,鸡肉"
          ],
          "price" : 9.9,
          "sales" : 140000,
          "score" : 4.9,
          "store_id" : 5,
          "store_name" : "麦当劳",
          "create_time" : "2023-01-18 08:12:00"
        },
        "sort" : [
          12
        ]
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "11",
        "_score" : null,
        "_source" : {
          "id" : 11,
          "name" : "火腿扒麦满分组合",
          "tags" : [
            "汉堡"
          ],
          "price" : 8,
          "sales" : 100000,
          "score" : 4.9,
          "store_id" : 5,
          "store_name" : "麦当劳",
          "create_time" : "2023-01-18 08:11:00"
        },
        "sort" : [
          11
        ]
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "10",
        "_score" : null,
        "_source" : {
          "id" : 10,
          "name" : "双层原味板烧鸡腿麦满分四件套",
          "tags" : [
            "汉堡,鸡肉"
          ],
          "price" : 29,
          "sales" : 3000,
          "score" : 4.8,
          "store_id" : 5,
          "store_name" : "麦当劳",
          "create_time" : "2023-01-18 08:10:00"
        },
        "sort" : [
          10
        ]
      }
    ]
  }
}

三、指定返回字段

在实际的查询中,我们通过是有选择地返回我们想要的字段,这样会节省带宽和内存的使用。Elasticsearch 通过两个参数来指定返回字段:

  • fields:用来指定返回的字段

  • _source:将 _source 设为 false,表示不会返回所有完整文档数据(文档数据存在 _source 中)。

3.1 示例:只返回 id 和 name 字段

GET /mt_product/_search
{
  "query": {
    "match_all": {}
  },
  "size": 3,
  "fields": [
    "id",
    "name"
  ],
  "_source": false
}

查询结果:

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 12,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "fields" : {
          "name" : [
            "招牌海苔单人餐"
          ],
          "id" : [
            1
          ]
        }
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 1.0,
        "fields" : {
          "name" : [
            "1-2人招牌双拼套餐"
          ],
          "id" : [
            2
          ]
        }
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 1.0,
        "fields" : {
          "name" : [
            "三文鱼寿司"
          ],
          "id" : [
            3
          ]
        }
      }
    ]
  }
}

四、去重

当我们的索引中存在重复数据时,可以将其去重。Elasticsearch 通过 collapse 参数来实现去重,去重时需要指定字段。

4.1 示例:根据 store_id 字段去重

GET /mt_product/_search
{
  "query": {
    "match_all": {}
  },
  "collapse": {
    "field": "store_id"
  }
}

响应结果:

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 12,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "id" : 1,
          "name" : "招牌海苔单人餐",
          "tags" : [
            "寿司"
          ],
          "price" : 9.9,
          "sales" : 1000,
          "score" : 4.7,
          "store_id" : 1,
          "store_name" : "M多寿司",
          "create_time" : "2023-01-18 08:01:00"
        },
        "fields" : {
          "store_id" : [
            "1"
          ]
        }
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 1.0,
        "_source" : {
          "id" : 3,
          "name" : "三文鱼寿司",
          "tags" : [
            "寿司,鱼肉"
          ],
          "price" : 16.9,
          "sales" : 820,
          "score" : 4.9,
          "store_id" : 2,
          "store_name" : "爱食寿司",
          "create_time" : "2023-01-18 08:03:00"
        },
        "fields" : {
          "store_id" : [
            "2"
          ]
        }
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "5",
        "_score" : 1.0,
        "_source" : {
          "id" : 5,
          "name" : "劲脆鸡腿汉堡",
          "tags" : [
            "汉堡,鸡肉"
          ],
          "price" : 21.5,
          "sales" : 200,
          "score" : 4.5,
          "store_id" : 3,
          "store_name" : "肯德基",
          "create_time" : "2023-01-18 08:05:00"
        },
        "fields" : {
          "store_id" : [
            "3"
          ]
        }
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "8",
        "_score" : 1.0,
        "_source" : {
          "id" : 8,
          "name" : "3层芝士年堡套餐",
          "tags" : [
            "汉堡"
          ],
          "price" : 29,
          "sales" : 4000,
          "score" : 4.9,
          "store_id" : 4,
          "store_name" : "汉堡王",
          "create_time" : "2023-01-18 08:08:00"
        },
        "fields" : {
          "store_id" : [
            "4"
          ]
        }
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "10",
        "_score" : 1.0,
        "_source" : {
          "id" : 10,
          "name" : "双层原味板烧鸡腿麦满分四件套",
          "tags" : [
            "汉堡,鸡肉"
          ],
          "price" : 29,
          "sales" : 3000,
          "score" : 4.8,
          "store_id" : 5,
          "store_name" : "麦当劳",
          "create_time" : "2023-01-18 08:10:00"
        },
        "fields" : {
          "store_id" : [
            "5"
          ]
        }
      }
    ]
  }
}

五、高亮显示

Elasticsearch 可以将搜索关键字做高亮显示,可以指定高亮显示的字段,会在响应结果中对关键字加 <em> 标签,便于前端特殊处理。

5.1 示例:将 name 字段做高亮显示

GET /mt_product/_search
{
  "query": {
    "multi_match": {
      "query": "寿司",
      "fields": ["name", "tag"]
    }
  },
  "highlight": {
    "fields": {
      "name": {}
    }
  }
}

查询结果:

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.7955686,
    "hits" : [
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 1.7955686,
        "_source" : {
          "id" : 3,
          "name" : "三文鱼寿司",
          "tags" : [
            "寿司,鱼肉"
          ],
          "price" : 16.9,
          "sales" : 820,
          "score" : 4.9,
          "store_id" : 2,
          "store_name" : "爱食寿司",
          "create_time" : "2023-01-18 08:03:00"
        },
        "highlight" : {
          "name" : [
            "三文鱼<em>寿司</em>"
          ]
        }
      },
      {
        "_index" : "mt_product",
        "_type" : "_doc",
        "_id" : "4",
        "_score" : 1.6760855,
        "_source" : {
          "id" : 4,
          "name" : "极上全品寿司套餐",
          "tags" : [
            "寿司"
          ],
          "price" : 25,
          "sales" : 1500,
          "score" : 4.6,
          "store_id" : 2,
          "store_name" : "爱食寿司",
          "create_time" : "2023-01-18 08:04:00"
        },
        "highlight" : {
          "name" : [
            "极上全品<em>寿司</em>套餐"
          ]
        }
      }
    ]
  }
}


系列文章

🔥 Elasticsearch 核心技术(一):Elasticsearch 安装、配置、运行(Windows 版)
🔥 Elasticsearch 核心技术(二):elasticsearch-head 插件安装和使用
🔥 Elasticsearch 核心技术(三):Kibana 安装、配置、运行(Windows 版)
🔥 Elasticsearch 核心技术(四):索引管理、映射管理、文档管理(REST API)
🔥 Elasticsearch 核心技术(五):常用数据类型详解
🔥 Elasticsearch 核心技术(六):内置的 8 种分词器详解 + 代码示例
🔥 Elasticsearch 核心技术(七):IK 中文分词器的安装、使用、自定义字典
🔥 Elasticsearch 核心技术(八):常用 DSL 查询(全文搜索、精确匹配、布尔查询)

热门专栏

👍 《Python入门核心技术
👍 《IDEA 教程:从入门到精通
👍 《Java 教程:从入门到精通
👍 《MySQL 教程:从入门到精通
👍 《大数据核心技术从入门到精通

有关Elasticsearch 核心技术(九):搜索结果处理(分页、排序、指定返回字段、去重、高亮显示)的更多相关文章

  1. ruby - 如何指定 Rack 处理程序 - 2

    Rackup通过Rack的默认处理程序成功运行任何Rack应用程序。例如:classRackAppdefcall(environment)['200',{'Content-Type'=>'text/html'},["Helloworld"]]endendrunRackApp.new但是当最后一行更改为使用Rack的内置CGI处理程序时,rackup给出“NoMethodErrorat/undefinedmethod`call'fornil:NilClass”:Rack::Handler::CGI.runRackApp.newRack的其他内置处理程序也提出了同样的反对意见。例如Rack

  2. ruby-on-rails - 如何验证非模型(甚至非对象)字段 - 2

    我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss

  3. ruby-on-rails - form_for 中不在模型中的自定义字段 - 2

    我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢

  4. ruby-on-rails - 在 Rails 和 ActiveRecord 中查询时忽略某些字段 - 2

    我知道我可以指定某些字段来使用pluck查询数据库。ids=Item.where('due_at但是我想知道,是否有一种方法可以指定我想避免从数据库查询的某些字段。某种反拔?posts=Post.where(published:true).do_not_lookup(:enormous_field) 最佳答案 Model#attribute_names应该返回列/属性数组。您可以排除其中一些并传递给pluck或select方法。像这样:posts=Post.where(published:true).select(Post.attr

  5. ruby-on-rails - Nokogiri:使用 XPath 搜索 <div> - 2

    我使用Nokogiri(Rubygem)css搜索寻找某些在我的html里面。看起来Nokogiri的css搜索不喜欢正则表达式。我想切换到Nokogiri的xpath搜索,因为这似乎支持搜索字符串中的正则表达式。如何在xpath搜索中实现下面提到的(伪)css搜索?require'rubygems'require'nokogiri'value=Nokogiri::HTML.parse(ABBlaCD3"HTML_END#my_blockisgivenmy_bl="1"#my_eqcorrespondstothisregexmy_eq="\/[0-9]+\/"#FIXMEThefoll

  6. Unity 热更新技术 | (三) Lua语言基本介绍及下载安装 - 2

    ?博客主页:https://xiaoy.blog.csdn.net?本文由呆呆敲代码的小Y原创,首发于CSDN??学习专栏推荐:Unity系统学习专栏?游戏制作专栏推荐:游戏制作?Unity实战100例专栏推荐:Unity实战100例教程?欢迎点赞?收藏⭐留言?如有错误敬请指正!?未来很长,值得我们全力奔赴更美好的生活✨------------------❤️分割线❤️-------------------------

  7. MIMO-OFDM无线通信技术及MATLAB实现(1)无线信道:传播和衰落 - 2

     MIMO技术的优缺点优点通过下面三个增益来总体概括:阵列增益。阵列增益是指由于接收机通过对接收信号的相干合并而活得的平均SNR的提高。在发射机不知道信道信息的情况下,MIMO系统可以获得的阵列增益与接收天线数成正比复用增益。在采用空间复用方案的MIMO系统中,可以获得复用增益,即信道容量成倍增加。信道容量的增加与min(Nt,Nr)成正比分集增益。在采用空间分集方案的MIMO系统中,可以获得分集增益,即可靠性性能的改善。分集增益用独立衰落支路数来描述,即分集指数。在使用了空时编码的MIMO系统中,由于接收天线或发射天线之间的间距较远,可认为它们各自的大尺度衰落是相互独立的,因此分布式MIMO

  8. ruby-on-rails - Sphinx - 何时对字段使用 'has' 和 'indexes' - 2

    我几天前在我的ruby​​onrails2.3.2上安装了Sphinx和Thinking-Sphinx,基本搜索效果很好。这意味着,没有任何条件。现在,我想用一些条件过滤搜索。我有公告模型,索引如下所示:define_indexdoindexestitle,:as=>:title,:sortable=>trueindexesdescription,:as=>:description,:sortable=>trueend也许我错了,但我注意到只有当我将:sortable=>true语法添加到这些属性时,我才能将它们用作搜索条件。否则它找不到任何东西。现在,我还在使用acts_as_tag

  9. ruby - 如何搜索有用的 ruby - 2

    寻找有用的ruby的好网站是什么? 最佳答案 AgileWebDevelopment列出插件(虽然不是ruby​​gems,我不确定为什么),并允许人们对它们进行评级。RubyToolbox按类别列出gem并比较它们的受欢迎程度。Rubygems有一个搜索框。StackOverflow对最有用的rails插件和ruby​​gems有疑问。 关于ruby-如何搜索有用的ruby,我们在StackOverflow上找到一个类似的问题: https://stacko

  10. Ruby - 如何处理子类意外覆盖父类(super class)私有(private)字段的问题? - 2

    假设您编写了一个类Sup,我决定将其扩展为SubSup。我不仅需要了解你发布的接口(interface),还需要了解你的私有(private)字段。见证这次失败:classSupdefinitialize@privateField="fromsup"enddefgetXreturn@privateFieldendendclassSub问题是,解决这个问题的正确方法是什么?看起来子类应该能够使用它想要的任何字段而不会弄乱父类(superclass)。编辑:equivalentexampleinJava返回"fromSup",这也是它应该产生的答案。 最佳答案

随机推荐