Sort order Search results

Permalink
Hello,

i'm overriding the search block to do a custom search for page attributes. This all seems to work, the pages with the attribute value searched for get returned.
But the alphabetical sorting of the results doesn't work.

in the controller.php - do_search() function i added the following line

$ipl->sortByName(); //--should do the sorting?
      $ipl->filter(false, '(ak_exclude_search_index = 0 or ak_exclude_search_index is null)');
      $res = $ipl->getPage();


but the results come back unsorted

where did i go wrong or what did i miss?

Thank you

gr Marco

stmarco
 
jordanlev replied on at Permalink Best Answer Reply
jordanlev
I've learned from my own projects that using the "IndexedPageList" class (like the search block does) is a waste of time -- it doesn't provide any added functionality over the normal "PageList" class, and worse than that it *removes* functionality that PageList has. For example, it doesn't let you set a SortBy field, and it doesn't provide all of the data for each returned collection object. It's really very weird and I don't quite understand why it exists in the first place.

So you can either change the search controller and view to use the normal PageList class, or you can override the "IndexedPageList" code so it doesn't override your sorting. Which version of C5 are you using?
stmarco replied on at Permalink Reply
stmarco
Hello Jordan

thanks, this was not an urgent problem but one i had to solve in the end. I'm using Concrete 5.5.2.1

I have altered the code from

$ipl = new IndexedPageList();

to
$ipl = new PageList();


and worked with the results

instead of
$results[] = new IndexedSearchResult($r['cID'], $r['cName'], $r['cDescription'], $r['score'], $r['cPath'], $r['content']);

i used
$results[] =  array("cID"=>$r->getCollectionID(), "cName"=>$r->getCollectionName());


then in the view.php i altered everything to use the cID to get the page info instead of the indexedpagelist object.
tudorsv replied on at Permalink Reply
Wow finally, Thank you so much Jordan ! I have wasted almost all day trying to get sortBy(...) to work in the Search block controller and I thought I was the problem...