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!

traisoon
 
RadiantWeb replied on at Permalink Best Answer Reply
RadiantWeb
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){
      $ipl->filterByKeywords($var);
  }
}


Chad
traisoon replied on at Permalink Reply
traisoon
Cool! Thanks Chad! ^_^
ginslo replied on at Permalink Reply
ginslo
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
jordanlev
See this thread for how to fix the problem with more than one word:
http://www.concrete5.org/index.php?cID=112065...

(And note that this fix will be implemented in the next release of C5)
Steevb replied on at Permalink Reply
Steevb
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
jordanlev
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
Steevb
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
RadiantWeb
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 needs...it's a different story.

ChadStrat
Steevb replied on at Permalink Reply
Steevb
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);?>
</div>
<article class="content">
<? $a = new Area('Heading');$a->display($c);?>
<section>
<? $a = new Area('Main');$a->display($c);?>
</section>
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?

Thanks

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

Chad
Steevb replied on at Permalink Reply
Steevb
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
Steevb
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.

Worse.

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!

HAPPY DAYS!!


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

BTW: I'm running 5.4.1.1

Thanks for trying to help.
andrew replied on at Permalink Reply
andrew
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:

https://github.com/concrete5/concrete5...

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
Steevb
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
Steevb
Whoops!!!

Does not work for me?

Sorry
Steevb replied on at Permalink Reply
Steevb
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
rbnz
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){
   $ipl->filterByKeywords($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
emsconcrete
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?

Thanks,
George
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']);
Loader::library('database_indexed_search');
$ipl = new IndexedPageList();
$aksearch = false;
if (is_array($_REQUEST['akID'])) {
Loader::model('attribute/categories/collection');
foreach($_REQUEST['akID'] as $akID => $req) {
$fak = CollectionAttributeKey::getByID($akID);
if (is_object($fak)) {
$type = $fak->getAttributeType();
$cnt = $type->getController();
$cnt->setAttributeKey($fak);
$cnt->searchForm($ipl);
$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){
$ipl->filterByKeywords($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.
michaeloz replied on at Permalink Reply
FYI, still seeing this issue today. Working on a clean install. Overrode
concrete/blocks/search/controller.php in application/blocks/search/controller.php to get this to work.

<?php
namespace Application\Block\Search;
use Concrete\Block\Search\Controller as SearchBlockController;
use Concrete\Core\Page\PageList;
use Concrete\Core\Attribute\Key\CollectionKey;
class Controller extends SearchBlockController
{
    /**
     * Highlight parts of a text (extended version).
     *
     * @param string $fulltext the whole text
     * @param string $highlight The text to be highlighted
     *
     * @return string|null
     */