How to make Concrete5's Search/Search Indexing Work

Overview

Concrete5's search is made up of two main systems, The search block provides the users search box and the search indexer which indexes the content of the local site. Here's some common pitfalls using the search functionality and how to resolve them.

Search results mess up the layout

When you add a search block to a page, the default behavior is to return the results on the same page as the search box, this typically results in your search results displaying in a sidebar, header or some other place they really shouldn't show up.

sidebar_search.png

The best way to set this up, is to create a page (add page), I'll call mine Search Results. In the main area of that page, add a new search block with the default options, then exit edit mode and publish your changes. Go back to any other search blocks you have on your site and select the "post to another page elsewhere" option and enter the path of your new search results page.

search_results_edit.png

Now searching from your search blocks will now post to your own dedicated search results page and display results in the Main Area.

search_results.png

Search results only return results from some pages and some content.

By default Concrete5 only indexes areas named: 'Main Content' and 'Main', on a default install of concrete5 this will be where all your actual content is, but on a customized site with custom page types, you may have other areas you'd like to be searched. To configure this you'll have to get into the code just a little bit.

Override the index_search.php job file by copying it from [site root]/concrete/jobs/index_search.php to [site root]/jobs/index_search.php

Then open up the file in the editor of your choice and modify the run() function. In the code below I'm making the indexer index the content from two additional areas "Custom Area 1" and "Custom Area 2"

public function run() {
Loader::model('attribute/categories/collection');
Loader::model('attribute/categories/file');
Loader::model('attribute/categories/user');
Cache::disableLocalCache();
$attributes = CollectionAttributeKey::getList();
$attributes = array_merge($attributes, FileAttributeKey::getList());
$attributes = array_merge($attributes, UserAttributeKey::getList());
foreach($attributes as $ak) {
$ak->updateSearchIndex();
}

Loader::library('database_indexed_search');
$is = new IndexedSearch();

// Add These Lines
$is->addSearchableArea('Custom Area 1');
$is->addSearchableArea('Custom Area 2');

$result = $is->reindexAll();
return t('%s page(s) indexed.', $result->count);
}
}

save your changes, then go to the Dashboard -> Maintenance section and re-run your search indexer.

If you've added any custom blocks and the content from those blocks are not showing up in your search results the problem is most likely that the block developer did not include the "getSearchableContent()" function in the block's controller. This function should returns trimmed down text content for a given block. Below is the getSearchableContent function from the core content block's controller:

public function getSearchableContent() {
return $this->content;
}

 

Including Page Attributes in search results

You can include page attributes in your search results by modifying the attribute type in: Dashboard -> Pages and Themes -> Page Types -> Attributes

search_attributes.png

Recent Discussions on this Topic

What Gets Searched And What Doesn't?

I've updated search indexing in the dashboard but much of my text is not included. Does standard search only index meta tags such as Description and Keywords? Sorry if this has been answered before but I can't find it in the forum.

Not working - help!

Hi, have set up a search function for searching our news section. I have created the new page for search results, with a search block - this works if done by itself. I have also setup the search block on the original page and set it to show results on the…

Search not working in custom layout?

when you add a custom layout with the new add layout function, the search results can not be shown for the text in those layouts? what do i need to change in the /jobs/index_search.php i added some lines but couldn't get it to index anything in the add…

Question regarding search function

I've created my website, have ecommerce installed on it. When I create a new product, I give it a stock number, such as N98. When I search "N98" I get a "no items found" type message. However, when I search on the term "necklace" (of which N98 is), I get …

Searchable scrapbook blocks?

How can I enable a search in a scrapbook block? When I add a default content block in the scrapbook, and I place this content (alias) on several pages, it's not found by the search engine.