sphinx full text search engine

วันนี้ทำงานสบายๆ ก็เลยมาเขียนซะหน่อย ห่างหายไปจาก blog นานๆ แล้ว ที่จะพูดถึงวันนี้ก็คือ fulltext search

ช่างเป็นอะไรที่ กิน performance เครื่องสุดๆ ลองคิดถึง algorithm ง่ายของ LIKE ใน SQL นะ

1 record ก็จะมีั text เช่น ‘some text’
แล้วเราก็หาคำว่า ‘me’ ใน text นี้ มันก็ต้องหา so, om, me แล้วก็เจอ ลองคิดดูว่ามันจะหาไปกี่ที
แน่นอนว่า วิธีนี้มันโง่และทึ่มมาก เพราะทำงานธรรมดาสุดๆ คือ เทียบกันไปเรื่อยๆ การทำงานจึงเป็น loop ไป เรื่อยๆ แต่ปัจจุบันนั้นก็มีคนศึกษาเรื่องนี้และได้คิด algorithm ออกมาเพื่อที่จะจัดการกับ full text search อีกมาก บาง algorithm ก็ได้รับความนิยม จนไปสู่การนำมาใช้งานจริง
.
sphinx ก็เป็นอีก 1 ตัวที่ได้รับความนิยมอยู่ในขณะนี้ เพราะด้วย performance และการใช้งานนั้นง่าย รวมทั้งยังเป็น Open Source อีกด้วย ทำให้เปิดโลกกว้างการการเพิ่มเติมและการนำไปใช้ด้วย

sphinx search นั้นมี feature หลักคือ

  • high indexing speed (upto 10 MB/sec on modern CPUs)
  • high search speed (avg query is under 0.1 sec on 2-4 GB text collections)
  • high scalability (upto 100 GB of text, upto 100 M documents on a single CPU)
  • supports distributed searching (since v.0.9.6)
  • supports MySQL natively (MyISAM and InnoDB tables are both supported)
  • supports phrase searching
  • supports phrase proximity ranking, providing good relevance
  • supports English and Russian stemming
  • supports any number of document fields (weights can be changed on the fly)
  • supports document groups
  • supports stopwords
  • supports different search modes (“match all”, “match phrase” and “match any” as of v.0.9.5)
  • generic XML interface which greatly simplifies custom integration
  • pure-PHP (ie. NO module compiling etc) search client API

ซึ่งถ้าอ่านดีๆ แล้วก็จะเห็น performance นั้นสูงทีเดียวและสามารถใช้งานได้ง่ายด้วย API และยัง support กับ Mysql และ postgresql ซึ่งเป็นฐานข้อมูล แบบ open source ที่ได้รับความนิยมทั่วโลก

จากที่ได้ลองติดตั้งดู ไม่มีอะไรยากเกินไปกว่า แตก tarball -> ./configure -> make -> make install แล้วก็ config อีกนิดหน่อย แค่ ใส่ user pass และ db name ของ database server ลงไปก็เสร็จแล้ว

ข้างใน config ก็มีให้เลือก database server อยู่แล้ว สามารถเลือกรูปแบบให้เหมาะสมได้เลย

ใน tutorial นั้นก็ได้มีการเขียนติดต่อกับ PHP ได้เลย เพียงนำ lib include ไปเท่านั้น

สามารถ compile ร่วมไปกับ mysql ให้เป็น engine ของ mysql ได้

วันนี้มาเกริ่นๆ เท่านั้น เกี่ยวกับ sphinx search ต่อไปก็จะมาพูดถึงการเขียนกัน แล้วก็รายละเอียด ลึกๆ แล้วกัน

One Response to “sphinx full text search engine”

Leave a Reply

You must be logged in to post a comment.