Search code examples
sqlruby-on-railsrubysearchlogic

How to add a GROUP_BY clause in a Searchlogic query?


I'm using Searchlogic with Rails 2.3.5 and I need to do add a GROUP_BY clause with 2 columns to my query. I tried:

User.search.group = "column1, column2"     # Undefined method 'group'
User.search(:group => "column1, column2")  # Searchlogic::Search::UnknownConditionError: The group is not a valid condition. You may only use conditions that map to a named scope

And neither worked. I couldn't find any other ways in Searchlogic's docs. Is there any other way?


Solution

  • According to this page: http://vladzloteanu.wordpress.com/2009/01/25/searchlogic-plugin-activerecord-search-on-steroids/

    You can probably use:

    User.search.conditions.group("column1,column2")