- Enable Keyword Search in Textpattern
-
Update 15 January 2009: As of Textpattern 4.0.6 or 4.07 the instructions below no longer work, and I have not managed to enable keyword search again with the new Textpattern publish.php code. I tried replacing
if (empty($cols) or $cols[0] '') $cols = array('Title', 'Body');withif (empty($cols) or $cols[0] '') $cols = array('Title', 'Body', 'Keywords');…but then no search results are returned when a search is performed. Based on this forum thread I suspect a Textpattern bug is crawling about! I will keep this post updated with any developments. Thanks to Art Zoller Wagner for alerting me to this issue.· · ·
The default Textpattern built-in search only returns results from the title and body of posts. The following are instructions to make Textpattern search through post keywords as well.
- Access your Textpattern website MySQL database using phpMyAdmin and click on the Textpattern table.
- Scroll down to the Indexes table on the bottom of the page and click on the pencil on the searching value row.
- Click on Go on the bottom-right next to the Add to index [1] column(s) to add a new field. The default value for the new field which appears as a drop-down button is - – ignore – -. Click on the drop-down button and select Keywords [varchar(255)], then click on Save. You can now exit phpMyAdmin.
- Open publish.php in your website’s Textpattern folder and find the following code (lines 576 and 577 in Textpattern v4.0.5):
$match = ", match (Title,Body) against ('$q') as score"; $search = " and (Title rlike '$q' or Body rlike '$q') $s_filter"; - Change the above code to this:
$match = ", match (Title,Body,Keywords) against ('$q') as score"; $search = " and (Title rlike '$q' or Body rlike '$q' or Keywords rlike '$q') $s_filter";
Thanks to a helpful article which was pointed out to me in the Textpattern forum.