Search only functions if one word is entered

Permalink 2 users found helpful
As the title states, the C5 search only functions if a single word is input. Otherwise, if more than one word is entered, the search results are null. I am updated and have indexed my site many times.

Any suggestions?

rbucky
 
Mnkras replied on at Permalink Reply
Mnkras
this is fixed in the svn,

stick this in
/concrete/blocks/search/controller.php

<?
defined('C5_EXECUTE') or die("Access Denied.");
class SearchBlockController extends BlockController {
   var $pobj;
   protected $btTable = 'btSearch';
   protected $btInterfaceWidth = "400";
   protected $btInterfaceHeight = "170";
   public $title = "";
   public $buttonText = ">"; 
   public $baseSearchPath = "";
   public $resultsURL = "";
   protected $hColor = '#EFE795';
   public function highlightedMarkup($fulltext, $highlight) {
      $this->hText = $fulltext;
      $this->hHighlight  = str_replace(array('"',"'","&quot;"),'',$highlight); // strip the quotes as they mess the regex
Mnkras replied on at Permalink Best Answer Reply
Mnkras
seems the code tags are screwed up,

<?
defined('C5_EXECUTE') or die("Access Denied.");

class SearchBlockController extends BlockController {

var $pobj;

protected $btTable = 'btSearch';
protected $btInterfaceWidth = "400";
protected $btInterfaceHeight = "170";

public $title = "";
public $buttonText = ">";
public $baseSearchPath = "";
public $resultsURL = "";

protected $hColor = '#EFE795';

public function highlightedMarkup($fulltext, $highlight) {
$this->hText = $fulltext;
$this->hHighlight = str_replace(array('"',"'","&quot;"),'',$highlight); // strip the quotes as they mess the regex
$this->hText = @preg_replace( "#$this->hHighlight#i", '<span style="background-color:'. $this->hColor .';">$0</span>', $this->hText );
return $this->hText;
}

public function highlightedExtendedMarkup($fulltext, $highlight) {
$text = @preg_replace("#\n|\r#", ' ', $fulltext);

$matches = array();
$highlight = str_replace(array('"',"'","&quot;"),'',$highlight); // strip the quotes as they mess the regex

$regex = '([a-z|A-Z|0-9|\.|_|\s]{0,45})'. $highlight .'([a-z|A-Z|0-9|\.|_|\s]{0,45})';
preg_match_all("#$regex#i", $text, $matches);

if(!empty($matches[0])) {
$body_length = 0;
$body_string = array();
foreach($matches[0] as $line) {
$body_length += strlen($line);

$body_string[] = $this->highlightedMarkup($line, $highlight);

if($body_length > 150)
break;
}
if(!empty($body_string))
return @implode("....", $body_string);
}
}

/**
* Used for localization. If we want to localize the name/description we have to include this
*/
public function getBlockTypeDescription() {
return t("Add a search box to your site.");
}

public function getBlockTypeName() {
return t("Search");
}

public function getJavaScriptStrings() {
return array('search-title' => t('Please enter a valid search title.'));
}

function __construct($obj = null) {
parent::__construct($obj);
if ($this->title == '') {
$this->title=t("Search");
}
}

public function indexExists() {
$db = Loader::db();
$numRows = $db->GetOne('select count(cID) from PageSearchIndex');
return ($numRows > 0);
}

function view(){
$c = Page::getCurrentPage();
$this->set('title', $this->title);
$this->set('buttonText', $this->buttonText);
$this->set('baseSearchPath', $this->baseSearchPath);

//auto target is the form action that is used if none is explicity set by the user
$autoTarget= $c->getCollectionPath();
/*
* This code is weird. I don't know why it's here or what it does

if( is_array($_REQUEST['search_paths']) ){
foreach($_REQUEST['search_paths'] as $search_path){
$autoTarget=str_replace('search_paths[]='.$search_path,'',$autoTarget);
$autoTarget=str_replace('search_paths%5B%5D='.$search_path,'',$autoTarget);
}
}
$autoTarget=str_replace('page='.$_REQUEST['page'],'',$autoTarget);
$autoTarget=str_replace('submit='.$_REQUEST['submit'],'',$autoTarget);
$autoTarget=str_replace(array('&&&&','&&&','&&'),'',$autoTarget);
*/

$resultTargetURL = ($this->resultsURL != '') ? $this->resultsURL : $autoTarget;
$this->set('resultTargetURL', $resultTargetURL);

//run query if display results elsewhere not set, or the cID of this page is set
if( !empty($_REQUEST['query']) || isset($_REQUEST['akID'])) {
$this->do_search();
}
}

function save($data) {
$args['title'] = isset($data['title']) ? $data['title'] : '';
$args['buttonText'] = isset($data['buttonText']) ? $data['buttonText'] : '';
$args['baseSearchPath'] = isset($data['baseSearchPath']) ? $data['baseSearchPath'] : '';
if( $args['baseSearchPath']=='OTHER' && intval($data['searchUnderCID'])>0 ){
$customPathC = Page::getByID( intval($data['searchUnderCID']) );
if( !$customPathC ) $args['baseSearchPath']='';
else $args['baseSearchPath'] = $customPathC->getCollectionPath();
}
if( trim($args['baseSearchPath'])=='/' || strlen(trim($args['baseSearchPath']))==0 )
$args['baseSearchPath']='';
$args['resultsURL'] = ( $data['externalTarget']==1 && strlen($data['resultsURL'])>0 ) ? trim($data['resultsURL']) : '';
parent::save($args);
}

public $reservedParams=array('page=','query=','search_paths[]=','submit=','search_paths%5B%5D=' );

function do_search() {
$q = $_REQUEST['query'];
$_q = trim(preg_replace('/[^A-Za-z0-9\s\']/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;
}
}
}

if((empty($_REQUEST['query']) && $aksearch == false) || $this->resultsURL != '') {
return false;
}

$ipl->setSimpleIndexMode(true);
if (isset($_REQUEST['query'])) {
$ipl->filterByKeywords($_q);
}

if( is_array($_REQUEST['search_paths']) ){

foreach($_REQUEST['search_paths'] as $path) {
if(!strlen($path)) continue;
$ipl->filterByPath($path);
}
}

$res = $ipl->getPage();

foreach($res as $r) {
$results[] = new IndexedSearchResult($r['cID'], $r['cName'], $r['cDescription'], $r['score'], $r['cPath'], $r['content']);
}

$this->set('query', $q);
$this->set('paginator', $ipl->getPagination());
$this->set('results', $results);
$this->set('do_search', true);
}

}

?>
rbucky replied on at Permalink Reply
rbucky
Hell yeah. That worked like a charm. Thank you...
ryan replied on at Permalink Reply
ryan
I believe I fixed this in subversion a week or so back.
rbucky replied on at Permalink Reply
rbucky
It did not come through with the updates for me, if it was supposed to. But, works now.
Mnkras replied on at Permalink Reply
Mnkras
it was added right after 5.4.1.1 was released,
zoinks replied on at Permalink Reply
My controller.php file pretty much looks the same as that, but I copied and pasted it in there anyway and uploaded it.

It still will not find anything beyond one word.

I searched: "my first blog post"
Results: no matches

I searched: first
Result: YES

I searched: blog
Result: YES

I am using the latest version of C5 as of July 8, 2011.

Doesn't seem like this should be a problem this far into the game... seems like something that would be fixed on version 1, so I'm confused. Why does this only seem to be an issue for some of us?
markm replied on at Permalink Reply
You say "pretty much." Did you copy the code block listed above and ensure proper permissions were set?
zoinks replied on at Permalink Reply
Well, I did say "pretty much," but I ended that sentence with...

"...but I copied and pasted it in there anyway and uploaded it."

So, I that answers your first question.

And, yes, I did set up the search pages through the site map and index the site via the site maintenance section, otherwise the search function wouldn't return anything at all.

I guess this must be some error that just slipped through on 5.4.1.1 because I can't imagine it's been there all along.
zoinks replied on at Permalink Reply
Well, maybe I need to put controller.php in the other directory to get it to work. I was doing the override thing. I'll try that now...

EDIT: actually, that will have to wait til tomorrow since I don't have the FTP info on me. Drat.
zoinks replied on at Permalink Reply
UPDATE: THIS DID WORK. Eventually. Thank you, Mnkras. So, it's nothing I did, it is just an error that slipped through... so I should make a note somewhere, I guess, for future sites.
GroupeSolution2 replied on at Permalink Reply
Hi!
I know your post dates from a while back but I’m giving it a shot any way.

I’m running version: 5.6.3.2 and can’t get my C5 search bloc to use more than one word.
I’ve entered the code in /concrete/blocks/search/controller.php you kindly provided but with no results – still only one word.

Anything else I should try or do?

Thanks in advance for your reply
rbucky replied on at Permalink Reply
rbucky
Have you taken a look at C5's Git repo for the latest config?https://github.com/concrete5/concrete5....
PassionForCreative replied on at Permalink Reply
PassionForCreative
I'm currently putting a site together for an alternative therapist who has a ton of treatments for a ton of ailments. The site search is something that we see being used quite often. When I search for Joint Pain, I get a handful of results linking me to the relevant pages.

However if I search for Period Pain I get nothing. If I search for Pain on it's own I get a lot of results, with Period Pain being among them. Can anyone help point me in the right direction?
Steevb replied on at Permalink Reply
Steevb
Hi,

Have you got Chadstrat's modified code in place?

"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);
  }
}




