Order Low Search Results by Low Events Date Field
Hi,
We use Low Search to search within different collections using keywords. We would like the results for a search by keywords within the Events collection to be ordered by a Low Events date (start date) field and the results for search by keywords within any other collection to continue to be ordered by relevance.
Currently we cannot get any of the keyword searches to be ordered by the Low Events date field.
Our query looks like this:
http://staging.artpractical.com/archi...
How can we accomplish this? We already extended the search for this website by writing custom filters. In fact we were wondering if this is existing functionality which we broke somehow OR the Low Search module can't do this out of the box.
Thanks.
Replies
Matts Härsing 30 Jan 2015 05:33
I'm doing this with Stash. You will have to show the results separately as it would make no sense otherwise. Like so:
<!-- Do search and save results to Stash -->
{exp:stash:set_list name="search_results"}
{exp:low_search:results query="{segment_N}" collection="collection_1|collection_2" orderby="section" sort="asc"}
{stash:title}{title}{/stash:title}
{stash:url_title}{url_title}{/stash:url_title}
{stash:summary}{long_title}{/stash:summary}
{stash:entry_date}{entry_date}{/stash:entry_date}
{stash:low_search_collection_name}{low_search_collection_name}{/stash:low_search_collection_name}
{stash:low_search_score}{low_search_score}{/stash:low_search_score}
{stash:low_search_excerpt}{low_search_excerpt}{/stash:low_search_excerpt}
{/exp:low_search:results}
{/exp:stash:set_list}
<!-- Search finished -->
<!-- Split the results and show them -->
<!-- COLLECTION 1, ordered by date -->
{exp:stash:get_list name="search_results" match="#collection_1#" against="low_search_collection_name" orderby="entry_date" sort="asc"}
{title}
{summary}
{/exp:stash:get_list}
<!-- COLLECTION 2, ordered by score -->
{exp:stash:get_list name="search_results" match="#collection_2#" against="low_search_collection_name" orderby="low_search_score" sort="desc"}
{title}
{summary}
{/exp:stash:get_list}
<!-- Done! -->
Low 30 Jan 2015 08:05
Looking at your template code, you could use JavaScript to change the value of a (hidden) orderby parameter when you select a Collection. For example, set the value of
to "event_date|asc" when the collection id is 7, and empty it out (triggering the default) when it is not 7.
You should be able to sort by the events field name itself, not using a modifier, ie "events_field" rather than "low_events:start_date".
Stoyan Vasilev 2 Feb 2015 18:32
Thanks for the input. We upgraded to the latest version of Low Search and implemented your suggestion.
Everything works and now we are wondering if there is a way to sort the same results by event end date. Is this possible (even if we have to write something ourselves)?
Thanks.
Stoyan Vasilev 2 Feb 2015 18:47
We also just flipped the order using the orderby_sort field which you mentioned and when the results are in reverse chronological order the the sorting doesn't work properly.
This is independent of the question above (we don't have the modifier in our code).
Low 2 Feb 2015 19:02
You should be able to use the same value as you would with the Low Events Entries tag: orderby="low_events:end"
Not exactly sure what you mean with the second question, tho. Can you elaborate? Possibly in a new thread, along with all the data (version info, template code, debugger output)?
Stoyan Vasilev 2 Feb 2015 20:15
Hey,
For issue #1 neither of these work -- events are not ordered by end date:
http://staging.artpractical.com/archi...
http://staging.artpractical.com/archi...
For issue #2 this does not work properly -- you will see in the fourth column that the order is not correct:
http://staging.artpractical.com/archi...
Does this make things clearer?
Thanks.
Low 2 Feb 2015 20:24
I'll need to take a look myself. Please send SuperAdmin login credentials to hi at gotolow dot com if you can.
Stoyan Vasilev 2 Feb 2015 20:30
Just shared them with you.
Low 2 Feb 2015 21:18
Hmm, I reckon I need to migrate Low Events' extension file (which takes care of LS compatibility now) to a proper Low Search filter. Will tinker tomorrow.
Stoyan Vasilev 2 Feb 2015 21:43
Sounds good. Please keep us posted. We were supposed to relaunch the Events section with the updated functionality that you see today and these two issues are the only items left.
Thanks!