You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lucy.apache.org by Saurabh Vasekar <sv...@listenlogic.com> on 2012/06/19 19:51:52 UTC

[lucy-user] Sort results based on a particular field

Hello,

I am using the Lucy library. How do I sort the results of the search based
on a particular field of an index. Suppose I am creating an index based on
a field and I want to see the results in sorted order
(ascending/descending) order. Can it be done in Lucy? I am using Perl to
search through the indexes I have created. Also, the field against which I
want to sort is an integer but while creating the index I have specified
the field as FullTextType.

e.g.

$field = Lucy::Plan::FullTextType->new(
           analyzer => $polyanalyzer,
);

$schema->spec_field( name => 'field', type => $field);

The order in which the sorted results are generated will differ based on
the type of field. Suppose if field is of type string and it contains
values 1, 100 and 2. Then sorted order in this case will be
1
100
2

If field is of type integer then sorted order will be
1
2
100

How can I sort based on integer and string in Lucy? Is it possible?

Thank you.

Re: [lucy-user] Sort results based on a particular field

Posted by Peter Karman <pe...@peknet.com>.
Saurabh Vasekar wrote on 6/19/12 12:51 PM:

> 
> How can I sort based on integer and string in Lucy? Is it possible?
> 

I do not believe non-string field types have been released in a public API yet.
For sorting on integer-like strings, I run my input data through sprintf() to
created fixed-width strings.

For more on sorting see:

https://metacpan.org/module/Lucy::Search::SortSpec


-- 
Peter Karman  .  http://peknet.com/  .  peter@peknet.com