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

Support archive

Low Search - Dynamic Sorting / Sort by # Parents

alan poon 12 Nov 2012 18:31 question, complete

Hi,

Been using Low Search for a week now, awesome add-on! Just had a couple questions related to sorting:

1) What's the best way to give the user sorting options? Right now, every time I need to "update" my searches I use invisible text inputs with all of the selected keywords, categories, and parent/child relationships, and then resubmit the form. Should I be using dynamic parameters instead?

2) Is there any way to sort by the total number of parents of a specific channel?

Thanks in advance!
Alan

Replies

  1. Low 12 Nov 2012 21:36

    Hi Alan,

    1) Sorry, re-submitting the Form is the only way at the moment. I do have some ideas how to improve this, which I'll add to the feature-request list.

    2) Again, sorry. The only sorting options are by relevance (the default), or anything the native channel:entries tag can use.

  2. alan poon 13 Nov 2012 16:47

    Thanks for the response!

    If I understand correctly, with #1 there are no functional limitations, in that you can still achieve the same results as dynamic parameters (e.g. sorting buttons), you just need to write a bit more code to re-input all of the original values. Is that right?

    For #2 though - I feel like this would be valuable functionality:Take the Event / Performer example from the ExpressionEngine user manual, you'd need to be able to sort by number of parents in order to list the top performers by number of apperances... Is there a workaround to use SQL for this? Would this be a candidate for the feature-request list?

    Thanks,
    Alan

  3. Low 14 Nov 2012 11:19

    If I understand correctly, with #1 there are no functional limitations, in that you can still achieve the same results as dynamic parameters (e.g. sorting buttons), you just need to write a bit more code to re-input all of the original values. Is that right?


    Yes, that's right. Remembering a search query should be easy to implement with the search form. Just add the query="" param and set some conditionals in place.

    As for ranking entries depending on number of parents/children; that looks like a tricky issue. I'll consider it, but cannot make any guarantees.

  4. alan poon 29 Nov 2012 16:38

    Sorry for coming back to this, just want to make sure I'm doing this right...

    I pasted my code below for a "sort by date - descending" link, and I have to duplicate that code for "sort by date - ascending", "sort by name - descending", etc... Seems excessive... Wondering if there's an easier / better way to do this (I tried using dynamic variables, but it wasn't "keeping" all of the existing search criteria)

    Thanks!
    Alan

    <!--
    {!-- Link: Sorting by date - desc --}

    {exp:low_search:form collection="my_collection" search_mode="all" result_page="search_results" query="{segment_2}" require_all="category" secure="no" form_id="my_form"}

    {!-- Keep existing categories searched with hidden checkboxes --}

    {exp:channel:categories channel="my_channel" style="linear"}
    {if category_id IN ({low_search_category})}

    <input type="checkbox" name="category[]" value="{category_id}" checked="checked" style="display:none;"/>
    {/if}

    {/exp:channel:categories}

    {!-- Keep existing keyword searched with a hidden textbox --}

    <input type="text" class="field" name="keywords" id="s" value="{low_search_keywords}" style="display:none;" />

    {!-- Set order and sort: date, desc --}

    <input type="checkbox" name="orderby" value="date" checked="checked" style="display:none;"/>
    <input type="checkbox" name="sort" value="desc" checked="checked" style="display:none;"/>

    {!-- Link --}

    <a href="javascript:{}" onclick="document.getElementById('my_form').submit(); return false;">Sort Desc</a>

    {/exp:low_search:form}
    -->

  5. alan poon 29 Nov 2012 16:51

    Just thought of another option - instead of:

    <!--
    {!-- Set order and sort: date, desc --}

    <input type="checkbox" name="orderby" value="date" checked="checked" style="display:none;"/>
    <input type="checkbox" name="sort" value="desc" checked="checked" style="display:none;"/>

    {!-- Link --}

    <a href="javascript:{}" onclick="document.getElementById('my_form').submit(); return false;">Sort Desc</a>
    -->

    I could have the href call a javascript function which set those two variables... That way, I don't have to repeat all of that code for each link.

    Although would still be interested in finding out the "recommend" way to do this :)

    Cheers,
    Alan

  6. Low 30 Nov 2012 07:58

    Hi Alan,

    This is how you'd go about this at the moment. I do have something on my todo-list to make this (a lot) easier, but that will come in a next version somewhere.

  7. Low 30 Nov 2012 09:39

    Actually, scratch that, it's already possible with the URL tag. If you feed it the query="" parameter, any other parameters set (like sort) will override the values in the query="" parameter.

    So, for example:

    <a href="{exp:low_search:url query="{segment_3}" sort="desc"}">Descending order</a> 
    <a href="{exp:low_search:url query="{segment_3}" sort="asc"}">Ascending order</a>

  8. alan poon 30 Nov 2012 17:06

    Oh man, that is SO much easier.... Glad I asked

    Thanks!!!