Search Excerpt WordPress Plugin

Moved!

I have moved this project to my programming/Internet blogSearch Excerpt WordPress Plugin.

WordPress’ searching capability is a bit mediocre at the moment. It splits up the keywords, digs out texts using SQL LIKE statement, and returns all entries that match the criteria, in a reverse chronological order. Then the default template will display some of these entries, using the template function the_excerpt(), which basically returns the first 55 words, HTML striped.

To have a more functional search, i.e. returning entries in the order of relevance, I think WordPress would need to either try to index the text (which is wha Search Reloaded plugin is about), or utilise MySQL’s full-text search functions. Both would require modifying the database layout and change “the loop”. Yuk.

To have a more meaningful result display, i.e. returning text snippets surrounding the matches, is however quite easy to achieve. Thus my Sunday evening’s little project, “Search Excerpt” plugin that displays more meaningful result than the default first 55 words.

Category: General | Mon, 22 August 2005 12:30 pm

Links to This Article

  1. Tue, 23 August 2005 1:08 am
    Tech Gadgets Blog - LiewCF.com
  2. Sat, 26 November 2005 3:32 am
    虎蝠[Blog] » Blog Archive » hoofo.net使用的WP插件及应用列表
  3. Mon, 5 December 2005 9:26 am
    Php网站技术资讯收集 » 窝子网志|WozLog采用WordPress插件及应用列表
  4. Sat, 7 January 2006 9:00 am
    RRRrrrr!!! » Blog Archive » [转]wordpress重要插件
  5. Sat, 7 January 2006 9:30 am
    RRRrrrr!!! » Blog Archive » [转]wordpress重要插件
  6. Sun, 26 February 2006 6:52 am
    看看中文支持 » WordPress插件集合
  7. Sun, 5 March 2006 4:45 pm
    Cell Ninja - Cell Ninja thus far
  8. Thu, 9 March 2006 2:30 am
    iqwolf» Blog Archive » 我使用的WordPress插件
  9. Sat, 8 April 2006 10:55 pm
    本站使用的WP插件及应用列表 at Css博客吧
  10. Fri, 21 April 2006 1:48 am
    WordPress plugins Collection WP插件集合 - Oneandhalf Computing Techno-junkies
  11. Mon, 8 May 2006 4:16 pm
    Search Excerpt WordPress Plugin 1.1 Released | FuCoder.com

Comments

