当前位置: 首页 > news >正文

Elasticsearch使用function_score查询酒店和排序

需求

基于用户地理位置,对酒店做简单的排序,非个性化的推荐。酒店评分包含以下:

  1. 酒店类型(依赖用户历史订单数据):希望匹配出更加符合用户使用的酒店类型
  2. 酒店评分:评分高的酒店用户体验感好
  3. geo地理位置评分:例如出差的用户,距离较近的较为便捷
  4. 价格评分(依赖用户历史订单数据):符合用户的消费习惯

实现

基于Elasticsearch 7.4,centos7环境。

索引Mapping

{"properties": {"address": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"addressEn": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"boardRoom": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"brandCode": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"businessZone": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"cityCode": {"type": "keyword"},"cityId": {"type": "long"},"cityName": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"commentFacilityPoint": {"type": "float"},"commentHygienePoint": {"type": "float"},"commentPoint": {"type": "float"},"commentPositionPoint": {"type": "float"},"commentRecommendPercent": {"type": "float"},"commentServicePoint": {"type": "float"},"diningRoom": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"email": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"factories": {"properties": {"facilityName": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"facilityType": {"type": "long"},"facilityValue": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}}}},"fixTime": {"type": "date","format": "yyyy-MM-dd"},"gdLocation": {"type": "geo_point"},"govStar": {"type": "long"},"govZone": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"gymnasium": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"hotelCode": {"type": "keyword"},"hotelDesc": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"hotelFacility": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"hotelGroup": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"hotelName": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"hotelNameEn": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"hotelService": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"hotelShortDesc": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"hotelStatus": {"type": "long"},"hotelTips": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"location": {"type": "geo_point"},"mainPicture": {"type": "keyword"},"minPrice": {"type": "float"},"openingTime": {"type": "date","format": "yyyy-MM-dd"},"parking": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"phoneNum": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"pickUpService": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"pictures": {"properties": {"pictureType": {"type": "long"},"pictureUrl": {"type": "keyword"}}},"postNumber": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"roomCount": {"type": "long"},"rooms": {"properties": {"bedNumber": {"type": "long"},"bedWidth": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"checkNumber": {"type": "long"},"facilities": {"properties": {"facilityValue": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"roomCode": {"type": "keyword"}}},"pictures": {"properties": {"pictureUrl": {"type": "keyword"},"roomCode": {"type": "keyword"}}},"roomArea": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"roomBedType": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"roomCigaretteInfo": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"roomCode": {"type": "keyword"},"roomCount": {"type": "long"},"roomFloor": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"roomMainPicture": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"roomName": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"windowType": {"type": "long"},"wrapRoomName": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}}}},"starCode": {"type": "long"},"starName": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"swimmingPool": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"trafficInfo": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"type": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"wifi": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}}}
}

字段的描述:

{"hotelCode": "酒店编号","hotelName": "酒店中文名","hotelNameEn": "酒店英文名","hotelStatus": "酒店状态:1启用,2挂起","cityId": "系统城市ID","cityCode": "城市编号","cityName": "城市名称","openingTime": "开业时间","fixTime": "装修时间","starCode": "星级编号(1,2,3,4,5)","starName": "星级描述","govStar": "是否挂牌星级:1:是;0:否","phoneNum": "电话","email": "邮件","postNumber": "邮编","location": "百度坐标","gdLocation": "高德坐标","address": "地址","addressEn": "地址","brandCode": "酒店品牌,例如“麗枫”。","hotelGroup": "酒店所属集团名称。例如“7天(铂涛)”。","roomCount": "房间数量","mainPicture": "图片地址","hotelTips": "酒店温馨提示信息","hotelFacility": "酒店设施","hotelService": "酒店服务","hotelShortDesc": "酒店简介","hotelDesc": "酒店详细介绍","trafficInfo": "交通信息","wifi": "是否有免费WIFI,字段不为空表示有该项服务","boardRoom": "是否有会议室,字段不为空表示有该项服务","diningRoom": "是否有餐厅,字段不为空表示有该项服务","parking": "是否有停车场,字段不为空表示有该项服务","pickUpService": "是否有接机服务,字段不为空表示有该项服务","swimmingPool": "是否有游泳池,字段不为空表示有该项服务","gymnasium": "是否有健身房,字段不为空表示有该项服务","govZone": "行政区域信息,信息来自于“按城市查询县级行政区域”接口","businessZone": "商圈信息","minPrice": "最低价","commentPoint": "酒店点评分数(满分5分)","commentRecommendPercent": "酒店有百分之多少用户推荐,例如90%时数据是90.0","commentPositionPoint": "对于酒店位置的单项点评分数(满分5分)","commentFacilityPoint": "对于酒店设施的单项点评分数(满分5分)","commentServicePoint": "对于酒店服务的单项点评分数(满分5分)","commentHygienePoint": "对于酒店卫生的单项点评分数(满分5分)"
}

查询酒店和排序

数据量较大,上传不了,有需要可私信获取demo酒店数据。

排序方式有推荐、距离、好评、低价、高价,这里我们实现推荐排序。

