How to change search block to filterByAttribute?

Permalink
I'm overriding the 'search' block controller's 'do_search' function:
function do_search() {
      $q = $_REQUEST['query'];
      Loader::library('database_indexed_search');
      $ipl = new IndexedPageList();
      $ipl->filterByKeywords($q);
      if( is_array($_REQUEST['search_paths']) ){ 
         foreach($_REQUEST['search_paths'] as $path) {
            //if(!strlen($path)) continue;
            $ipl->addSearchPath($path);
         }
      }
      $res = $ipl->getPage(); 
      foreach($res as $r) { 
         $results[] = new IndexedSearchResult($r['cID'], $r['cName'], $r['cDescription'], $r['score'], $r['cPath'], $r['content']);
      }

If I change the loader library for a model and change the filterByKeywords for filterByAttribute:
function do_search() {
      $q = $_REQUEST['query'];
      $length = $_REQUEST['length'];
      $continent = $_REQUEST['continent'];
      $adventure = $_REQUEST['adventure'];
      $interest = $_REQUEST['interest'];
      $attributeKeyHandle = 'continent';
      //Loader::library('database_indexed_search');
      //$ipl = new IndexedPageList();
      //$ipl->filterByKeywords($q);
      Loader::model('page_list');
      $ipl = new PageList();
      $ipl->filterByAttribute('continent', '%' . $continent . '%', 'like');
      if( is_array($_REQUEST['search_paths']) ){ 
         foreach($_REQUEST['search_paths'] as $path) {

it throws an error: "Fatal error: Class 'IndexedSearchResult' not found in /srv/www/htdocs/c5/blocks/search/controller.php".

And if I add a library 'Loader::library('indexed_search');', it says "Fatal error: Cannot use object of type Page as array in /srv/www/htdocs/c5/blocks/search/controller.php"

How can I search for pages by attributes and only show those which match all? Thank you.

linuxoid
 
linuxoid replied on at Permalink Reply
linuxoid
$%@%$@#%#^%#^%@^#&^##$%%!!!!!!! I'll be damned!!! I've just got back to a default Search block controller, just changed the filterByKeywords for filterByAttribute - it showed me that fatal database error which said something about 'cIndexScore' table couldn't be found, then by pure luck I saw this in the database_indexed_search.php:
class IndexedPageList extends PageList {
   public function getPage() {
      $this->sortByMultiple('cIndexScore desc', 'cDatePublic desc');
      $r = parent::getPage();
      $results = array();
      foreach($r as $c) {
         $results[] = array('cID' => $c->getCollectionID(), 'cName' => $c->getCollectionName(), 'cDescription' => $c->getCollectionDescription(), 'score' => $c->getPageIndexScore(), 'cPath' => $c->getCollectionPath(), 'content' => $c->getPageIndexContent());
      }
      return $results;
   }
}

So I've removed the 'cIndexScore desc' from the getPage() function and it started workign! The search actually finds the attributes and displays all relevant pages. Holy sh*t! I've wasted 3 weeks trying to fix this. I don't know if removing 'cIndexScore desc' broke something else, but at least the search works.

Can anyone shed some more light on this? What's the 'cIndexScore desc' and why doesn't this table exist in the database?
jincmd replied on at Permalink Reply
jincmd
Could you link me to a page that displays this mod in action?
linuxoid replied on at Permalink Reply
linuxoid
You mean to a real web page? Sorry, I'm currently running only on localhost. What would you like to see? Maybe I can take some screen shots and attach them here.
jincmd replied on at Permalink Reply
jincmd
That would be just as well....
synlag replied on at Permalink Reply
synlag
cIndexScore is not set in <web-root>/concrete/config/db.xml, dunno might be a miss, i couldn't locate it elsewhere.

sortByMultiple is implemented in item_list.

i've found a comment by andrew
/**
* @DEPRECATED.
* Just use PageList with filterByKeywords instead. We'll keep this around so people know what to expect
*/

filterByKeywords and filterByAttribute works fine.

http://docs.concrete5addons.com/... might help
linuxoid replied on at Permalink Reply
linuxoid
If you read my first post, when I changed IndexedPageList for just PageList, it gave me those two errors: "Fatal error: Class 'IndexedSearchResult' not found in /srv/www/htdocs/c5/blocks/search/controller.php" and "Fatal error: Cannot use object of type Page as array in /srv/www/htdocs/c5/blocks/search/controller.php".

Could you please paste a code example of searching by attributes? If my page has a few attributes and some have multiple choices, will it search and match only all those set or I have to implement it all in a loop myself, checking for each attribute for each query? Thank you.
synlag replied on at Permalink Reply
synlag
Yes, i see.

Guess the search block needs a bit of overwork, as it makes use of IndexedPageList which is depricated.
linuxoid replied on at Permalink Reply 1 Attachment
linuxoid
How come the Documentation (http://www.concrete5.org/documentation/developers/pages/searching-and-filtering/) shows Filtering Methods Available - $pl->filterByAttribute($attributeKeyHandle, $value, $comparison) when it doesn't exist in the page_list.php?

Would greatly appreciate your help (code example) to filterByAttribute to match all multiple attributes selected by select boxes (attached screenshot)
synlag replied on at Permalink Reply
synlag
It's implemented in Matogertels search tools package.

Take a look

http://www.concrete5.org/marketplace/addons/search-tools/...
Tony replied on at Permalink Reply
Tony
related thread, with some code examples and some explanations:

http://www.concrete5.org/index.php?cID=51736...