All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Separate search result by collection

TheJae 21 May 2012 09:03 question, complete

Hi Low,

I just purchased Low Search and i'd like to know if we're able to separate results by collection, for e.g, i have these collection Sport Shoe, High heels, Ballet shoe and Leather shoe. And I want the results to be displayed as follow when the user search for 'red colour'.

Sport Shoes (2 results)
-----------------------------------
1. Result item 1
1. Result item 2

High heels (1 result)
-----------------------------------
1. Result item 1

Ballet Shoes ( 4 results)
-----------------------------------
1. etc...
etc...

Replies

  1. Low 21 May 2012 09:08

    Currently, that's only possible if you add a low_search:results tag for each collection. However, that could cause some performance issues, 'cause each query will be executed for each tag.

    But let me ask this first: how are you handling pagination with a setup like this? Or are you not paginating search results?

  2. TheJae 21 May 2012 09:11

    I am not paginating.

    It's just a design thing, if it's not really recommended then i'll just output a list. I was hoping I could wrap the results as follow:

    {low_search_collection_sportshoes}
    {entryid} - {title} ({entry_date})
    {/low_search_collection_sportshoes}

  3. Low 21 May 2012 09:19

    I'm afraid that's not possible at the moment. But you could get the desired output by using PHP on Output in your template. Something like this:

    <?php 

    $results = array();

    {exp:low_search:results query="{segment_3}"}
    $results["{low_search_collection_label}"][] = <<<EOE
    <li>{entry_id} - {title} ({entry_date})</li>
    EOE;
    {/exp:low_search:results}

    ?>

    <!-- More template code -->

    <?php foreach ($results AS $collection => $rows): ?>
    <h3><?=$collection?> (<?=count($rows)?> results)</h3>
    <ul><?=implode("\n", $rows)?></ul>
    <?php endforeach; ?>