How to change search block to filterByAttribute?
Permalinkfunction 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.
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
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.
Guess the search block needs a bit of overwork, as it makes use of IndexedPageList which is depricated.
Would greatly appreciate your help (code example) to filterByAttribute to match all multiple attributes selected by select boxes (attached screenshot)
Take a look
http://www.concrete5.org/marketplace/addons/search-tools/...
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?