How to Search Multiple Keyword Using Search Core block?

Permalink 5 users found helpful
Hey guy! Anyone know how to make the search form (from the pre-loaded basic search block) with multiple keyword? Thanks!

View Replies: View Best Answer
RadiantWeb replied on at Permalink Best Answer Reply
you have to modify the search controller to explode the var by a delimiter (I chose comma).

one way is this starting on line 145 of the search block controller:

if (isset($_REQUEST['query'])) {
  $search_vars = explode(',',$_REQUEST['query']);
  foreach($search_vars as $key=>$var){

traisoon replied on at Permalink Reply
Cool! Thanks Chad! ^_^
ginslo replied on at Permalink Reply
Thanks very much Chad for this and to traisoon for posting the question. I was just preparing to do the same. Simple searches like 'Santa Fe' or 'New York' were failing. This fixes it perfectly. Do you know if there was any reason why this isn't in the core code by default or are there reasons why one wouldn't want this mod?
jordanlev replied on at Permalink Reply
See this thread for how to fix the problem with more than one word:

(And note that this fix will be implemented in the next release of C5)
Steevb replied on at Permalink Reply
Spent most of the morning working on this and it does not work for me?

Done all that was asked:- indexing, changing controller, etc.

If I search for more than one word in a sentence and they follow each other I get results.

If I try odd words that I know are in the content but do not follow each other I get no results.

So if visitors type in something that does not match exactly in page order they have no results?

Is there a way around this?

If not, then there is no point in having the search facility!
jordanlev replied on at Permalink Reply
I think ChadStrat's answer above would address this. If it's not working though I'm not sure what to do -- I've never used that myself. I agree that Concrete5's built-in search could definitely use some improvement.
Steevb replied on at Permalink Reply
Hi Jordan,

Done Chads and everything else.

It will not work from visitor point of view.

I have the word 'pink' and 'house' in my content but they are miles apart.

if I search for 'pink house' why does it not show in results?

There is no paid add-on to address this issue either?

We need help

Thanks for responding.
RadiantWeb replied on at Permalink Reply
hi, one reason could be your theme has an incorrect main content area i.e.-"main" (case sensitive, should be "Main").

This is a common mistake when dev'g custom themes, which in normal cases does not matter...but in the case of auto-indexing, it does. The indexer needs to have "Main" as the content area if I recall correctly.(someone correct me if I am wrong)

The search tool uses the PageSearchIndex table to speed things up...otherwise...searching would be RIDICULOUSLY slow.

So, I "think" the issue could be that you simply need to add a content area named "Main", then move your content to that area.(don't just remove and add..better to move it, then remove the old area). Then save your page, and the indexer should pick up that content.

Your search should then yield proper results.

This of course is specific to "content" or text. For atribute specific's a different story.

Steevb replied on at Permalink Reply
Hi Chad,
Thanks for getting back, all is as should be.
Themes always set up as normal with obligatory sections in the right format!
<div id="topnav">
<? $a = new Area('Header Nav');$a->display($c);?>
<article class="content">
<? $a = new Area('Heading');$a->display($c);?>
<? $a = new Area('Main');$a->display($c);?>
The reason for this headache is I've NEVER actually tried using it from the other point of view?
I just whack it in and away you go!!

But my new client has tried all the Concrete5 features I SHOUTED about and this one falls flat.......

What next?


JoeHiveCreative replied on at Permalink Reply
so, your content block is in the "Main" area? and you have ran the indexing job in your dashboard as a double measure?

Steevb replied on at Permalink Reply
Hi Chad and every one else,

As previously stated have done all updates, changes and additions. Have now spent ALL day trying to get this to work and it will not!!!

Either it it works or it does not work?

Does it work for you?

If it does work then its my fault?

If it does not work, why not?

Spent two hours looking at alternative ways to add a search.

Couldn't find one that I liked.

Looked at Google integration on the forums, no good.

Why is this so difficult?

Any light, anyone..........

Surely this is fundamental to the CMS?

All I want to do is find a couple of key words in my results?
Steevb replied on at Permalink Reply
This was literally driving me mad!

Has anybody else got this problem?

Does your search work with random typing?

I spent on and off close to 36 hours trying to get this to work!

Then it came to me!

look at other Concrete5 sites with the search facility plumbed in and see whose search box worked as I wanted.

Found one, type in something random and you get results, GREAT!

I don't why it works just yet, but it works.

I know going to laugh, but I'm not a developer and I was desperate!

Tried a cut & paste of the site code, blended it into my code.

Complete rubbish.

Found the Concrete5 version they are using.

Tried pasting that version controller.php and view.php.


This morning another flash of inspiration, try uploading the complete search block?

Hallelujah!! It works.........

Tried the same thing on two other sites and it works.

Slight glitch is it wont quite pick and highlight sometimes, but then I'm trying to be really extreme with my searches.

All I care about is that I get a response on the page and NOT:

'There were no results found. Please try another keyword or phrase.'

Not sure how to use Chadstrat's code just yet. But at least my client should stop ringing me every two hours!


My secret? I used the search block in its entirety found in Concrete5 version -

BTW: I'm running

Thanks for trying to help.
andrew replied on at Permalink Reply
Sorry it's been such an ordeal. Yeah, we kind of botched the search block in the latest release. You might try downloading the latest copy of the development concrete5 copy from here:

and then grabbing just the search block from there and see if it helps with any of the other problems you're having.
Steevb replied on at Permalink Reply
Thanks Andrew,

I'll have a play around.

Two sides to a coin?

One person moaning.

Could have been a lot MORE!

For the moment updating the others before they find out..........
Steevb replied on at Permalink Reply

Does not work for me?

Steevb replied on at Permalink Reply
Sorry again,

Forgot to say, I'll try running the whole thing locally (new C5) and see what happens.

Many thanks
rbnz replied on at Permalink Reply
I think I fixed it...

instead of a "," use a " "

then it'll split keywords by a space

if (isset($_REQUEST['query'])) {
   $search_vars = explode(' ',$_REQUEST['query']);
   foreach($search_vars as $key=>$var){

Can't get the highlighting to work though...
btw am using extended search addon - don't know if this makes a diff
emsconcrete replied on at Permalink Reply
I used rbnz's code and it works on multiple non-sequential keywords, but the description and highlighting disappear from the results. Has anyone figured out how to bring those back?

wwwdev3 replied on at Permalink Reply
Chad -- I tried this fix but it didn't seem to work. Here's the patch and the code before it. Does this look right?

function do_search() {
$q = $_REQUEST['query'];
$_q = preg_replace('/[^A-Za-z\']/i', '', $_REQUEST['query']);
$ipl = new IndexedPageList();
$aksearch = false;
if (is_array($_REQUEST['akID'])) {
foreach($_REQUEST['akID'] as $akID => $req) {
$fak = CollectionAttributeKey::getByID($akID);
if (is_object($fak)) {
$type = $fak->getAttributeType();
$cnt = $type->getController();
$aksearch = true;

// PUT IN PER POSTING ON C5 to make work with multi terms
if (isset($_REQUEST['query'])) {
$search_vars = explode(',',$_REQUEST['query']);
foreach($search_vars as $key=>$var){

///////////////////////////////////// END OF FIX

When will this be fixed in the core product?
wwwdev3 replied on at Permalink Reply
Chad -- Sorry followed the thread some more and found the reg exp fix. Thanks. -- Kelly
kaost replied on at Permalink Reply
Thanks Chad. Issue fixed.