On 7/7/06, Tom Davies <[EMAIL PROTECTED]> wrote:
> Hi Dave,
>
> I currently only use a small subset of the Ferret API so this may not
> work universally for all areas you support sorting. One simple
> sorting solution would be to just support SQL style string expressions
> for sorting. It should be relatively easy to implement. So this
> code:
>
> sort_fields = []
> sort_fields << Ferret::Search::SortField.new('created_at')
> sort_fields << Ferret::Search::SortField.new('url')
> num = INDEX.search_each(query, :sort => sort_fields) do |doc, score|
>
> Could be rewritten as:
> num = INDEX.search_each(query, :sort => 'created_at, url') do |doc, score|
>
> And perhaps it could also support ASC DESC syntax as well.
>
> In general I think anywhere the Ferret API requires us to create
> internal Ferret classes and pass them in it would be nice if there was
> a way to abstract this from the caller as much as possible using
> simple datastructures such as symbols, strings and arrays.
Thanks for your feedback Tom. I couldn't agree more. In the version
I'm working on now for example, Documents are going to basically be
Hashes with a boost attribute. So everything you normally do with a
Hash, you'll be able to do with a Document.
By the way, did you already know you could do this in the current
version of Ferret?:
num = INDEX.search_each(query, :sort => ['created_at', 'url']) do
|doc, score|
The only problem with this is that it doesn't allow you to reverse the
sort. You have to do this;
url_sorter = Ferret::Search::SortField.new('url', :reverse => true)
num = INDEX.search_each(query, :sort => ['created_at',
url_sorter]) do |doc, score|
Maybe your sql sort string idea is a good one. Which do you think is better?
num = INDEX.search_each(query, :sort => 'created_at, url_sorter
DESC') do |doc, score|
or
num = INDEX.search_each(query, :sort => ['created_at',
'url_sorter', DESC]) do |doc, score|
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk