Cheers Pat

I'm hoping it's not such an odd case, it's just that we need to
display search results based on lots of different criteria, not just
simply ordering by date or title etc. I think your previous suggestion
about creating a new attribute based on CRC32-ing the various fields
to group_by is excellent and I will implement that today and report
back on how successful it is. My main concern was that if I do start
grouping like that, I might loose control over the order in which the
records are displayed within the group. i.e which record actually
displays, representing the group. I will play with the group_clause
and see how I get on.

Apart from that, I was just interested in the difference between using
group_by in the model and group_by in the query.

As always, thanks for getting back.

Shaun


On Jan 25, 2:45 am, Pat Allan <[email protected]> wrote:
> Hi Shaun
>
> TS really works best if a normal search translates nicely across to each row 
> in the model's table, instead of grouping on that table's columns (ie: each 
> document id in Sphinx should map to a record in the table). So I'd stick to 
> using Sphinx's grouping instead when searching.
>
> I've not tested it, but if you wanted to group for *every* search on a 
> specific model, you may be able to use :group_by et al in your define_index 
> block, like so:
>   set_property :group_by => 'group_num'
>
> I see this as a pretty odd case, though... would it be better changing the 
> way your tables are structured instead? Though that maybe isn't a good fit 
> from the overall perspective of the app.
>
> --
> Pat
>
> On 24/01/2010, at 5:02 PM, Shaun wrote:
>
>
>
> > Hi Pat
>
> > Thanks for getting back to me mate. Greatly appreciated!
>
> > Yeah, that sounds like a good idea, I hadn't thought of it like that -
> > it just takes thinking about things a little differently. Thanks for
> > the pointer.
>
> > Is there any more information on the difference between using group_by
> > in the search query and using it in the index? If you group in the
> > index by one field and then use group by in the search query on
> > another field, what would be happening behind the scenes there?
>
> > Also, is it possible to set the group clause when grouping at the
> > index level to set the order by which the records are grouped?
>
> > Thanks again
>
> > Shaun
>
> > On Jan 23, 9:14 pm, Pat Allan <[email protected]> wrote:
> >> Hi Shaun
>
> >> There was support for grouping on a pair of attributes back in Sphinx 
> >> 0.9.8, but that was really just a hack for 64bit int support, which is now 
> >> in 
> >> 0.9.9.http://www.sphinxsearch.com/forum/view.html?id=890http://www.sphinxse...
>
> >> If you want results grouped by format and title together, why not set a 
> >> single attribute that CRC's both of them?
> >>   has "CRC32(CONCAT(format, title))", :as => :group_num, :type => :integer
>
> >> --
> >> Pat
>
> >> On 22/01/2010, at 7:35 PM, Shaun wrote:
>
> >>> Hi there
>
> >>> Is there a way I can group my results by multiple attributes? I have
> >>> many records that contain the same data in a few fields and need to
> >>> collapse them into one record. Am I right in thinking the :group_by
> >>> option in the search method only allows one attribute to be specified?
> >>> I have tried :group_by => 'field_one, field_two' but I then get zero
> >>> results from the search. I am also specifying the group_function as
> >>> attr and a group_clause as results within the group need to be
> >>> ordered:
>
> >>> Product Model:
>
> >>> define_index do
> >>>    indexes title
>
> >>>    has "CRC32(format)", :as => :num_format, :type => :integer
> >>>    has "CRC32(title)", :as => :num_title, :type => :integer
> >>>    has "COUNT(DISTINCT suppliers.id)", :as => :supplier_count, :type
> >>> => :integer
> >>> end
>
> >>> @products = Product.search(
> >>>            :conditions => {:title => params[:q]},
> >>>            :page => params[:page] || 1,
> >>>            :index => 'product_core', #I have another index in the
> >>> same model
> >>>            :group_by => 'num_format',
> >>> #would like to say  :group_by => 'num_title, num_format',
> >>>            :group_function => :attr,
> >>>            :group_clause   => "supplier_count desc"
> >>>            )
>
> >>> Is there something else I should be doing?
>
> >>> Any suggestions welcome!
>
> >>> Many thanks
>
> >>> Shaun
>
> >>> --
> >>> You received this message because you are subscribed to the Google Groups 
> >>> "Thinking Sphinx" group.
> >>> To post to this group, send email to [email protected].
> >>> To unsubscribe from this group, send email to 
> >>> [email protected].
> >>> For more options, visit this group 
> >>> athttp://groups.google.com/group/thinking-sphinx?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Thinking Sphinx" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to 
> > [email protected].
> > For more options, visit this group 
> > athttp://groups.google.com/group/thinking-sphinx?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to