筛选条件也是多样的,如下所示,这里我们使用距离筛选:

  1. 评分:4.8以上、4.5以上、4.0以上、3.5以上
  2. 酒店类型:民宿、 酒店公寓、青年公寓、特色住宿、别墅、客栈、农家院、电竞酒店、情侣酒店
  3. 宾客类型:外宾适用、港澳台宾客适用
  4. 特色主题“地铁附近、亲子精选、商务出行、度假休闲、湖畔美居、动人夜景、依山傍水、地标景、四合院
  5. 酒店设施:免费停车、洗衣服、24小时热水、空调、停车场、棋牌室、健身房、接送机服务、洗衣服服务
  6. 房型:大床房、双床房、床位房、单人床房、电竞房、情侣房、影音房、私汤房、亲子房
  7. 餐食:含早
  8. 距离:1km以内、1-3km、3-5km、5-10km

基于地理位置(也可以增加其他条件)5km范围内的酒店数据使用function_scope排序。

在价格和位置上,我们期望和origin数据接近的酒店数据,使用了衰减函数进行评分,衰减函数详细说明在后面进行说明。

在酒店名称上,我们期待根据用户历史订单时间,赋予不同的权重,使用query_string查询。

注意的是boost_mode使用了replace使用function_score计算的分数,避免elasticsearch的文档评分干扰。

增加query 参数_source_includes=hotelName,cityName,address,commentPoint,gdLocation,minPrice,方便观察数据

