Projects » wpSearchMu

wpSearchMu enables sitewide search over an entire WordPress Mu installation. It is an offshoot of the excellent wpSearch plugin, just extended to work for Mu instead of only ‘normal’ wordpress.

wpSearchMu replaces the default WordPress search with the open source Lucene search engine. This allows unparalleled result accuracy for your blog. With wpSearchMu, you can specify settings on a per blog level. This means that your root blog can be setup to search the entire Mu site, while each individual blog can be set up to search only itself (or any combination of blogs).

Current Version: 2.1.2

Download it here:
Download It HereWP Search Mu Plugin 2.1.2

More Info and Source Code

I just set up a repository at the generous wordpress.org site. Check out the wpSearchMu page for more info.

To download the source for your hackering pleasure, just type:

svn co http://svn.wp-plugins.org/wpsearchmu wpsearchmu

Installation

  1. Upload the wpSearchMu zip to your mu-plugins directory and unzip it. You should be left with a wp-search-mu.php and a wp-search-mu directory in the mu-plugins folder.
  2. Next, you’ll need to configure your search index options, and then build the full search index. Building the index may take a few minutes but you should rarely need to do this more than once.Also, so that Lucene can create the search index, you’ll need to set the permissions of the wpsearchmu directory to full permissions. From the root directory of your WordPress installation:
    chmod -R 777 wp-content/mu-plugins/wp-search-mu/
    
  3. After that, you’ll want to update your search.php to work with wpSearchMu’s search results.

Theme integration

You’ll need to update your search.php to work with results from more than one blog. At the beginning of the Loop, add:

switch_to_blog($post->blog_id);

and at the end, add:

restore_current_blog();

After your done, your search.php should look something like:

while (have_posts()) : the_post();
switch_to_blog($post->blog_id);
?>
<h2><a href="&lt;?php the_permalink() ?&gt;"></a></h2>
<div class="entry">

<a href="&lt;?php the_permalink() ?&gt;">Read more...</a></div>
restore_current_blog();
endwhile;
?&gt;

Also! If you’re using the Thematic framework for your theme needs, and don’t want to edit the search.php file directly, Adam Warner has a great write up describing how to get it working for Thematic child themes.

Also! If you want to query the index outside of the normal WordPress search.php file, then you can do that too! Have a look at the following code for how to query the search index of a particular blog.

// switch to the blog who's index you want to use
switch_to_blog(3);
$index = wpSearch_createIndexObject(false);
$s = "my search terms";
// get the results from the lucene index
$lq = "post_title:($s) post_content:($s) post_name:($s)";
$query = Zend_Search_Lucene_Search_QueryParser::parse($lq);
$hits = $index->find($query);

// interate over the results
// and output some HTML
$posts = array();
$count = 1;
foreach($hits as $hit){
$post = WPSearchResult::BuildWPResultFromHit($hit);
$posts[] = $post;
the_title();
echo "<br>";
}
restore_current_blog();

Before and After

Search accuracy was dramatically increased after installing wpSearchMu. Below is a sample screenshot showing the top result for searching my blog for “columnizer”. Default WordPress search on the left links to an unrelated post. The results on the right show wpSearchMu correctly linking to Columnizer’s project page.

Before and After

wpSearchMu Settings

Below is a summary of all the available options for wpSearchMu.

1. Index and search only want you want.

you can setup wpSearchMu to index every blog in your Mu install, or only certain blogs. You tell it to search only a specific list of blogs, or everything except a certain list of blogs.

2. Boosting / Weighting

‘Boosting’ one field higher than another will make that field more important in searches. Usually, the title is the most important thing to match in a search, but that’s up to you. Setup field weights to match what you think is important. You can setup custom weights not just for the title and body of a post, but for custom fields as well! Which brings us to…

3. Searching comments

One pitfall of WordPress’s default search is that it doesn’t also search comments. With wpSearchMu, you can optionally index all comments as well, not just posts and pages.

Wishlist

1. Searching custom fields

Have any important data tucked away in custom fields? I do! that’s why I extended wpSearchMu to include the ability to search custom fields.

FAQ

1. Why wpSearchMu?

wpSearchMu stands apart from Google CSE, OneSearch, and others, in that it’s based on the open source Lucene search engine, which yeilds much more accurate results compared to OneSearch. Unlike the Google search, it’s 100% tweakable, customizable, and doesn’t show unwanted mandatory ads.

2. What’s Lucene, and what’s a search index?

Lucene is an open source search engine/platform/framework that lets you index and search just about any data you put into it. A search index is just that, an index! like at the back of a book that lists the pages each word is on, Lucene’s index lets you quickly get the post, page, or comment from a given search query.

