早在2017年,便提出了开发竞争对手价格监控服务的想法。 它与其他类似服务的区别在于其每天自动进行商品匹配的功能。 显然,由于几乎完全没有有关如何执行此操作的信息,价格监控服务仅提供了由客户自己或服务运营商进行手动比较的可能性,每个比较的价格为0.2到1卢布。 例如,每个站点有10个站点和20,000种产品的实际情况不可避免地需要过程的自动化,因为手动匹配已经太长且昂贵。
下面将使用使用
Elaticsearch技术的众多竞争药店的示例来描述自动匹配的方法。
环境说明
- 作业系统:Windows 10
- 依据:Elaticsearch 6.2
- 客户要求:邮递员6.2
设置Elaticsearch
一站式配置
产品现场
映射器和
分析仪PUT http://localhost:9200/app { "mappings": { "product": { "properties": { "name": { "type": "text", "analyzer": "name_analyzer" # }, "manufacturer": { "type": "text" }, "city_id": { "type": "integer" }, "company_id": { "type": "integer" }, "category_id": { "type": "integer" }, } } }, "settings": { "index": { "analysis": { "analyzer": { "name_analyzer": { "type": "custom", "tokenizer": "standard", # , "char_filter": [ "html_strip", # html "comma_to_dot_char_filter" # , ], "filter": [ "word_delimeter_filter", # "synonym_filter", # "lowercase" # ] } }, "filter": { "synonym_filter": { "type": "synonym_graph", "synonyms": [ ", ", ", ", ", ", ", , ", ", ", ", , , ", ", ", ", ", ", , ", ", , ", ", , , -, -", ", , ", ", , , ", ", ", ", ", ", , ", ", , ", ", ", ", ", ", ", ", ", ", , , ", ", ", ", g", "ml, " ] }, "word_delimeter_filter": { "type": "word_delimiter", "type_table": [ ". => DIGIT", # "- => ALPHANUM", "; => SUBWORD_DELIM", "` => SUBWORD_DELIM" ] } }, "char_filter": { "comma_to_dot_char_filter": { "type": "mapping", "mappings": [ ", => ." ] } } } } } }
例如,我们可以看一下分析仪“ name_analyzer”的哪个部分会破坏药物的名称“用于10g管外用的羟考酮10mg + 30mg / g软膏”。 我们使用请求
_analyze 。
POST http://localhost:9200/app/_analyze { "analyzer" : "name_analyzer", "text" : " 10+30/ 10" }
结果
{ "tokens": [ { "token": "", "start_offset": 0, "end_offset": 9, "type": "<ALPHANUM>", "position": 0 }, { "token": "10", "start_offset": 10, "end_offset": 12, "type": "<ALPHANUM>", "position": 1 }, { "token": "", "start_offset": 12, "end_offset": 14, "type": "<ALPHANUM>", "position": 2 }, { "token": "30", "start_offset": 15, "end_offset": 17, "type": "<ALPHANUM>", "position": 3 }, { "token": "", "start_offset": 17, "end_offset": 19, "type": "<ALPHANUM>", "position": 4 }, { "token": "g", "start_offset": 20, "end_offset": 21, "type": "SYNONYM", #, "g" SYNONYM, , ", g" "position": 5 }, { "token": "", "start_offset": 20, "end_offset": 21, "type": "<ALPHANUM>", "position": 5 }, { "token": "", "start_offset": 22, "end_offset": 26, "type": "<ALPHANUM>", "position": 6 }, { "token": "", "start_offset": 27, "end_offset": 30, "type": "<ALPHANUM>", "position": 7 }, { "token": "", "start_offset": 31, "end_offset": 40, "type": "<ALPHANUM>", "position": 8 }, { "token": "", "start_offset": 41, "end_offset": 51, "type": "<ALPHANUM>", "position": 9 }, { "token": "", "start_offset": 52, "end_offset": 56, "type": "<ALPHANUM>", "position": 10 }, { "token": "10", "start_offset": 57, "end_offset": 59, "type": "<ALPHANUM>", "position": 11 }, { "token": "g", "start_offset": 59, "end_offset": 60, "type": "SYNONYM", "position": 12 }, { "token": "", "start_offset": 59, "end_offset": 60, "type": "<ALPHANUM>", "position": 12 } ] }
填充测试数据
请求
_bulk POST http://localhost:9200/_bulk { "index": { "_index": "app", "_type": "product", "_id": 195111 } } { "name": " 10+30/ 10", "manufacturer": " ", "city_id": 1, "company_id": 2, "category_id": 1 } { "index": { "_index": "app", "_type": "product", "_id": 195222 } } { "name": " 10 +30 /: 10 ", "manufacturer": "", "city_id": 1, "company_id": 3, "category_id": 1 }
映射搜索
让我们要寻找竞争对手的所有相似产品的客户产品具有特征
{ "name": " 10 +30 / 10 ", "manufacturer": " ", "city_id": 1, "company_id": 1, "category_id": 1 }
在
药品目录中,我们从产品名称中选择药品名称。 在这种情况下,单词“ Hyoxysone”。 此单词将是必填条件。
我们还将名称中的所有数字“ 10 30 10”删去,它们也是必不可少的标准。 此外,如果将某个数量包括两次,则在找到的商品中也应该出现两次,否则我们将增加与错误商品相符的机会。
_搜索请求
GET http://localhost:9200/app/product/_search { "query": { "bool": { "filter": [ { "terms": { "company_id": [ 2, 3, 4, 5, 6, 7, 8 ] } }, { "term": { "city_id": { "value": 1, "boost": 1 } } }, { "term": { "category_id": { "value": 1, "boost": 1 } } } ], "must": [ { "bool": { "should": [ { "match": { "name": { "query": " + / ", "boost": 1, "operator": "or", "minimum_should_match": 0, "fuzziness": "AUTO" } } } ], "must": [ { "match": { "name": { "query": "", "boost": 2, "operator": "or", "minimum_should_match": "70%", "fuzziness": "AUTO" } } }, { "match_phrase": { "name": { "query": "10 30 10", "boost": 2, "slop": 100 } } } ] } } ], "should": [ { "bool": { "should": [ { "match": { "manufacturer": { "query": " ", "boost": 1, "operator": "or", "minimum_should_match": "70%", "fuzziness": "AUTO" } } }, { "match": { "manufacturer": { "query": "alenta armacevtika ", "boost": 1, "operator": "or", "minimum_should_match": "70%", "fuzziness": "AUTO" } } } ] } } ] } }, "highlight": { "fields": { "name": {} } }, "size": 50 }
在输出中,我们获得商品的ID,以及它们的名称+得分(用于分析)以及匹配的匹配片段。
- 羟考松 10 mg + 30 mg / g 外用软膏 , 管 10 g-算法得分:69.84
- 外用HYOXISON 软膏 10 mg + 30 mg / g : 10 g-算法评估:49.79
结论
所描述的方法肯定不会给出100%的匹配精度,但是它将极大地促进商品的手动匹配过程。 也适用于不需要绝对精度的任务。
通常,如果您使用其他启发式方法来改进搜索查询并增加同义词的数量,则可以获得接近令人满意的结果。
此外,在旧i7上进行的性能测试显示出良好的结果。 在几秒钟内执行200,000个产品的阵列中的10个搜索查询。 您可以
在这里看到这个现场医学实例。
在评论中提出您的选择,匹配方式。
感谢您的关注!