{"explain": true,"query": {"function_score": {"query": {"bool": {"must": {"match_all": {}},// 根据距离筛选数据"filter": {"geo_distance": {"distance": "5km","gdLocation": {"lat": "23.150261","lon": "113.324994"}}}}},"boost": 5,// max_boost 参数来限制新分数不超过一定的限制。 "max_boost": 100,"functions": [// 酒店类型(依赖用户历史数据){"filter": {// 根据历史数据,不同关键词设置权重“青年旅舍”权重1,“青年公寓”权重2,“酒店公寓”权重3"query_string": {"query": "hotelName:(\"青年旅舍\"^0.1 or \"青年公寓\"^0.1 or \"酒店公寓\"^0.2)"}},// 生成从 0 到但不包括 1 均匀分布的分数(非必填),默认情况下,它使用内部 Lucene 文档 ID 作为随机源"random_score": {// 使用_seq_no字段作为随机源,唯一的缺点是如果文档已更新,则分数将会更改"field": "_seq_no","seed": 10},"weight": 3},// 衰减函数(DECAY_FUNCTION )-geo 地理位置评分{// gauss 正常衰减"gauss": {// 在origin上偏移offset后随着scale进行衰减"gdLocation": {// 用于计算距离的原点 lon,lat(经纬度)"origin": "113.324994,23.150261",// 定义计算得分等于衰减参数时距原点 + 偏移量的距离"scale": "2km",// 如果定义了offset,则衰减函数将仅计算距离大于offset的文档的衰减函数。默认值为 0。"offset": "1km",//衰减参数定义如何在给定scale的距离上对文档进行评分。如果未定义衰减,则距离scale上的文档将评分为 0.5。"decay": "0.33"}},"weight": 20},//价格排序(依赖历史数据,缺省 150){"gauss": {// 在150元基础上偏移30元在100元范围内衰减"minPrice": {"origin": 150,"offset": 0,"scale": 50}},"weight": 15},// 酒店评分{"gauss": {"commentPoint": {"origin": 5,"offset": 1,"scale": 2}},"weight": 10}],// functions函数的分数与查询的分数相结合// multiply:查询得分与functions得分相乘(默认)、replace:仅使用functions得分,忽略查询得分、sum:查询得分与functions得分相加、avg:平均、max:查询得分和functions得分的最大值、min:查询得分和functions得分的最小值"boost_mode": "replace",// Score_mode 指定如何组合计算functions函数的分数// multiply(默认)分数相乘、sum分数相加、avg:分数被平均、max:使用最高分数、min:使用最低分数"score_mode": "sum",// 默认情况下,修改分数不会更改匹配的文档。要排除不满足特定分数阈值的文档,可以将 min_score 参数设置为所需的分数阈值。"min_score": 0}},// 返回距离"script_fields": {"distance_in_m": {"script": "doc['gdLocation'].arcDistance(23.150261,113.324994)"}}
}

查询结果:

{"took": 35,"timed_out": false,"_shards": {"total": 1,"successful": 1,"skipped": 0,"failed": 0},"hits": {"total": {"value": 3244,"relation": "eq"},"max_score": 27.109045,"hits": [{"_shard": "[hotel_test][0]","_node": "cdYh0ptNTP6kMXlVSE8dqA","_index": "hotel_test","_type": "_doc","_id": "HCIc1I0BqMZKQzdgx805","_score": 27.109045,"_source": {"gdLocation": {"lon": "113.318928","lat": "23.118031"},"address": "华利路172号","cityName": "广州市","commentPoint": 3.7,"minPrice": 149.0,"hotelName": "美佳酒店公寓(广州星辰大厦店)"},"fields": {"distance_in_m": [3637.0993194146326]},"_explanation": {"value": 27.109045,"description": "min of:","details": [{"value": 27.109045,"description": "function score, score mode [sum]","details": [{"value": 2.2679522,"description": "function score, product of:","details": [{"value": 1.0,"description": "match filter: (hotelName:\"酒 店 公 寓\")^0.2 (hotelName:\"青 年 旅 舍\")^0.1 (hotelName:or)^2.0 (hotelName:\"青 年 公 寓\")^0.1","details": []},{"value": 2.2679522,"description": "product of:","details": [{"value": 0.75598407,"description": "random score function (seed: 10, field: _seq_no)","details": []},{"value": 3.0,"description": "weight","details": []}]}]},{"value": 0.0,"description": "product of:","details": [{"value": 0.0,"description": "Function for field gdLocation:","details": [{"value": 0.0,"description": "exp(-0.5*pow(MIN of: [Math.max(arcDistance(23.118030996993184, 113.31892794929445(=doc value),113.324994, 23.150261(=origin)) - 1000.0(=offset), 0)],2.0)/1803975.3084153999)","details": []}]},{"value": 20.0,"description": "weight","details": []}]},{"value": 14.995842,"description": "product of:","details": [{"value": 0.9997228,"description": "Function for field minPrice:","details": [{"value": 0.9997228,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(149.0(=doc value) - 150.0(=origin))) - 0.0(=offset), 0)],2.0)/1803.3688011112042)","details": []}]},{"value": 15.0,"description": "weight","details": []}]},{"value": 9.845252,"description": "product of:","details": [{"value": 0.9845252,"description": "Function for field commentPoint:","details": [{"value": 0.9845252,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(3.700000047683716(=doc value) - 5.0(=origin))) - 1.0(=offset), 0)],2.0)/2.8853900817779268)","details": []}]},{"value": 10.0,"description": "weight","details": []}]}]},{"value": 100.0,"description": "maxBoost","details": []}]}},{"_shard": "[hotel_test][0]","_node": "cdYh0ptNTP6kMXlVSE8dqA","_index": "hotel_test","_type": "_doc","_id": "CCId1I0BqMZKQzdg3dtd","_score": 26.72167,"_source": {"gdLocation": {"lon": "113.319571","lat": "23.118040"},"address": "珠江新城华穗路174","cityName": "广州市","commentPoint": 3.6,"minPrice": 157.0,"hotelName": "广州华美酒店公寓"},"fields": {"distance_in_m": [3625.479965509789]},"_explanation": {"value": 26.72167,"description": "min of:","details": [{"value": 26.72167,"description": "function score, score mode [sum]","details": [{"value": 2.1975284,"description": "function score, product of:","details": [{"value": 1.0,"description": "match filter: (hotelName:\"酒 店 公 寓\")^0.2 (hotelName:\"青 年 旅 舍\")^0.1 (hotelName:or)^2.0 (hotelName:\"青 年 公 寓\")^0.1","details": []},{"value": 2.1975284,"description": "product of:","details": [{"value": 0.7325095,"description": "random score function (seed: 10, field: _seq_no)","details": []},{"value": 3.0,"description": "weight","details": []}]}]},{"value": 0.0,"description": "product of:","details": [{"value": 0.0,"description": "Function for field gdLocation:","details": [{"value": 0.0,"description": "exp(-0.5*pow(MIN of: [Math.max(arcDistance(23.118039965629578, 113.31957092508674(=doc value),113.324994, 23.150261(=origin)) - 1000.0(=offset), 0)],2.0)/1803975.3084153999)","details": []}]},{"value": 20.0,"description": "weight","details": []}]},{"value": 14.797592,"description": "product of:","details": [{"value": 0.98650616,"description": "Function for field minPrice:","details": [{"value": 0.98650616,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(157.0(=doc value) - 150.0(=origin))) - 0.0(=offset), 0)],2.0)/1803.3688011112042)","details": []}]},{"value": 15.0,"description": "weight","details": []}]},{"value": 9.726549,"description": "product of:","details": [{"value": 0.97265494,"description": "Function for field commentPoint:","details": [{"value": 0.97265494,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(3.5999999046325684(=doc value) - 5.0(=origin))) - 1.0(=offset), 0)],2.0)/2.8853900817779268)","details": []}]},{"value": 10.0,"description": "weight","details": []}]}]},{"value": 100.0,"description": "maxBoost","details": []}]}},{"_shard": "[hotel_test][0]","_node": "cdYh0ptNTP6kMXlVSE8dqA","_index": "hotel_test","_type": "_doc","_id": "liIX1I0BqMZKQzdgfYmJ","_score": 25.0,"_source": {"gdLocation": {"lon": "113.332040","lat": "23.136532"},"address": "天河东路153号富海大厦首层","cityName": "广州市","commentPoint": 4.1,"minPrice": 150.0,"hotelName": "IU酒店(广州天河东体育中心地铁站店)"},"fields": {"distance_in_m": [1688.0487591581082]},"_explanation": {"value": 25.0,"description": "min of:","details": [{"value": 25.0,"description": "function score, score mode [sum]","details": [{"value": 0.0,"description": "product of:","details": [{"value": 0.0,"description": "Function for field gdLocation:","details": [{"value": 0.0,"description": "exp(-0.5*pow(MIN of: [Math.max(arcDistance(23.13653199467808, 113.33203992806375(=doc value),113.324994, 23.150261(=origin)) - 1000.0(=offset), 0)],2.0)/1803975.3084153999)","details": []}]},{"value": 20.0,"description": "weight","details": []}]},{"value": 15.0,"description": "product of:","details": [{"value": 1.0,"description": "Function for field minPrice:","details": [{"value": 1.0,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(150.0(=doc value) - 150.0(=origin))) - 0.0(=offset), 0)],2.0)/1803.3688011112042)","details": []}]},{"value": 15.0,"description": "weight","details": []}]},{"value": 10.0,"description": "product of:","details": [{"value": 1.0,"description": "Function for field commentPoint:","details": [{"value": 1.0,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(4.099999904632568(=doc value) - 5.0(=origin))) - 1.0(=offset), 0)],2.0)/2.8853900817779268)","details": []}]},{"value": 10.0,"description": "weight","details": []}]}]},{"value": 100.0,"description": "maxBoost","details": []}]}},{"_shard": "[hotel_test][0]","_node": "cdYh0ptNTP6kMXlVSE8dqA","_index": "hotel_test","_type": "_doc","_id": "JyIY1I0BqMZKQzdgnpWo","_score": 25.0,"_source": {"gdLocation": {"lon": "113.346694","lat": "23.173795"},"address": "天源路134-140号201铺","cityName": "广州市","commentPoint": 4.2,"minPrice": 150.0,"hotelName": "广州友逸·青舍酒店(天河客运站地铁站店)"},"fields": {"distance_in_m": [3430.6572488915003]},"_explanation": {"value": 25.0,"description": "min of:","details": [{"value": 25.0,"description": "function score, score mode [sum]","details": [{"value": 0.0,"description": "product of:","details": [{"value": 0.0,"description": "Function for field gdLocation:","details": [{"value": 0.0,"description": "exp(-0.5*pow(MIN of: [Math.max(arcDistance(23.173794960603118, 113.34669392555952(=doc value),113.324994, 23.150261(=origin)) - 1000.0(=offset), 0)],2.0)/1803975.3084153999)","details": []}]},{"value": 20.0,"description": "weight","details": []}]},{"value": 15.0,"description": "product of:","details": [{"value": 1.0,"description": "Function for field minPrice:","details": [{"value": 1.0,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(150.0(=doc value) - 150.0(=origin))) - 0.0(=offset), 0)],2.0)/1803.3688011112042)","details": []}]},{"value": 15.0,"description": "weight","details": []}]},{"value": 10.0,"description": "product of:","details": [{"value": 1.0,"description": "Function for field commentPoint:","details": [{"value": 1.0,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(4.199999809265137(=doc value) - 5.0(=origin))) - 1.0(=offset), 0)],2.0)/2.8853900817779268)","details": []}]},{"value": 10.0,"description": "weight","details": []}]}]},{"value": 100.0,"description": "maxBoost","details": []}]}},{"_shard": "[hotel_test][0]","_node": "cdYh0ptNTP6kMXlVSE8dqA","_index": "hotel_test","_type": "_doc","_id": "YCIZ1I0BqMZKQzdgKJuj","_score": 25.0,"_source": {"gdLocation": {"lon": "113.333399","lat": "23.192820"},"address": "沙太路283号天健装饰城N栋","cityName": "广州市","commentPoint": 4.2,"minPrice": 150.0,"hotelName": "广州OK好主题商务酒店(南方医科大学店)"},"fields": {"distance_in_m": [4809.715858252524]},"_explanation": {"value": 25.0,"description": "min of:","details": [{"value": 25.0,"description": "function score, score mode [sum]","details": [{"value": 0.0,"description": "product of:","details": [{"value": 0.0,"description": "Function for field gdLocation:","details": [{"value": 0.0,"description": "exp(-0.5*pow(MIN of: [Math.max(arcDistance(23.1928199948743, 113.33339896984398(=doc value),113.324994, 23.150261(=origin)) - 1000.0(=offset), 0)],2.0)/1803975.3084153999)","details": []}]},{"value": 20.0,"description": "weight","details": []}]},{"value": 15.0,"description": "product of:","details": [{"value": 1.0,"description": "Function for field minPrice:","details": [{"value": 1.0,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(150.0(=doc value) - 150.0(=origin))) - 0.0(=offset), 0)],2.0)/1803.3688011112042)","details": []}]},{"value": 15.0,"description": "weight","details": []}]},{"value": 10.0,"description": "product of:","details": [{"value": 1.0,"description": "Function for field commentPoint:","details": [{"value": 1.0,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(4.199999809265137(=doc value) - 5.0(=origin))) - 1.0(=offset), 0)],2.0)/2.8853900817779268)","details": []}]},{"value": 10.0,"description": "weight","details": []}]}]},{"value": 100.0,"description": "maxBoost","details": []}]}},{"_shard": "[hotel_test][0]","_node": "cdYh0ptNTP6kMXlVSE8dqA","_index": "hotel_test","_type": "_doc","_id": "LCIX1I0BqMZKQzdgP4dj","_score": 24.995842,"_source": {"gdLocation": {"lon": "113.347091","lat": "23.174963"},"address": "天源路150号","cityName": "广州市","commentPoint": 4.1,"minPrice": 149.0,"hotelName": "广州源悦商务酒店(天河客运站店)"},"fields": {"distance_in_m": [3556.3638692192253]},"_explanation": {"value": 24.995842,"description": "min of:","details": [{"value": 24.995842,"description": "function score, score mode [sum]","details": [{"value": 0.0,"description": "product of:","details": [{"value": 0.0,"description": "Function for field gdLocation:","details": [{"value": 0.0,"description": "exp(-0.5*pow(MIN of: [Math.max(arcDistance(23.174962978810072, 113.34709097631276(=doc value),113.324994, 23.150261(=origin)) - 1000.0(=offset), 0)],2.0)/1803975.3084153999)","details": []}]},{"value": 20.0,"description": "weight","details": []}]},{"value": 14.995842,"description": "product of:","details": [{"value": 0.9997228,"description": "Function for field minPrice:","details": [{"value": 0.9997228,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(149.0(=doc value) - 150.0(=origin))) - 0.0(=offset), 0)],2.0)/1803.3688011112042)","details": []}]},{"value": 15.0,"description": "weight","details": []}]},{"value": 10.0,"description": "product of:","details": [{"value": 1.0,"description": "Function for field commentPoint:","details": [{"value": 1.0,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(4.099999904632568(=doc value) - 5.0(=origin))) - 1.0(=offset), 0)],2.0)/2.8853900817779268)","details": []}]},{"value": 10.0,"description": "weight","details": []}]}]},{"value": 100.0,"description": "maxBoost","details": []}]}},{"_shard": "[hotel_test][0]","_node": "cdYh0ptNTP6kMXlVSE8dqA","_index": "hotel_test","_type": "_doc","_id": "vCIY1I0BqMZKQzdgGY-9","_score": 24.995842,"_source": {"gdLocation": {"lon": "113.300959","lat": "23.143710"},"address": "永福路3号","cityName": "广州市","commentPoint": 4.1,"minPrice": 151.0,"hotelName": "窝趣公寓(广州永福黄花岗地铁站店)"},"fields": {"distance_in_m": [2563.1222106598048]},"_explanation": {"value": 24.995842,"description": "min of:","details": [{"value": 24.995842,"description": "function score, score mode [sum]","details": [{"value": 0.0,"description": "product of:","details": [{"value": 0.0,"description": "Function for field gdLocation:","details": [{"value": 0.0,"description": "exp(-0.5*pow(MIN of: [Math.max(arcDistance(23.143709963187575, 113.30095899291337(=doc value),113.324994, 23.150261(=origin)) - 1000.0(=offset), 0)],2.0)/1803975.3084153999)","details": []}]},{"value": 20.0,"description": "weight","details": []}]},{"value": 14.995842,"description": "product of:","details": [{"value": 0.9997228,"description": "Function for field minPrice:","details": [{"value": 0.9997228,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(151.0(=doc value) - 150.0(=origin))) - 0.0(=offset), 0)],2.0)/1803.3688011112042)","details": []}]},{"value": 15.0,"description": "weight","details": []}]},{"value": 10.0,"description": "product of:","details": [{"value": 1.0,"description": "Function for field commentPoint:","details": [{"value": 1.0,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(4.099999904632568(=doc value) - 5.0(=origin))) - 1.0(=offset), 0)],2.0)/2.8853900817779268)","details": []}]},{"value": 10.0,"description": "weight","details": []}]}]},{"value": 100.0,"description": "maxBoost","details": []}]}},{"_shard": "[hotel_test][0]","_node": "cdYh0ptNTP6kMXlVSE8dqA","_index": "hotel_test","_type": "_doc","_id": "pCIX1I0BqMZKQzdgfYmJ","_score": 24.995842,"_source": {"gdLocation": {"lon": "113.280966","lat": "23.133804"},"address": "建设大马路13号","cityName": "广州市","commentPoint": 4.3,"minPrice": 151.0,"hotelName": "7天优品酒店(广州建设大马路店)"},"fields": {"distance_in_m": [4859.477242418425]},"_explanation": {"value": 24.995842,"description": "min of:","details": [{"value": 24.995842,"description": "function score, score mode [sum]","details": [{"value": 0.0,"description": "product of:","details": [{"value": 0.0,"description": "Function for field gdLocation:","details": [{"value": 0.0,"description": "exp(-0.5*pow(MIN of: [Math.max(arcDistance(23.133803978562355, 113.28096597455442(=doc value),113.324994, 23.150261(=origin)) - 1000.0(=offset), 0)],2.0)/1803975.3084153999)","details": []}]},{"value": 20.0,"description": "weight","details": []}]},{"value": 14.995842,"description": "product of:","details": [{"value": 0.9997228,"description": "Function for field minPrice:","details": [{"value": 0.9997228,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(151.0(=doc value) - 150.0(=origin))) - 0.0(=offset), 0)],2.0)/1803.3688011112042)","details": []}]},{"value": 15.0,"description": "weight","details": []}]},{"value": 10.0,"description": "product of:","details": [{"value": 1.0,"description": "Function for field commentPoint:","details": [{"value": 1.0,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(4.300000190734863(=doc value) - 5.0(=origin))) - 1.0(=offset), 0)],2.0)/2.8853900817779268)","details": []}]},{"value": 10.0,"description": "weight","details": []}]}]},{"value": 100.0,"description": "maxBoost","details": []}]}},{"_shard": "[hotel_test][0]","_node": "cdYh0ptNTP6kMXlVSE8dqA","_index": "hotel_test","_type": "_doc","_id": "9iMk1I0BqMZKQzdgQzUI","_score": 24.983374,"_source": {"gdLocation": {"lon": "113.327053","lat": "23.192682"},"address": "广州大道北同和镇蟹山村牌坊侧","cityName": "广州市","commentPoint": 4.4,"minPrice": 148.0,"hotelName": "城市便捷酒店(广州南方医院同和地铁站店)"},"fields": {"distance_in_m": [4721.698475981125]},"_explanation": {"value": 24.983374,"description": "min of:","details": [{"value": 24.983374,"description": "function score, score mode [sum]","details": [{"value": 0.0,"description": "product of:","details": [{"value": 0.0,"description": "Function for field gdLocation:","details": [{"value": 0.0,"description": "exp(-0.5*pow(MIN of: [Math.max(arcDistance(23.19268198683858, 113.32705294713378(=doc value),113.324994, 23.150261(=origin)) - 1000.0(=offset), 0)],2.0)/1803975.3084153999)","details": []}]},{"value": 20.0,"description": "weight","details": []}]},{"value": 14.983374,"description": "product of:","details": [{"value": 0.9988916,"description": "Function for field minPrice:","details": [{"value": 0.9988916,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(148.0(=doc value) - 150.0(=origin))) - 0.0(=offset), 0)],2.0)/1803.3688011112042)","details": []}]},{"value": 15.0,"description": "weight","details": []}]},{"value": 10.0,"description": "product of:","details": [{"value": 1.0,"description": "Function for field commentPoint:","details": [{"value": 1.0,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(4.400000095367432(=doc value) - 5.0(=origin))) - 1.0(=offset), 0)],2.0)/2.8853900817779268)","details": []}]},{"value": 10.0,"description": "weight","details": []}]}]},{"value": 100.0,"description": "maxBoost","details": []}]}},{"_shard": "[hotel_test][0]","_node": "cdYh0ptNTP6kMXlVSE8dqA","_index": "hotel_test","_type": "_doc","_id": "VCIc1I0BqMZKQzdgHMU6","_score": 24.983374,"_source": {"gdLocation": {"lon": "113.335878","lat": "23.136834"},"address": "龙口西路65号天信大厦B座","cityName": "广州市","commentPoint": 4.2,"minPrice": 152.0,"hotelName": "七橙商务公寓(广州岗顶地铁站龙口西店)"},"fields": {"distance_in_m": [1862.1268585567427]},"_explanation": {"value": 24.983374,"description": "min of:","details": [{"value": 24.983374,"description": "function score, score mode [sum]","details": [{"value": 0.0,"description": "product of:","details": [{"value": 0.0,"description": "Function for field gdLocation:","details": [{"value": 0.0,"description": "exp(-0.5*pow(MIN of: [Math.max(arcDistance(23.13683399464935, 113.33587791770697(=doc value),113.324994, 23.150261(=origin)) - 1000.0(=offset), 0)],2.0)/1803975.3084153999)","details": []}]},{"value": 20.0,"description": "weight","details": []}]},{"value": 14.983374,"description": "product of:","details": [{"value": 0.9988916,"description": "Function for field minPrice:","details": [{"value": 0.9988916,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(152.0(=doc value) - 150.0(=origin))) - 0.0(=offset), 0)],2.0)/1803.3688011112042)","details": []}]},{"value": 15.0,"description": "weight","details": []}]},{"value": 10.0,"description": "product of:","details": [{"value": 1.0,"description": "Function for field commentPoint:","details": [{"value": 1.0,"description": "exp(-0.5*pow(MIN[Math.max(Math.abs(4.199999809265137(=doc value) - 5.0(=origin))) - 1.0(=offset), 0)],2.0)/2.8853900817779268)","details": []}]},{"value": 10.0,"description": "weight","details": []}]}]},{"value": 100.0,"description": "maxBoost","details": []}]}}]}
}

DECAY_FUNCTION - 衰减函数

衰减函数(Decay Function)是一个数学函数,它用于描述一个数量随着时间、距离或其他因素递减的过程。衰减函数通常是指数函数或者多项式函数的形式,用以模拟现象如电磁波的衰减、放射性物质的衰变、药物在体内的代谢等。

在地理信息系统(Geographic Information Systems, GIS)或地理学领域中,衰减函数可以用来衡量地理位置之间的相互作用或影响随距离的递减。例如,一个城市的经济影响力对附近的城镇可能很大,但对更远的城镇影响则小得多,衰减函数可以用来量化这种影响力的减弱程度。

以下是一些衰减函数在地理领域的应用示例:

  1. 空间相互作用模型:在模拟城市之间的人口迁移、商业交往或通勤模式时,衰减函数可以用来表示随着距离增加,这些互动的可能性怎样降低。

  2. 热点分析:在热点分析中,可以用衰减函数来确定某一事件(如犯罪、病例报告等)对周围区域的影响,随距离递减。

  3. 可达性评估:在评估某个地点对于居民的可达性时,可以使用衰减函数来模拟不同交通模式(步行、开车等)的时间或距离衰减。

  4. 地理加权回归(Geographically Weighted Regression, GWR):在地理加权回归分析中,衰减函数用于赋予数据点一个权重,这个权重基于数据点之间的空间距离,更近的点有更大的影响力。

在具体应用中,选择合适的衰减函数类型和参数对模型结果的精确性有很大影响。常见的衰减函数形式包括:

  • 指数衰减函数:f(d) = e^(-λd),其中d是距离,λ是衰减系数。
  • 幂律衰减函数:f(d) = d^(-β),其中d是距离,β是衰减系数。

这些函数的参数通常需要根据实际数据进行拟合和调整,以最好地反映现实世界中的衰减现象。

相关文章:

Elasticsearch使用function_score查询酒店和排序

需求 基于用户地理位置,对酒店做简单的排序,非个性化的推荐。酒店评分包含以下: 酒店类型(依赖用户历史订单数据):希望匹配出更加符合用户使用的酒店类型酒店评分:评分高的酒店用户体验感好ge…...

iOS消息发送流程

Objc的方法调用基于消息发送机制。即Objc中的方法调用,在底层实际都是通过调用objc_msgSend方法向对象消息发送消息来实现的。在iOS中, 实例对象的方法主要存储在类的方法列表中,类方法则是主要存储在原类中。 向对象发送消息,核心…...

【接口测试】常见HTTP面试题

目录 HTTP GET 和 POST 的区别 GET 和 POST 方法都是安全和幂等的吗 接口幂等实现方式 说说 post 请求的几种参数格式是什么样的? HTTP特性 HTTP(1.1) 的优点有哪些? HTTP(1.1) 的缺点有哪些&#x…...

服务器硬件基础知识

1. 服务器分类 服务器分类 服务器的分类没有一个统一的标准。 从多个多个维度来看服务器的分类可以加深我们对各种服务器的认识。 N.B. CISC: complex instruction set computing 复杂指令集计算 RISC: reduced instruction set computer 精简指令集计算 EPIC: explicitly p…...

matlab实现层次聚类与k-均值聚类算法

1. 原理 1.层次聚类:通过计算两类数据点间的相似性,对所有数据点中最为相似的两个数据点进行组合,并反复迭代这一过程并生成聚类树 2.k-means聚类:在数据集中根据一定策略选择K个点作为每个簇的初始中心,然后将数据划…...

【机器学习】包裹式特征选择之递归特征消除法

🎈个人主页:豌豆射手^ 🎉欢迎 👍点赞✍评论⭐收藏 🤗收录专栏:机器学习 🤝希望本文对您有所裨益,如有不足之处,欢迎在评论区提出指正,让我们共同学习、交流进…...

【ArcGIS】重采样栅格像元匹配问题:不同空间分辨率栅格数据统一

重采样栅格像元匹配问题:不同空间分辨率栅格数据统一 原始数据数据1:GDP分布数据2.1:人口密度数据2.2:人口总数数据3:土地利用类型 数据处理操作1:将人口密度数据投影至GDP数据(栅格数据的投影变…...

Qt 简约又简单的加载动画 第七季 音量柱风格

今天和大家分享两个音量柱风格的加载动画,这次的加载动画的最大特点就是简单,只有几行代码. 效果如下: 一共三个文件,可以直接编译运行 //main.cpp #include "LoadingAnimWidget.h" #include <QApplication> #include <QGridLayout> int main(int argc…...

【JS】数值精度缺失问题解决方案

方法一&#xff1a; 保留字符串类型&#xff0c;传给后端 方法二&#xff1a; 如果涉及到计算&#xff0c;用以下方法 // 核心思想 在计算前&#xff0c;将数字乘以相同倍数&#xff0c;让他没有小数位&#xff0c;然后再进行计算&#xff0c;然后再除以相同的倍数&#xff0…...

c++基础知识补充4

单独使用词汇 using std::cout; 隐式类型转换型初始化&#xff1a;如A a1,,此时可以形象地理解为int i1;double ji;&#xff0c;此时1可以认为创建了一个值为1的临时对象&#xff0c;然后对目标对象进行赋值&#xff0c;当对象为多参数时&#xff0c;使用&#xff08;1&#xf…...

leetcode230. 二叉搜索树中第K小的元素

lletcode 230. 二叉搜索树中第K小的元素&#xff0c;链接&#xff1a;https://leetcode.cn/problems/kth-smallest-element-in-a-bst 题目描述 给定一个二叉搜索树的根节点 root &#xff0c;和一个整数 k &#xff0c;请你设计一个算法查找其中第 k 个最小元素&#xff08;从 …...

医学大数据|文献阅读|有关“肠癌+机器学习”的研究记录

目录 1.机器学习算法识别结直肠癌中的免疫相关lncRNA signature 2.基于机器学习的糖酵解相关分子分类揭示了结直肠癌癌症患者预后、TME和免疫疗法的差异&#xff0c;2区7 3.整合深度学习-病理组学、放射组学和免疫评分预测结直肠癌肺转移患者术后结局 4.最新7.4分纯生信&am…...

Linux信号【systemV】

目录 前言 正文&#xff1a; 1消息队列 1.1什么是消息队列&#xff1f; 1.2消息队列的数据结构 1.3消息队列的相关接口 1.3.1创建 1.3.2释放 1.3.3发送 1.3.4接收 1.4消息队列补充 2.信号量 2.1什么是信号量 2.2互斥相关概念 2.3信号量的数据结构 2.4…...

node.js最准确历史版本下载

先进入官网:Node.js https://nodejs.org/en 嫌其他博客多可以到/release下载:Node.js,在blog后面加/release https://nodejs.org/en/blog/release/ 点击next翻页,同样的道理...

UE5 C++ 单播 多播代理 动态多播代理

一. 代理机制&#xff0c;代理也叫做委托&#xff0c;其作用就是提供一种消息机制。 发送方 &#xff0c;接收方 分别叫做 触发点和执行点。就是软件中的观察者模式的原理。 创建一个C Actor作为练习 二.单播代理 创建一个C Actor MyDeligateActor作为练习 在MyDeligateAc…...

前端学习、CSS

CSS可以嵌入到HTML中使用。 每个CSS语法包含两部分&#xff0c;选择器和应用的属性。 div用来声明针对页面上的哪些元素生效。 具体设置的属性以键值对形式表示&#xff0c;属性都在{}里&#xff0c;属性之间用;分割&#xff0c;键和值之间用:分割。 因为CSS的特殊命名风格…...

Flink基本原理 + WebUI说明 + 常见问题分析

Flink 概述 Flink 是一个用于进行大规模数据处理的开源框架&#xff0c;它提供了一个流式的数据处理 API&#xff0c;支持多种编程语言和运行时环境。Flink 的核心优点包括&#xff1a; 低延迟&#xff1a;Flink 可以在毫秒级的时间内处理数据&#xff0c;提供了低延迟的数据…...

3. 文档概述(Documentation Overview)

3. 文档概述&#xff08;Documentation Overview&#xff09; 本章节简要介绍一下Spring Boot参考文档。它包含本文档其它部分的链接。 本文档的最新版本可在 docs.spring.io/spring-boot/docs/current/reference/ 上获取。 3.1 第一步&#xff08;First Steps&#xff09; …...

【vue3 路由使用与讲解】vue-router : 简洁直观的全面介绍

# 核心内容介绍 路由跳转有两种方式&#xff1a; 声明式导航&#xff1a;<router-link :to"...">编程式导航&#xff1a;router.push(...) 或 router.replace(...) &#xff1b;两者的规则完全一致。 push(to: RouteLocationRaw): Promise<NavigationFailur…...

ubuntu创建账号和samba共享目录

新建用于登录Ubuntu图形界面的用户 sudo su #切换为root用户获取管理员权限用于新建用户 adduser username #新建用户&#xff08;例如用户名为username&#xff09; adduser username sudo #将用户添加到 sudo 组 新建只能用于命令行下登录的用户 sudo su #切换为root用户…...

uniapp 对接腾讯云IM群组成员管理(增删改查)

UniApp 实战&#xff1a;腾讯云IM群组成员管理&#xff08;增删改查&#xff09; 一、前言 在社交类App开发中&#xff0c;群组成员管理是核心功能之一。本文将基于UniApp框架&#xff0c;结合腾讯云IM SDK&#xff0c;详细讲解如何实现群组成员的增删改查全流程。 权限校验…...

多模态商品数据接口:融合图像、语音与文字的下一代商品详情体验

一、多模态商品数据接口的技术架构 &#xff08;一&#xff09;多模态数据融合引擎 跨模态语义对齐 通过Transformer架构实现图像、语音、文字的语义关联。例如&#xff0c;当用户上传一张“蓝色连衣裙”的图片时&#xff0c;接口可自动提取图像中的颜色&#xff08;RGB值&…...

R语言速释制剂QBD解决方案之三

本文是《Quality by Design for ANDAs: An Example for Immediate-Release Dosage Forms》第一个处方的R语言解决方案。 第一个处方研究评估原料药粒径分布、MCC/Lactose比例、崩解剂用量对制剂CQAs的影响。 第二处方研究用于理解颗粒外加硬脂酸镁和滑石粉对片剂质量和可生产…...

PHP 8.5 即将发布:管道操作符、强力调试

前不久&#xff0c;PHP宣布了即将在 2025 年 11 月 20 日 正式发布的 PHP 8.5&#xff01;作为 PHP 语言的又一次重要迭代&#xff0c;PHP 8.5 承诺带来一系列旨在提升代码可读性、健壮性以及开发者效率的改进。而更令人兴奋的是&#xff0c;借助强大的本地开发环境 ServBay&am…...

如何应对敏捷转型中的团队阻力

应对敏捷转型中的团队阻力需要明确沟通敏捷转型目的、提升团队参与感、提供充分的培训与支持、逐步推进敏捷实践、建立清晰的奖励和反馈机制。其中&#xff0c;明确沟通敏捷转型目的尤为关键&#xff0c;团队成员只有清晰理解转型背后的原因和利益&#xff0c;才能降低对变化的…...

SpringAI实战:ChatModel智能对话全解

一、引言&#xff1a;Spring AI 与 Chat Model 的核心价值 &#x1f680; 在 Java 生态中集成大模型能力&#xff0c;Spring AI 提供了高效的解决方案 &#x1f916;。其中 Chat Model 作为核心交互组件&#xff0c;通过标准化接口简化了与大语言模型&#xff08;LLM&#xff0…...

解析“道作为序位生成器”的核心原理

解析“道作为序位生成器”的核心原理 以下完整展开道函数的零点调控机制&#xff0c;重点解析"道作为序位生成器"的核心原理与实现框架&#xff1a; 一、道函数的零点调控机制 1. 道作为序位生成器 道在认知坐标系$(x_{\text{物}}, y_{\text{意}}, z_{\text{文}}…...

深入浅出WebGL:在浏览器中解锁3D世界的魔法钥匙

WebGL&#xff1a;在浏览器中解锁3D世界的魔法钥匙 引言&#xff1a;网页的边界正在消失 在数字化浪潮的推动下&#xff0c;网页早已不再是静态信息的展示窗口。如今&#xff0c;我们可以在浏览器中体验逼真的3D游戏、交互式数据可视化、虚拟实验室&#xff0c;甚至沉浸式的V…...

归并排序:分治思想的高效排序

目录 基本原理 流程图解 实现方法 递归实现 非递归实现 演示过程 时间复杂度 基本原理 归并排序(Merge Sort)是一种基于分治思想的排序算法&#xff0c;由约翰冯诺伊曼在1945年提出。其核心思想包括&#xff1a; 分割(Divide)&#xff1a;将待排序数组递归地分成两个子…...

[拓扑优化] 1.概述

常见的拓扑优化方法有&#xff1a;均匀化法、变密度法、渐进结构优化法、水平集法、移动可变形组件法等。 常见的数值计算方法有&#xff1a;有限元法、有限差分法、边界元法、离散元法、无网格法、扩展有限元法、等几何分析等。 将上述数值计算方法与拓扑优化方法结合&#…...