YD Search Functions
This WordPress plugin implements advanced WordPress search functions that can render your search results in a way very similar to Google-like search engines.
Will generate “snippets“, ie “intelligent abstract” of the posts included in the search results, automatically extracting the most significant text around searched expressions or words (both full expression or individual words contained in the search request).
Will highlight searched text in the search result snippets.
Search results will conform to Google CSS syntax by default, and are widely customizable.
Upon installation, the plugin implements a set of advanced search functions that you can use inside your search result template files (search.php).
Please look at the doc on WordPress.org for more explanation, and download the plugin from there.
le 22 April 2010 à 9:51 h
Very nice plugin!
On the options page I only get a textfield with the word TEST and two buttons: update and reset widget (???). Is that correct?
le 22 April 2010 à 9:59 h
@Jack:
Yeah that’s all-right. There are no options right now, but it is definitely coming… things like abstract (snippet) text length, tags used for highlighting, choice of css stylesheet to include, etc. Will soon be options.
Right now, the plugin is still a work in progress, but since I’m already using it for my own sites and it works well, I decided to share it right away.
Expect version 0.2 to come your way as soon as the end of this week, and the options should be there sometimes next week.
Sorry for the “test” code and option… It looks weird but it does not harm.
Thanks for your appreciation.
le 23 April 2010 à 15:07 h
Bonjour YD
If you have a moment and feel like helping the stupid, I understand how to install the plugin almost completely – except – where is search.php in a typical WordPress installation? Our site is run on WP 2.9.2 with the Atahualpa theme, and the closest file I can find is searchform.php
All help appreciated, and my apologies for my ignorance …
Andrew Walker
le 23 April 2010 à 16:33 h
@Andrew:
Nothing stupid in your question. I have to admit help is kept to a strict minimum in the present distribution of this plugin. I thought only eggheads would be interested in the first place anyway ;-p
Some themes don’t use a search.php template file and work just fine without it.
In this case you will have to add some code in your main template to detect the use as a search result page.
I believe the appropriate function in WP would be: is_search()
So, you should put some conditional statement around your post display function, something like this maybe:
<?php
if( is_search() ) {
// — copy the code you can find on the plugin documentation page here —
} else {
the_content();
}
?>
– Hope this helps somewhat?
le 23 April 2010 à 17:15 h
Jeez – no good, too nervous about taking the site down in one cack-handed swipe. I know the lyrics and chords to more than three thousand songs but PHP? Argh!
Is there somewhere I could donate to the plugin and perhaps send you my template file so that someone who knows what they’re doing (ie you) might edit it?
le 25 April 2010 à 23:05 h
Your web site’s search form not working! 🙁
le 25 April 2010 à 23:17 h
@rimpe:
Thanks for noticeing. I just repaired it.
Please be aware that this site (yann.com) did not use th YD Search Function plugin until now.
For a more representative working example of the use of this plugin, please look here: http://www.nogent-citoyen.com/recherche/guinguette+marne
le 25 April 2010 à 23:41 h
@rimpe:
I just changed my mind about that. Now this site uses the plugin. Took 5 minutes to install and get the nice snippets. In the options page, I tweaked the settings like this :
Length of snippet: 600
Minimum word size: 3 (default)
Ellipsis: (default)
Before highlight: <b style=”background-color:#333300″>
After highlight: </b> (default).
le 4 May 2010 à 12:39 h
The plugin is working and I really like it, except that I’m getting the date in french and french format. How can I change this?
Also, if you would enter ‘honden’ (chiens) in the search bar in the sidebar on the left, you can see that there is one searchresult that looks diferent: ‘Bijvoederen van vogels’.
This is probably because ‘honden’ is a tag in that post, or ‘honden’ is part of the jpeg-filename of the image included.
le 4 May 2010 à 15:44 h
@Jack:
You’re right, I have yet to include the date format in the plugin option page. It’s in the to-do list.
But you can change it in the function call. The date locale is the 4th parameter to the function, and the time format is the 5th parameter. Like this for example:
yd_search_snippet( ”, ”, ”, ‘nl_NL.utf8’, ‘%e %b. %Y’ )
You’re right also about the fact that WordPress will return results that include the searched text in image names, but the snippet function cannot extract or highlight it. I’ll be working on searching images later on. It’s also in the to-do list, but further away.
(for those who wonder, the 3 first parameters to the function are optional, they are the content, the search string and the post date. The 6th optional parameter toggles html echo on/off)
le 4 May 2010 à 16:05 h
Thanks. I already changed the date format and language :).
Personally I don’t need to search for images, because that’s why I use ZenPhoto, so if you include it later on, perhaps an option can be added to NOT include searching for images?
Anyway, very nice plugin!
le 4 May 2010 à 17:24 h
Hey there,
thanks for the lovely, simple plugin.
Firstly, i’ve found a bug. Searching for a word in caps lock, eg PLUGIN doesn’t work.
Second, any chance you could implement an option in the menu to add or remove the date at the beggining of the snippet? Removing this works, but it would be good to not have to play with your code:
$content .= strftime( $timeformat, $the_time );
Third, highlighting doesn’t work when searching for more than one word.
Thanks for the work!
s
le 4 May 2010 à 18:12 h
@inky:
Thanks for reporting the bug. I will be correcting that soon.
I am aware that the highlighting does not work for multi-word right now. It used to work in the very first beta version, so I’m confident I will be able to make it work again soon.
I will also make displaying the date an option, as you suggested.
I have scheduled committing an update of the plugin by the end of this week, so hopefully all this will be corrected and implemented by then.
le 4 May 2010 à 18:28 h
@inky:
you can find a quick bugfix for the caps lock / uppercase problem here:
http://plugins.svn.wordpress.org/yd-search-functions/branches/0.2.1/
le 4 May 2010 à 18:54 h
Great, thanks for the super fast response. That fix works perfectly.
One more question. Would it be possible to make a precise word search option, so that if, for example, you searched for the word “iron” it would only come up with ‘iron’ and not, as on my website, ‘environment’. Perhaps, as a suggestion, if a word was entered surrounded by quotation marks?
Thanks Y!
le 7 May 2010 à 11:43 h
@Inky
Right now, the plugin relies on WordPress’ default search algorithm to get the search results (which is in fact a basic MySql fulltext index word match). It does not change the search results. It only deals with the way they are displayed.
In future versions, I will probably add some advanced search options to customize or improve WP search results. It should be possible then to implement some form of exact word matching option.
In the meantime, other plugins exist to tweak the WP search results or use other indexing methods. If you find a good one that works well in conjunction with my snippet function, please let me now!
le 7 May 2010 à 11:51 h
@All
Version 0.3.0 is just out. It includes some of your above requests:
– case-sensitive highlighting issue is fixed
– multiple-word hit-highlighting now works again
– the date-display becomes fully localized, customizable, and optional
Plus it introduces new features such as (basic) plural-form hit-highlighting (optional), and a better settings page design.
Hope you’ll enjoy it.
le 10 May 2010 à 8:49 h
Hello (I make it in english mais je suis français);
I will make a post on my plugins blog but I was curious to make a test on my principal blog. What will your plugin add on the WP installation – tables ?
le 10 May 2010 à 9:19 h
@Li-An:
This plugin does not change anything in the database structure.
It only deals with the existing WP search results.
It only adds a settings page to the admin menu, and a template function.
That’s all.
Ce plugin ne change rien à la structure des données, c’est simplement une fonction à utiliser pour reformatter les résultats de recherche de WordPress de façon plus utile.
le 10 May 2010 à 11:32 h
Merci/Thanks for the precisions.
le 10 May 2010 à 11:34 h
J’utilise personnellement Relvevansi qui permet lui aussi de surligner les résultats de la recherche et les trie suivant leur importance.
le 11 May 2010 à 0:00 h
@All:
Version 0.4.0 is just out!
It gives you search logging, a search statistics dashboard in the admin panel, “most searched” listing function and sidebar widget and a few new customization options for your search results.
le 14 May 2010 à 1:27 h
Sometimes I get this error message before the abstract:
Warning: strpos() [function.strpos]: Offset not contained in string in /home/content/68/5414068/html/wp-content/plugins/yd-search-functions/yd-search-functions.php on line 730
Thanks!
le 14 May 2010 à 1:43 h
@David
Thanks for reporting the bug, I will be looking into that and work on fixing this issue ASAP.
le 14 May 2010 à 12:17 h
I think when searching for ‘thing’ and getting searchresults like ‘anything’ is not bad in itself, but perhaps (just like Google), the plugin could present all results with the complete word ‘thing’ first, and after that everything else, like ‘anything’, ‘something’ etc.
le 20 May 2010 à 21:22 h
Hi all, very cool plugin! I added a mod to it to only show yd_most_searched() items which did indeed return a search result. The widget was showing any misspelled searches, which I did not want. Next I might add in something to only show full words.. i.e. if someone searches for “Healt” instead of “Health” (which also returned results) so the yd_most_searched() list would only contain full words. Below is the workflow I implemented, maybe it will help someone else – or make it’s way into the actual plugin 😀 Great work btw Y.Dubois!!
Line numbers might not be dead-on, but close. I added a table column called `ifmatch` after `count`.
Plugin mod to hide failed searches from the ‘Common Searches’ output
Update the SQL table creation code to add a ‘ifmatch’ field on line 860:
$sql = ”
CREATE TABLE IF NOT EXISTS `” . $table_name . “` (
`term` varchar(128) NOT NULL,
`slug` varchar(128) NOT NULL,
`count` bigint(20) NOT NULL default ‘1’,
`ifmatch` int(1) NOT NULL default ‘0’,
`first` timestamp NOT NULL default CURRENT_TIMESTAMP,
`last` timestamp NOT NULL default ‘0000-00-00 00:00:00’,
PRIMARY KEY (`term`),
FULLTEXT KEY `term` (`term`)
);
Line: 888 (Replace the $query with this new code and query):
//Store whether or not the match was a success
$match = 0;
$allsearch = &new WP_Query(“s=”.get_search_query().”&showposts=-1″);
$key = wp_specialchars($s, 1);
$count = $allsearch->post_count;
if ($count > 0) { $match = 1; }
$query = “INSERT DELAYED INTO `” . $table_name . “` ( term, slug, count, ifmatch, first, last ) VALUES ” .
” ( ‘” . preg_replace( “/’/”, “””, $search ) . “‘, ” .
” ‘” . $slug . “‘, ” .
” 1, ” .
” $match, ” .
“CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP() ) ” .
” ON DUPLICATE KEY UPDATE count = if( count > 0, count +1, -1 ), ifmatch = $match, last = CURRENT_TIMESTAMP”;
Update the yd_most_search() function, line 1033 to select only the ifmatch true items to display
$query = “SELECT term, slug, count FROM `” . $table_name . “` WHERE count > 0 AND ifmatch = 1 ORDER BY count DESC LIMIT $top_count”;
le 21 May 2010 à 18:05 h
Hey all, I wanted to display the YD results by relevance and not date (default WP functionality). Below is the code I worked up, it basically replaces your search.php loop and outputs the results by most relevant at the top. I didn’t want to hack the plugin up anymore, so this application uses the current plugin. Mail me with any questions…. jamesmehorter@gmail.com Hope it helps someone else out!
<?php
if (have_posts()) {
while (have_posts()): the_post();
//Generate some HTML to display the search results
//The whole result is wrapped in the permalink to the post/page
// Title
// Content
// Display Permalink
$html_str = "ID).”‘ title='”.get_the_title().”‘>\n”;
//Use the yd_highlight function to highlight keywords in the post/page title
$html_str .= yd_highlight(get_the_title($post->ID), searchQuery());
$html_str .= “”;
$html_str .= “\n”;
//Grab the yd_search_snippet of the content
$html_str .= yd_search_snippet(”,”,”,”,”,false);
$html_str .= “\n”;
$html_str .= “\n”;
$html_str .= “”.get_permalink($post->ID).”\n”;
$html_str .= “\n”;
$html_str .= “\n”;
//Store each loop item into an array that we will sort by relevance
$searchResults[] = $html_str;
endwhile; //END WHILE HAVE POSTS
//Sort an array by occurance of the query str
//PRE: Receive an unsorted array of strings and a query term
//POST: Return an array sorted by occurance of the query term
function SortByRelevance ($arrContent, $strQuery) {
foreach ($arrContent as $strContent) {
$occurance = substr_count($strContent, $strQuery);
$arrOccurance[$strContent] = $occurance;
arsort($arrOccurance);
}
foreach ($arrOccurance as $key => $value) {
$arrReturn[] = $key;
}
return $arrReturn;
}
//HighlighterText is the class name added to ‘Before Highlight:’ in the YD Search Functions Options
//I.E. We wrapped the highlight keyword in a span Keyword
$sortedResults = SortByRelevance ($searchResults, “HighlighterText”);
//Output the sorted results
foreach ($sortedResults as $result) { echo $result; }
?>
le 21 May 2010 à 18:06 h
Apparently this comment removed all the html used in the code.. just mail me if you want a copy.. but you get the idea..
le 21 May 2010 à 19:32 h
Hey James,
great ideas, great code.
I will reformat it and display it in this page for everyone to re-use, as soon as I can find a few minutes and see if part of your logic can make it in a future release.
You’re perfectly right, that’s the way this plugin is supposed to be used, creatively: my idea is just to give away a bunch of functions that are useful to me, and hopefully to others. I try to package the main features so that non-coders can take benefits from using this plugin also, but the real powerful stuff goes through some custom template coding.
If this plugin continues to be successful as it is now, I plan on putting some documentation pages on-line (and be more explicit inline in the code comments), to encourage such creativity. And I might as well open some kind of forum and find a way for people to easily share code around this plugin.
Thanks for your support, and just hang on a few days till I can cleanly display the code in your comments above: I’m very busy on another powerful plugin right now, but I hope I have time for the search functions sometime next week.
le 20 July 2010 à 17:10 h
great work,,,trying it now. thanks for your plugin
le 14 August 2010 à 16:21 h
Great plugin. Thanks.
I often get the same error as # 23 David 14 May 2010. He said:
“Sometimes I get this error message before the abstract:
Warning: strpos() [function.strpos]: Offset not contained in string in /home/content/68/5414068/html/wp-content/plugins/yd-search-functions/yd-search-functions.php on line 730”
Has there been any progress in repairing this item?
Thanks.
le 25 August 2010 à 17:40 h
@Joe: I thought this issue was already fixed. I’ll fix it for good in the next release of the plugin.
le 11 September 2010 à 15:38 h
Est-ce qu’une prochaine version pourrait le rendre compatible avec Markdown ?
http://michelf.com/projects/php-markdown/
le 16 September 2010 à 1:20 h
Loving this plugin. Still having trouble with the error Joe and David mentioned. Any luck with this so far?
le 16 September 2010 à 18:11 h
YD, I think we’ve got a solution to the error message people are getting before excerpts. Hope this helps.
On line 730, replace:
strpos( $content, ‘ ‘, $firstmatch – $halflength );
With:
if ($firstmatch – $halflength>0) $beginsnip = strpos( $content, ‘ ‘, $firstmatch – $halflength ); else $beginsnip = strpos( $content, ‘ ‘, $firstmatch);
Give it a try!
le 16 September 2010 à 23:43 h
@Cferson:
Thanks, I will test that and if it works all right it will be included in the next release.
le 18 September 2010 à 14:02 h
Hi, I managed to fix the error in line 730 with the code cferson mentioned, but now I get another ‘offset not contained in string’ in line 772.
le 23 October 2010 à 14:49 h
Hi YD and others,
To hide the warning message, I added a “@” before the call of the function strpos().
Line 731 and 771:
$beginsnip = @strpos( $content, ‘ ‘, $firstmatch – $halflength );
I don’t know if it is very “clean” but it works.
le 22 November 2010 à 23:19 h
I’m looking for a way for the search results in WordPress to not display the entire page. Is that possible with this plugin? I’ve tried to set the abstract length but it didn’t seem to have an effect. Thanks.
le 23 November 2010 à 12:38 h
Yes it is possible. Abstract length will do it if the plugin is installed like it should be. ie. you should replace the_content() with yd_search_snippet() in your search result template, as explained here: http://wordpress.org/extend/plugins/yd-search-functions/ .
le 18 December 2010 à 19:01 h
I love the plugin. Can you tell me how you have coded your own search page with the results shown in different tabs? I am trying to do exactly this, but I have not been able to achieve it.
Thanks
le 11 April 2011 à 17:57 h
The plugin is so amzing, but I’ve got some questions
1. the highlight function will cause the mess code when I’m using Asian Languages.
2. I’m trying to use WP Custom Search in order to have a more powerful search function, can I call YD functions to process the search result of that plugin? If could, how?
Thanks a lot.
le 16 November 2011 à 0:34 h
Bonjour Yann,
Dans la description du plugin, tu indique qu’il faut remplacer the_content() par .
Dans le code de search.php, je n’ai pas trouvé the_content().Est-ce que ça a disparu de la nouvelle version de wordpress? Est-ce que je dois remplacer une autre ligne ou le plugin n’est simplement plus compatible ?
Merci !
le 16 November 2011 à 0:42 h
@Mickael: le plugin est compatible avec les dernières versions de WordPress (il est notamment utilisé sur ce site sans aucun problème). Le thème par défaut de WordPress (TwentyEleven) a cependant beaucoup évolué, et le fichier qui génère le paragraphe correspondant aux résultats de recherche est maintenant content.php où il faut remplacer the_excerpt() là où on trouve les instructions suivantes :
<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
le 16 November 2011 à 0:48 h
Merci !
le 16 November 2011 à 10:05 h
Je viens de tester et j’obtiens toujours l’erreur Warning: strpos()
[function.strpos]: Offset not contained in string in /home/.../blog/wp-content/plugins/yd-search-functions/yd-search-functions.php on line 730
le 15 January 2012 à 1:13 h
Bonjour,
Je souhaite utiliser YD Most Searched dans la barre latérale de mon blogue (http://oreilletendue.com/) pour indiquer quelles y sont les recherches les plus fréquentes.
J’ai installé YD Most Searched et je l’ai configuré.
Comme mon gabarit n’accepte pas les widgets, je dois éditer le fichier «Colonne latérale» pour parvenir à mes fins.
Étant un néophyte sur WordPress, c’est là que mes problèmes commencent…
Si je me fie au site http://bibliobabil.com (il comporte ce que je souhaite avoir sur mon blogue), j’imagine que je devrai utiliser quelque chose du genre
Voir ce que les autres cherchent
[ensuite ???]
mais, manifestement, ça ne suffit pas.
(J’ai peut-être tout faux par ailleurs…)
Tout renseignement sera le bienvenu.
Merci à l’avance.
le 13 February 2012 à 20:43 h
Hi i used your Plugin.
But i want to display these result as like normal wordpress does.
i mean to say i just want to show only 3 lines of the result post and then want to place more link at the end. How can we do this??