How to change search block to filterByAttribute?
Permalink
I'm overriding the 'search' block controller's 'do_search' function:
If I change the loader library for a model and change the filterByKeywords for filterByAttribute:
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.
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']); }
Viewing 15 lines of 19 lines. View entire code block.
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) {
Viewing 15 lines of 28 lines. View entire code block.
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.
Could you link me to a page that displays this mod in action?
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.
That would be just as well....
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
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
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.
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.
Yes, i see.
Guess the search block needs a bit of overwork, as it makes use of IndexedPageList which is depricated.
Guess the search block needs a bit of overwork, as it makes use of IndexedPageList which is depricated.
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)
Would greatly appreciate your help (code example) to filterByAttribute to match all multiple attributes selected by select boxes (attached screenshot)
It's implemented in Matogertels search tools package.
Take a look
http://www.concrete5.org/marketplace/addons/search-tools/...
Take a look
http://www.concrete5.org/marketplace/addons/search-tools/...
related thread, with some code examples and some explanations:
http://www.concrete5.org/index.php?cID=51736...
http://www.concrete5.org/index.php?cID=51736...
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?