Have you looked at Jack's Extended Search add on?

http://www.concrete5.org/marketplace/addons/extended-search/...
boomgraphics replied on at Permalink Reply
boomgraphics
I think they fixed this in the latest release of c5...
PassionForCreative replied on at Permalink Reply
PassionForCreative
I got to the bottom of this. We are dealing with a Marketing "Expert" who gave his feedback and this was one of his comments. On further investigation the search term he gave isn't mentioned on the site so it would be hard for the site search to find it wouldn't it. He'll need to re-write his content to take this into account.

Thanks for all the suggestions guys.
Steevb replied on at Permalink Reply
Steevb
Hi,

I had this also with a site, the search word was 'Restaurants', but never mentioned in any of pages?
simonchilton replied on at Permalink Reply
simonchilton
Hi. I've read quite a few posts like this but none quite fit the bill. I'm working on a c5 5.4.2.2. site and the search only matches exact phrases, not individual words. I'd like it to match (and highlight in the results) ANY words, but prioritize results that contain ALL WORDS.

Has anyone got a way to do this? Is it better in 5.5.x?

Thanks.
frz replied on at Permalink Reply
frz
With some tinkering you can configure search to work with alot of different
requirements.
its not going to highlight in results .
I'd explore using google search on your site. works very well
best wishes

Franz Maruna
CEO - concrete5.org
http://about.me/frz
inukshuk replied on at Permalink Reply
This free Extended search add on works just fine with more than one word :)
http://www.concrete5.org/marketplace/addons/extended-search/...