3. Can I index only certain blogs?

wpSearchMu lets you index all, some, or just one of the blogs in your Mu site. You have complete control over which blogs are included in your search index.

4. Can wpSearchMu be installed on just the root blog? or does it have to be installed on every blog?

The wpSearchMu plugin can be activated on any and every blog in the Mu installation, not just the root blog. You have complete control over which blogs wpSearchMu is activated on.

Not only that, but for each blog that wpSearchMu is installed on, the blog owner can decide which blogs to include in it’s search results. This means that, for every blog on the site, search results on their blogs search page to return results just from their own blog, or from some subset of blogs, or from every blog in the system.

As an example, I’ve installed wpSearchMu on my root blog and set it up to return results from the main blog and from /notes/. I’ve also setup the /bookmarks/ blog to only search bookmarks. Both of these searches are powered by wpSearchMu.

Changelog

For a complete list of what’s changed in each version, check out the full changelog.

234 responses to “wpSearchMu”

  1. Adam W. Warner

    @Remco,

    Thanks and I’ll be sure and do the same if I come up with a solution.

  2. Remco

    @Adam,

    With some determination I managed to solve this thing! I’m quite proud of it, as a novice php hacker :-)

    Now I can exclude a number of posts or pages for each blog individually. And the same for custom_post_types.

    I added 9 lines of code to the file wpSearch.php.
    (which is here: wp-content/mu-plugins/wp-search-mu/wpSearch.php)
    In my version (2.1.2) the changes start around line 427 and end at 452.

    Notes:
    -Changes/additions are commented with my initials //RK
    -You have to provide excluded page/post ids for every blog separately. I have two blogs in my multisite setup, one with id=1 and one with id=3. That could be different in your situation.
    - In this example I excluded two custom post types (slides and portfolio) and the posttype ‘nav_menu_item’ , because for some strange reason ‘nav menu items’ came up in my search results.
    - I’m not entirely sure of my php syntax, but I get no errors, so it’s probably fine. If somebody can write it more elegantly, let me know.
    - Important: after your modifications, you will have to rebuild the search index for all of your individual blogs before you can see the results.

    I will paste the modified code block below with some surrounding code, so you can do a search for this part.

    You can download a zip of the complete file here:
    http://bit.ly/aiB7vf

    I did some testing in my setup and all seems to work nicely and as you would expect.

    If you have any questions, let me know.

    if(!$blogs) $blogs = array();

    foreach ($blogs as $blog) {
    if($blog !== false) switch_to_blog($blog);

    /* This is to keep the system from running out of memory */
    /* Process posts from the database in batches of $postsPerBatch */
    $postsPerBatch = 20;
    $cursor = 0;

    $excludedposts = “”; //RK added
    $excludedtypes = “”; //RK added

    if ($blog == ’1′) { //RK added
    $excludedposts = ’565, 230, 703, 694, 724, 706′; } //RK added: excluded posts or pages in blog with id=1
    if ($blog == ’3′) {
    $excludedposts = ’565, 703, 694, 724, 706′; } //RK added: excluded posts or pages in blog with id=3

    $excludedtypes = “‘slide’, ‘portfolio’, ‘nav_menu_item’”; //RK added: excluded custom post types plus nav_menu_item because I got search results from some nav_menu_items

    //
    // if $blog === false, then we’re in normal
    // wordpress, otherwise we’re in wordpress mu
    //
    // we need _posts and _options tables for this to work
    $blogPostsTable = $wpdb->prefix . “posts”;

    do
    {
    $index = wpSearch_createIndexObject($create_index,$index_blog_id);
    $sql = “SELECT *
    FROM $blogPostsTable
    WHERE ID NOT IN ($excludedposts)
    AND post_type NOT IN ($excludedtypes)
    AND post_status = ‘publish’
    LIMIT $cursor, $postsPerBatch”;//RK added the lines with $excludedposts and $excludedtypes. Don’t forget the AND in the line with post_status

    $posts = $wpdb->get_results($sql);

  3. Adam W. Warner

    @Remco,

    Thanks for this, truly, however it’s not working for me yet.

    I have replaced the wpSearch.php file with your version and then added two page ids for testing the results.

    I was getting three results for the “Bath” page, one from each of three blogs with ids 1, 3, and 7. This page on blog id 1 has an id of 71. So, in your code, I have this:
    if ($blog == ’1′) { //RK added
    $excludedposts = ’71′; } //RK added: excluded posts or pages in blog with id=1

    I then rebuilt the search index on blogs id 1,3,7, then went to the search for each blog to test and received no search results at all…just none.

    I put the original wpSearch.php up, then rebuilt all three blog search indexes. I then was back to my normal search results (three pages for each match).

    I’m racking my brain thinking of what the missing link might be but so far no luck.

  4. Remco

    @Adam,

    Sounds like you have a php syntax error. Did the rebuilding with the new code take as long as the rebuilding with the old code? I’m asking because when I did not have the correct syntax yet, I had the same issue, and the rebuilding took much shorter, and there were no search results.
    Just to be sure: you have the plugin in mu-plugins directory?

    It’s working on my install… could you send me your file so I can take a look at it? remcoATremcokalfDOTnl

  5. Adam W. Warner

    The rebuilding of the new code did NOT take long at all which is suspect for sure.

    I do have the plugin in mu-plugins (just as has been). Just to be clear, the path to the wpSearch.php I have replaced is at:
    /wp-content/mu-plugins/wp-search-mu/wpSearch.php

    I have only removed your post/page ids from the list and replaced with my own. I will email you my version so you can take a look.

    I do appreciate it:) Hopefully, I’ve just made a simple mistake…

  6. Remkus

    Hi,

    I’ve managed to get this plugin to work with the Genesis Theme Framework, but I am getting search results that resolve into 404′s when clicked on the provided link. It appears the plugin doesn’t add the proper subsite folder structure to the plugin wants to show a page it’s found on a site where the given page is not located. Have you heard of this issue before and/or do you know of a solution?

  7. Paul

    Hi,

    I am using the wpSearchMu plugin to search posts across two wordpress MU sites.

    The wpSearchMu initially works however when I try to index a post to search just that, it still comes up with results for other blog posts that I have NOT indexed.

    Also it still finds results of posts that I have deleted from the trash.

    Any help would be appreciated, thank you.

  8. Erwin

    I’m having the same problem as Remkus though I’m not using the Genesis Theme Framework.

  9. Juri

    Hi,
    I tried to use this plugin but when I build the index it creates many cloned posts and trashed posts and the search functionality in the Admin Panel –> Posts doesn’t work anymore. It breaks my site…any suggestions?
    Thanks

  10. Juri

    Hi Adam,
    I’m running WP 3.0 and I’m using many plugins but the issue still happens if I disable all of them. Probably wrong installation?
    Here it is what I did:
    Created mu-plugins folder and unzipped the files there.
    After move the file wp-search-mu.php in the mu-plugin folder.
    Now you have wp-search-mu.php file and “wpsearchmu” folder in the mu-plugins folder, right?
    Moved the subfolder “wp-search-mu” within the “wpsearchmu” folder into the main folder “mu-plugins” and remove the old folder “wpsearchmu” that would contain only the readme file.
    Only now I found the Wp Search Mu options in the Wp Admin panel.

    Edited Search.php and insert these*** lines

    ***blog_id); ?>***

    and

    ******

    Anything wrong?

  11. Andreas

    Hi,

    I have two mirror-installs of my site, one on a subdomain called beta and then a live-installation on the main-domain.

    While the plugin works perfect on the beta-domain (where I get the message ‘wpSearchMu is properly configured and indexed. All searches on this blog use wpSearchMu instead of the regular WordPress search.’) once on the live-install I receive the message ‘Since there is no index built for this blog, the default WordPress search will be used.’… I just can’t figure out why. Feels like I’ve tried everything by know so any suggestions on what this might be due to would be greatly appreciated! Thanks in advance :)

  12. List of potential plug in to double check « Project NAZCA

    [...] 11- http://welcome.totheinter.net/wpsearchmu/ [...]

  13. Roger

    This plug-in is great! Very well-documented code. Thank you!

    I was wondering, is there any intention to integrate faceted search capabilities into this? How hard would this be?

  14. Blogofant

    Is it possible to integrate the solr search engine? I am wondering u said u use lucene but isn’t it a java installation nessesary to use lucene? Because I installed solr for search diffrent webpages under drupal and now i want the search also for my first wpmu innstallation. I thought this is a possible way with your module to add lucene / solr. Maybe I didn’t understand the way your lucene integratyion works. Can u give me a hint of my missunderstanding? by the way really cool plugin!

  15. Ben

    I’ve been reluctant to comment. Thinking it may be user error, but we’d been using a previous version (2.0.1, I believe)with great results when we were running WordPress 2.9.2. I like this plugin because it not only searches posts, but pages also. Recently we moved our entire site to a new webhost, then we upgraded to WordPress 3.0.4 and upgraded wpsearchmu to version 2.1.2. We went through and fixed our permissions to 777 within the new server, installed as informed above, and when we run the indexing, it never completes. When I then go to another page or load the wpsearchmu settings/option, it tells me it is installed and properly indexed, but when I try and search for anything on the front side (only within that specific blog), I get a blank screen. This also affects any time any of my content editors on any of their respective sites try and submit edits or save a new post/page. They also get a blank screen although it does save.

    What might be causing this and what could I do to get this plugin to work?

  16. Newman

    I’m having trouble installing this plugin. I got through the first few steps and set the permissions to 777, but I never see any new options in my settings panel. This means I can’t go ahead and index it or use the plugin.

  17. NewYorkCityZoo

    Had to hack this a little to get it working. Was getting valid header errors after activating. Had to pull the plugin out of its containing folder. Dropped the wp-search-mu.php into the plugin folder. This fixed the header error.

    Like this:
    /plugins/wp-search-mu
    /plugins/wp-search-mu.php (eek!)

    Then since my wordpress version is 3.04 I got an error saying this plugin should be in the mu-plugins directory. My installation does not have this directory. Did a previous version have that directory for multisite plugins? Anyways the hack takes place in the wpSearch.php file. Line 877 “else if” needs to be commented out since its looking for mu-plugins to be in the url. After that the plugin works great!

    Thanks for the plugin and Ill check to see if someone has submitted the bug.

  18. Chris B

    God I loved this plugin…Until I updated to WordPress 3.1.

    It’s broke. Any chance of this thing getting updated?

  19. dajense

    Would love to check this out but apperently it’s broken in 3.1.
    The BE options are just not showing. Any chance for a fix?

  20. affiliscore

    would like to use this plugin – will you be updating it to support the latest version of wordpress?

  21. Bad Nasty Hacker

    chmod 777?

    Let EVERYONE read/write to EVERY file in Zend, Lucene, and this plugin?

    Seriously, you’ve GOT to be FUCKING CRAZY. Why not just put the root password up in the search results?

  22. rudy

    yeh, you’re right….777!!!!!!!!
    knowing this, i can hack loads of sites!!!

    you can chmod runtime with php….why not then?
    chmod 777 before indexing, then set back after indexing……

  23. sun

    wp-search-mu. php and wp-search-mu in the mu-plugins folder, but not showing anything?
    Plugins file what all don’t put?
    thanks!

  24. sun

    Search Chinese why not?

  25. Tony

    It doesn’t seem like this plugin works correctly if you have the domain mapping plugin installed. I am able to index from the root site but not from any other site on the network. Also results that show up in the root site search from blogs on other domains does not show the correct domain but only the sub directory path.

  26. Adam W. Warner

    For others looking for robust search for standard and Multisite, look at the following actively developed plugin: http://wordpress.org/extend/plugins/yolink-search/

    If this helps, please consider subscribing to my site (linked above in my signature)

  27. Trinzia

    Is this plugin actively supported?
    It would seem that “mu” is now part of the regular WordPress, and there hasn’t been an update in 1.5 years on wordpress site.

    I see the plugin allows search of custom fields, but can I create a form which will restrict the search only to a specified custom field?

    For example if I had a recipe site, and Ingredients were added in a Custom Field, can I then make a form that will allow a person to search only in Ingredients? How about to allow them to search NOT an ingredient, such as no eggs?

    Thanks.

  28. Grant

    Hi there. Is there any way to run the search index from the command line? My WP deployments are automated, and I’d like to build the index as soon as they are deployed. If I can do this from the command line it saves me some config

  29. Dcqxuics

    I’m on business http://yucijuluho.blog.free.fr/ pretteen teens bbs What a hot fuck! Sweet sucking, amazing body, and even takes her facial with a smile…where do I sign up!

  30. Ajivodav

    I’d like to send this parcel to http://uhicifequlol.de.tl tiny models pictures She has a way with her voice and her Asian language that is so hot and sexy to hear, her body is as sexy too. And she always knows when to use her hands she is very sexy and hot to watch.

  31. Saorjfjt

    I’m interested in http://tomiijafe.de.tl child models strawberry wow, she might be the cutest real, natural chick on this site. look like a beginner on this video… what’s the name?

  32. Gybfyoow

    I’d like to pay this cheque in, please http://ikyguokata.de.tl artistic nude preteen Sweet, hmm you want get my photos…you can find them on my profile in info – about me.. enjoy ..

  33. Vpbaeljw

    Will I have to work shifts? http://cocosenepa.de.tl 1894 cowboy model Why did this anonymous cunt say black dick and black girl in the title.Black women shouldnt do interracial hasen’t the white man raped his slaves enough?Damn liar

1 3 4 5
Google Author link