1.
Avatar for ]V[orlock Zernebock
Posted by ]V[orlock Zernebock on Mon, 22 August 2005 8:10 pm

Great plugin! Is there any way to use “Search Hilite” instead of simply use of <strong> tag?

]V[


2.
Avatar for scotty
Posted by scotty on Mon, 22 August 2005 8:35 pm

Code should be quite easy to hack to use <span class=”hilite”/> instead. However, you can also adjust your CSS stylesheet to change the appearance of strong in search pages.


3.
Avatar for Jam
Posted by Jam on Fri, 26 August 2005 5:44 pm

Nice plugin. Added aggressive support of Asian text (it doesn’t contain whitespace, so need different method to cut text). Check URL for the detail of my modification, a patch to php program, or modified version of ylsy_search_excerpt.php. I’m glad if you use my patch and distribute combined version. Thx.


4.
Avatar for scotty
Posted by scotty on Mon, 29 August 2005 10:54 am

Hi Jam,

Thanks for the fixes. I shall put your patch in for the next update.


5.
Avatar for ufbert
Posted by ufbert on Wed, 28 September 2005 10:29 am

I installed and got this: Warning: Wrong parameter count for preg_match() in /home/httpd/vhosts/harvesttheweb.com/httpdocs/wp-content/plugins/ylsy_search_excerpt.php on line 77


6.
Avatar for scotty
Posted by scotty on Wed, 28 September 2005 10:32 am

Your host need to have at least PHP 4.3 to support extra arguments for preg_match().


7.
Avatar for ufbert
Posted by ufbert on Wed, 28 September 2005 10:55 am

We have PHP 4.3.2 installed…


8.
Avatar for scotty
Posted by scotty on Wed, 28 September 2005 11:21 am

Alright. I just had a chance to read PHP’s documentation again on preg_match:

The flags parameter is available since PHP 4.3.0… The offset parameter is available since PHP 4.3.3…

So I guess PHP 4.3.2 is just one minor version short.


9.
Avatar for Michael
Posted by Michael on Wed, 5 October 2005 9:54 pm

I only get ‘…’ as result(s). I’m currently using my own page templates, therefor i needed the ‘Search Everything’ Plugin (http://dancameron.org/searcheverything/) maybe that causes the probs ?


Avatar for Michael
Posted by Michael on Wed, 5 October 2005 10:10 pm

correction: sometimes i get only ‘…’ but when i get relevant text sometimes there’s html in it. Thjis shouldn’t be possible (‘$text = strip_tags($text);’ line 49) or did i overlook sth ?


Avatar for Maurice
Posted by Maurice on Tue, 11 October 2005 4:25 am

It doesn’t work here at all, the search does tun up but no matches highlighted at all. Can it be a skin issue or chmod thing?


Avatar for NigelMellish
Posted by NigelMellish on Mon, 17 October 2005 11:05 pm

I have the same as Maurice. I’m using BLIX and also Search Meter, Search Pages, and Search Realoaded.


Avatar for Maurice
Posted by Maurice on Tue, 18 October 2005 12:10 am

Hmm I use BLIX too, maybe it’s a blix thing? Any fix for this? Realy want something like this, it really makes search better!


Avatar for rogopag
Posted by rogopag on Sat, 5 November 2005 11:32 am

where do I have tu put the function in the search template? thank you


Avatar for Matthew
Posted by Matthew on Mon, 7 November 2005 12:06 am

great plugin – I’m using it in combination with Search Reloaded & Search Pages without any obvious problems.

The only thing that I have noticed, is that every now & then it will return the odd result where it just shows the start of the article, even though the item to be highlighted is much further down the article – I’ve looked through these articles where this happens though & I can’t see why they should be behaving any differently from the rest of the articles work as expected. It is only very occasionaly that this seems to happen though.


Avatar for scotty
Posted by scotty on Mon, 7 November 2005 8:04 am

Matthew,

Can you show me some example?

Also as WP uses a partial match in SQL even inside HTML tags, whereas this plugin matches on word boundary of the actual text — so there might be instances where WP found a post but this plugin cannot, thus only the first few words got shown.


Avatar for Matthew
Posted by Matthew on Mon, 7 November 2005 1:24 pm

The problem is stranger than I first thought.
I found the previous example where I noticed the problem, which happened when it was running on a local copy of my site that I just use for testing (& is not up to date with posts.)
I tried the same search terms on my publicly accessible site though & they showed the post that didn’t display correctly before, without any problems.
Looking at the problem in more detail, it appears to happen with any terms that reference that post. I have a feeling though, that the post had some unicode text in it that got corrupted when I imported the database on my local machine though.

I’ve saved the problem search page here:
http://mtaylor.co.uk/wordpress/error/index.xhtml
(its the second of the two links)

& the page that it links to here:
http://mtaylor.co.uk/wordpress/error/page.xhtml

A problem I have noticed (which I can’t explain at all) is that Firefox doesn’t like certain pages when sent to it as XHTML, generally where a very common search term is used. (the page seems to validate fine though, & I can’t see the problem with it when I view the source.)
You can see an example of what I mean if you go to:
http://www.elginism.com/index.php?s=elgin

The error it gives is:
XML Parsing Error: not well-formed
Location: http://www.elginism.com/index.php?s=elgin
Line Number 103, Column 167:

Like I said though, I can’t see what the problem is when I look at the source of that page.


Avatar for Maurice
Posted by Maurice on Thu, 10 November 2005 12:27 am

How about us BLIX users? The plugin doesn’t seem to work when using this theme!


Avatar for scotty
Posted by scotty on Thu, 10 November 2005 7:57 am

Matthew,

I will look at your site later this week — sorry been very busy (which you can see from how much I have been blogging here)

Maurice,

not sure about BLIX theme. Probably because it does not provide a search theme file? Does it work if it uses default theme’s search.php?


Avatar for fallen
Posted by fallen on Wed, 16 November 2005 2:47 am

Hi! could you tell me where to put the “” I don’t know how to
use this?! and I need “Search Everything” Can they work together? thanks!


Avatar for Aleksandar
Posted by Aleksandar on Thu, 20 April 2006 5:52 am

I’m testig this plugin on the local WP 2.0.2 install. It works fine apart from the problem that call to the_excerpt() outputs entire post + actual result from your plugin.

I found that the cause is this line from default-filters.php file:
add_filter('get_the_excerpt', 'wp_trim_excerpt');

If I comment that out, then it outputs just the fragments, which is desired result.

Any ideas how to workaround this, without actually commenting out this file (it would simplify the future upgrades)?

The solution I found is to:
- remove the add_filter('the_excerpt', 'ylsy_search_excerpt'); line from the end of the plugin
- call echo ylsy_search_excerpt(''); instead of the_excerpt()


Avatar for DG
Posted by DG on Sun, 7 May 2006 11:20 pm

Hi,

I have installed this plugin, A Great work. I have few query’s and need your advice.

1. While installing this plugin, I was using

‘Search Everything’ Plugin (http://dancameron.org/searcheverything/)

. So, after the activation, I could not get Search Excerpts. I had then disabled Searrch Everything Plugin and got the Search Excertpts.

However, I am facing a minor problem, the result does not display background & padding around Post footer area i.e at the end of each Post, I have Meta Data and Bookmarks with a surrounding box and background color.

Could you please advice.

Regards,


Avatar for scotty
Posted by scotty on Mon, 8 May 2006 1:20 pm

Hi DG,

Sorry I have not had experience with searcheverything plugin. It wouldn’t even work for me (WP2.0.2) when I tried to download and test it. However from the code it seems SEv only modifies the SQL for the search. As long as your theme has a search.php file that uses the_excerpt() to output the post content, this plugin should work.


Avatar for scotty
Posted by scotty on Mon, 8 May 2006 1:49 pm

Hi all,

I have moved this project to my programming blog. This page is left here only for record keeping — please check the new site for more details about updates to this plugin. I’ll also close comments to this entry. Please forward all your enquiries to the new site.