ElasticSearch(十七)初識倒排索引

如今有兩條document:spa

doc1:I really liked my small dogs, and I think my mom also liked them.
doc2:He never liked any dogs, so I hope that my mom will not expect me to liked him.

1.分詞,初步的倒排索引的創建(*表明有,空表明無):code

word        doc1            doc2

I             *            *
really        *
liked         *            *
my            *            *
small         *    
dogs          *
and           *
think         *
mom           *            *
also          *
them          *    
He                         *
never                      *
any                        *
so                         *
hope                       *
that                       *
will                       *
not                        *
expect                     *
me                         *
to                         *
him                        *

 

 

這邊演示了一下倒排索引最簡單的創建的一個過程  orm

假設進行搜索:mother like little dog,結果是:不可能有任何結果blog

過程是將mother like little dog進行一個個拆分,而後進行匹配,無任何匹配信息。索引

這個是否是咱們想要的搜索結果???絕對不是,由於在咱們看來,mother和mom有區別嗎?同義詞,都是媽媽的意思。like和liked有區別嗎?沒有,都是喜歡的意思,只不過一個是如今時,一個是過去時。little和small有區別嗎?同義詞,都是小小的。dog和dogs有區別嗎?狗,只不過一個是單數,一個是複數。文檔

2.es在創建倒排索引的時候進行了normalization操做it

normalization,創建倒排索引的時候,會執行一個操做,也就是說對拆分出的各個單詞進行相應的處理,以提高後面搜索的時候可以搜索到相關聯的文檔的機率。io

normalization的意思是進行時態的轉換,單複數的轉換,同義詞的轉換,大小寫的轉換。class

mom —> mother
liked —> like
small —> little
dogs —> dog

從新創建倒排索引,加入normalization,再次用mother liked little dog搜索,就能夠搜索到了搜索

word        doc1            doc2

I             *            *
really        *
like          *            *            liked --> like
my            *            *
little        *                        small --> little
dog           *            *            dogs --> dog                        
and           *
think         *
mom           *            *
also          *
them          *    
He                         *
never                      * 
any                        *
so                         *
hope                       *
that                       *
will                       *
not                        *
expect                     * 
me                         *
to                         *
him                        *

 

進行搜索:mother like little dog,結果:doc1和doc2都會搜索出來

相關文章
相關標籤/搜索