Thuta Learning
ရှာဖွေရန်
Elasticsearch
IntermediateData & Databasesbeginner

Relevance Scoring (BM25) နှင့် Highlighting

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Relevance Scoring (BM25) နှင့် Highlighting concept ကို နားလည်ရှင်းပြနိုင်ရန်
  • နမူနာ Elasticsearch query/code ကို ကိုယ်တိုင် run ပြီး output စစ်နိုင်ရန်
  • Tutorial Platform project နှင့် production scenario တွင် မှန်ကန်စွာအသုံးချနိုင်ရန်

နားလည်ထားရမယ့် အချက်

`_score` ကို compute ဖို့ Elasticsearch က default အနေနဲ့ BM25 ဆိုတဲ့ ranking algorithm ကို သုံးပါတယ်—term frequency (document ထဲမှာ search term ဘယ်နှစ်ကြိမ် repeat ဖြစ်လဲ, များလေ score မြင့်လေ ဒါပေမယ့် diminishing returns ရှိတယ်), inverse document frequency (collection တစ်ခုလုံးထဲမှာ word ဘယ်လောက်ရှားပါးလဲ—ရှားလေ term က document set တစ်ခုလုံးထဲ ခွဲခြားဖို့ ပိုတန်ဖိုးရှိလေ score ပိုမြင့်လေ), field length normalization (short field ထဲက match ဟာ long field ထဲက match ထက် value ပိုတန်ဖို့ compensate) သုံးမျိုးကို ပေါင်းစပ်ထားပါတယ်—ဒါကြောင့် "redis" ဆိုတဲ့ word ကို document တိုင်းလိုလိုမှာ ပါနေရင် (ဥပမာ Redis-focused course တစ်ခုလုံးမှာ) ဒီ word ရဲ့ discriminating power နည်းသွားလို့ score contribution လျော့သွားနိုင်ပါတယ်။ Highlighting ကတော့ `_score` ကို ဆက်နွယ်တဲ့ feature တစ်ခုဖြစ်ပြီး matched term ကို document body ထဲက surrounding context နဲ့တကွ `<em>` tag (customizable) ဝိုင်းပြီး snippet အဖြစ် ပြန်ပေးနိုင်ပါတယ်—user ကို document တစ်ခုလုံး ဖတ်ခိုင်းစရာမလိုဘဲ "ဘာကြောင့် ဒီ result က relevant ဖြစ်လဲ" ဆိုတာ instantly မြင်စေနိုင်ပါတယ်။ ဒါက Google search result list ထဲက bold text snippet ("...ဒီနေရာမှာ **redis cache** ဆိုတဲ့ term ပါတယ်...") နဲ့ တိုက်ရိုက် ဆင်တူပါတယ်—user ရဲ့ eye ကို result တစ်ခုစီရဲ့ relevance ကို ချက်ချင်း scan လုပ်ခွင့်ပေးတဲ့ UX pattern တစ်ခုပါ။ Highlighting ကို production မှာ enable လုပ်ရင် extra computation cost ရှိလို့ result list တွေအားလုံးအတွက် အလိုအလျောက် on ထားတာထက် user-visible search result page တွေအတွက်သာ selective ဖြစ်စေသင့်ပါတယ်။

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

Tutorial Platform ရဲ့ public search result page မှာ user က "session store" ရှာလိုက်ရင် `body` field ကို `highlight` block ထဲထည့်ပြီး response ထဲက `highlight.body` array ကနေ "...Redis ကို **session store** အဖြစ်..." လို snippet ကို card component ထဲ ပြသမယ်—title-only preview ထက် ဘယ် lesson က ဘာကြောင့် relevant ဖြစ်လဲ ပိုသိသာစေပါတယ်။ Admin search-quality debugging tool မှာတော့ `explain: true` parameter ကို ထည့်ပြီး `_score` ကို BM25 factor တစ်ခုချင်း breakdown ကြည့်နိုင်ပါတယ်—result ranking မှားနေတယ်ထင်ရင် ဒီ breakdown ကို tracing tool အဖြစ်သုံးမယ်။

အတူတူ စမ်းရေးကြည့်မယ်

http
GET /tutorials/_search
{
  "query": {
    "match": { "body": "session store" }
  },
  "highlight": {
    "fields": {
      "body": { "fragment_size": 150, "number_of_fragments": 1 }
    }
  }
}
You should see
Search result document တစ်ခုစီမှာ `highlight.body` array ထဲ matched term ကို `<em>` tag ဝိုင်းထားသော snippet ရမည်။

၅ မိနစ် စမ်းကြည့်

`title` field ပေါ်မှာ "elasticsearch" ရှာသော query တစ်ခုရေးပြီး `title` field အတွက် highlight block ထည့်ပါ—`explain: true` ကိုပါ ထည့်ပြီး `_score` breakdown ကို run ကြည့်ပါ။

သတိလေးတစ်ချက်

`_score` ကို absolute/comparable value တစ်ခုလို့ ထင်ပြီး query နှစ်ခု (structure မတူတဲ့) ရဲ့ `_score` တွေကို တိုက်ရိုက်နှိုင်းယှဉ်ခြင်း—BM25 score ဟာ query တစ်ခုစီရဲ့ context အတွင်းမှာသာ relative ဖြစ်လို့ query ကွဲရင် comparison မှားပါတယ်။

Highlighting ကို result list အားလုံးအတွက် default on ထားပြီး large `body` field ပေါ်မှာ run ခြင်း—matched snippet ရှာဖို့ extra computation ကို request တိုင်းအတွက် ကုန်ကျစေပြီး latency ကို မလိုအပ်ဘဲ တိုးစေနိုင်ပါတယ်။

Elasticsearch Guide — HighlightingElastic

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • `_score` ကို absolute/comparable value တစ်ခုလို့ ထင်ပြီး query နှစ်ခု (structure မတူတဲ့) ရဲ့ `_score` တွေကို တိုက်ရိုက်နှိုင်းယှဉ်ခြင်း—BM25 score ဟာ query တစ်ခုစီရဲ့ context အတွင်းမှာသာ relative ဖြစ်လို့ query ကွဲရင် comparison မှားပါတယ်။
  • Highlighting ကို result list အားလုံးအတွက် default on ထားပြီး large `body` field ပေါ်မှာ run ခြင်း—matched snippet ရှာဖို့ extra computation ကို request တိုင်းအတွက် ကုန်ကျစေပြီး latency ကို မလိုအပ်ဘဲ တိုးစေနိုင်ပါတယ်။
  • နမူနာ query/mutation ကို production cluster ပေါ် တိုက်ရိုက်မစမ်းဘဲ local/test instance နှင့် recoverable data ပေါ်တွင် အရင်အတည်ပြုပါ။

လေ့ကျင့်ခန်း

`title` field ပေါ်မှာ "elasticsearch" ရှာသော query တစ်ခုရေးပြီး `title` field အတွက် highlight block ထည့်ပါ—`explain: true` ကိုပါ ထည့်ပြီး `_score` breakdown ကို run ကြည့်ပါ။

You'll know it worked when: Search result document တစ်ခုစီမှာ `highlight.body` array ထဲ matched term ကို `<em>` tag ဝိုင်းထားသော snippet ရမည်။