zoukankan      html  css  js  c++  java
  • 55.TF/IDF算法

    主要知识点:

    • TF/IDF算法介绍
    • 查看es计算_source的过程及各词条的分数
    • 查看一个document是如何被匹配到的

       

       

    一、算法介绍

    relevance score算法,简单来说,就是计算出,一个索引中的文本,与搜索文本,他们之间的关联匹配程度。Elasticsearch使用的是 term frequency/inverse document frequency算法,简称为TF/IDF算法

       

    1Term frequency

    搜索文本中的各个词条在field文本中出现了多少次,出现次数越多,就越相关

    示例

    搜索请求:hello world

    doc1hello you, and world is very good

    doc2hello, how are you

    doc1比doc2更相关

       

    2Inverse document frequency

    搜索文本中的各个词条在整个索引的所有文档中出现了多少次,出现的次数越多,就越不相关。

       

    搜索请求:hello world

       

    doc1hello, today is very good

    doc2hi world, how are you

       

    比如说,在index中有1万条documenthello这个单词在所有的document中,一共出现了1000次;world这个单词在所有的document中,一共出现了100次,那么doc2doc1更相关

       

       

    3Field-length norm

    field越长,相关度越弱

       

    搜索请求:hello world

       

    doc1{ "title": "hello article", "content": "babaaba 1万个单词" }

    doc2{ "title": "my article", "content": "blablabala 1万个单词,hi world" }

       

    hello world在整个index中出现的次数是一样多的,但是word是在一万个单词中才出现的,所以doc1更相关,title field更短

       

    二、查看_score是如何被计算出来的

       

    GET /test_index/test_type/_search?explain

    {

    "query": {

    "match": {

    "test_field": "test hello"

    }

    }

    }

       

    三、查看一个document是如何被匹配到的

       

    GET /test_index/test_type/6/_explain

    {

    "query": {

    "match": {

    "test_field": "test hello"

    }

    }

    }

       

    四、延伸阅读

    百度百科

       

  • 相关阅读:
    数据库学习之范式理解
    Java学习之网络编程
    Hadoop学习之HBase和Hive的区别
    erlang 查看进程相关信息
    erlang web socket参考。
    erlang启动参数
    调试信息和错误信息。
    进程监控树。
    erlang的进程池。
    日志系统。
  • 原文地址:https://www.cnblogs.com/liuqianli/p/8472495.html
Copyright © 2011-2022 走看看