enhance wordpress search using sphinx
DESCRIPTION
This presentation provide the details of what is the problem with WordPress Search and how Full-Text search on WordPress can be used using SphinxTRANSCRIPT
![Page 1: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/1.jpg)
![Page 2: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/2.jpg)
EnhanceWordPress
Search using Sphinx
![Page 3: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/3.jpg)
I’m Roshan Bhattarai
• CTO @ Proshore• Co-author – PHP AJAX COOKBOOK• A Developer and learner• Sometime I blog @ http://roshanbh.com.np• Twitter/Facebook/Linkedin @roshanbh
![Page 4: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/4.jpg)
What’s the problem with search in
WordPress
![Page 5: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/5.jpg)
![Page 6: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/6.jpg)
![Page 7: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/7.jpg)
Problem with default WordPress Search
• Default WordPress uses SQL like operator and % wildcard character to get search result
• SQL’s Like operator doesn’t care much about the relevancy of the result
• Like operation is too slow in large set of textual data
• WordPress sort the search result by date
![Page 8: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/8.jpg)
Ok let’s improve the WordPress Search
![Page 9: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/9.jpg)
So what’s resolution ?
• Use the MySQL Full-Text indexing and Search.
• Use Full-Text search server
![Page 10: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/10.jpg)
MySQL Full-Text search
• http://wordpress.org/plugins/wp-cjk-fulltext-index/
• It improve the searching speed and result relevancy by using MATCH AGAINST than LIKE function
• Use Full-Text index
http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html
![Page 11: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/11.jpg)
Full-Text Search SQL Example
Normal Like Search :
WHERE (post_title LIKE '%morbi%') OR (post_content LIKE '%morbi%')
Full-Text MySQL Search :
WHERE MATCH (post_title,post_content) AGAINST (’morbi');
![Page 12: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/12.jpg)
Pros and Cons MySQL Full-Text Indexing
• Pros• Can be used in Shared hosting • No need to install extra search server
• Cons• Still slow with very large data• Not featured rich like Search server
![Page 13: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/13.jpg)
And a very good news
![Page 14: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/14.jpg)
• Please upgrade your WordPress now. Relevancy is added in the search of WordPress 3.7
• Official Note from WordPress 3.7 release :
Search results are now ordered by how well the search query matches a post, instead of ordered only by date. For example, when your search terms match a post title, that result will be pushed to the top.
WordPress 3.7 has better search
![Page 15: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/15.jpg)
Difference in Search SQL
• Wordpress 3.6
WHERE ((wp_posts.post_title LIKE '%morbi%') OR (wp_posts.post_content LIKE '%morbi%'))ORDER BY wp_posts.post_date DESC
• WordPress 3.7
WHERE ((wp_posts.post_title LIKE '%morbi%') OR (wp_posts.post_content LIKE '%morbi%'))ORDER BY wp_posts.post_title LIKE '%morbi%' DESC, wp_posts.post_date DESC
![Page 16: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/16.jpg)
Still, It uses like operator
of SQL
![Page 17: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/17.jpg)
Why full text search engine
• Provides more relevant result.• Uses a ranking algorithm to quantify how
strongly a given record matches search keywords.
• Fast indexing • Search is fast compared to default MySQL
search and MyQL Full text indexing• Allow to use special operators like OR or
NOT in search
![Page 18: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/18.jpg)
Popular Full text search engines
• Apache Solr ( http://lucene.apache.org/solr/ )
• Elastic Search ( http://www.elasticsearch.org/ )
• Sphinx ( http://sphinxsearch.com/ )
![Page 19: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/19.jpg)
Why Sphinx ?
• Easy to setup and use
• Good documentation
• Used by many big websites like Craiglist, Groupon, Metacafe etc
• My personal choice
![Page 20: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/20.jpg)
Server Requirement
• Must have server with SSH access
• VPS or Dedicated server is recommended
![Page 21: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/21.jpg)
Installation of Sphinx
For Mac ( using Homebrew)
brew install sphinx –-mysql
For Windows / Ubuntu / Debian / RHEL/CentOS
http://sphinxsearch.com/downloads/release/
![Page 22: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/22.jpg)
WordPress Plugin
WordPress Sphinx Search Plugin
http://wordpress.org/plugins/wordpress-sphinx-plugin/
![Page 23: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/23.jpg)
Two main componentsWhen installed sphinx, two application called indexer and searchd gets installed.
• Indexer This component of Sphinx is used for indexing the data.
• Searchd This is a search daemon which returns of the document id of matched search results.
![Page 24: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/24.jpg)
Installation
![Page 25: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/25.jpg)
![Page 26: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/26.jpg)
![Page 27: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/27.jpg)
![Page 28: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/28.jpg)
Now setup Cron Job
Note : Delta index is a small temporary index above main index.
![Page 29: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/29.jpg)
The boring installaion is done ! YaY
![Page 30: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/30.jpg)
To run indexer and searchd Manually
• To run indexer manually/usr/local/sphinx/bin/indexer --rotate –config /<path of wordpress>/wp-content/uploads/sphinx/sphinx.conf wp_delta wp_main wp_stats
• To run searchd manually /usr/local/sphinx/bin/searchd --config /<pat of wordpress>/wp-content/uploads/sphinx/sphinx.conf
![Page 31: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/31.jpg)
Now let’s look at the result of all the hard
work
![Page 32: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/32.jpg)
Normal WordPress search result
![Page 33: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/33.jpg)
Search result after using Sphinx
![Page 34: Enhance WordPress Search Using Sphinx](https://reader036.vdocument.in/reader036/viewer/2022062417/54b6bdc24a7959fa048b45f7/html5/thumbnails/34.jpg)
Doh! This guy is done with his boring talk
Listening to next person is always boring. To make it exciting you’ve to do it yourself
Thank you!
Any Questions ?