Order results by category?
Hi Low,
For the Low Search results, is it possible to order the results by category, in the same way that you can order the results by custom fields?
If so, could you tell me the syntax that I'd need to use for this please? My categories are all named 'category[]' so not sure what to use, if this is even possible.
Thanks,
Stephen
Replies
Low 3 Jul 2012 07:19
Hi Stephen,
By default, search results are ordered by relevance. You can also order the results exactly like you would order a channel:entries tag. Ordering by category is not possible, I'm afraid.
Stephen 4 Jul 2012 04:16
Hi Low,
In a 'keyword-less' search, are results ordered by the orderby and sort tags, or is there some sort of relevance matching in place here too if they're not used?
It's a shame you can't order by category. From my point of view, if I can filter results by it, I'd like to have the option to sort by it, so I guess this is a feature request. :-)
As a workaround, I think I'll just import my categories as 'dummy' custom fields, in addition to as categories, just so that I can sort by them.
Thanks,
Stephen
Low 4 Jul 2012 08:01
Keyword-less searches do not query the collection indexes, so no fulltext search is performed, which means no relevance can be calculated. It simply sets parameters to the channel:entries tag (which is called behind the scenes), thus filtering entries. You could say keyword-less searches are an advanced version of the Dynamic Parameters: http://expressionengine.com/user_guid...
Looking at the channe:entries tag, you can't order by category either, which is why it's not supported by LS. And thinking of it, how would you order by category? Alphabetically by first category assigned to the entry?
Stephen 5 Jul 2012 05:26
Hi Low,
Thanks for the explanation.
For info, I've got 4 category groups - Town, County, LA Area, and Region. Each entry is only assigned to one category from each of these groups, and my advanced search form looks like this.
I envisaged using something like this to order the results alphabetically by town (cat group 1), then county (cat group 2), then LA Area (cat group 3), then region (cat group 4), then by a custom field:
orderby="category_group_1|category_group_2|category_group_3|category_group_4|my_custom_field" sort="asc"
Maybe it's an edge-case thing, but I've got the workaround mentioned above so all is well. :-)
Thanks,
Stephen
Paul Cripps 1 May 2014 16:05
+1 for the order by categories, it would be a great addition to the site we're currently building.
We have a table list of results, with table headings for both custom fields and categories.
Each heading has a link, which toggles the direction of the results for the given data.
Using Mo’ Variables we simply add a link such as this:
{if get:sort=='desc'}
{low_search:url orderby='my_custom_field_name' sort='asc' result_page='/results'}
{if:else}
{low_search:url orderby='my_custom_field_name' sort='desc' result_page='/results'}
{/if}
Expanding this, and taking on board Stephen's thoughts it would be great if we could do the same for a category group:
{if get:sort=='desc'}
{low_search:url orderby_category_id='category_group_1' sort='asc' result_page='/results'}
{if:else}
{low_search:url orderby_category_id='category_group_1' sort='desc' result_page='/results'}
{/if}
We're taking his workaround on board and trying 'dummy' custom fields.
Low 1 May 2014 16:12
Ordering by category still makes no real sense to me, actually. What would happen if an entry is put in multiple categories? Where would it appear in the order?