You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Marc Sturlese <ma...@gmail.com> on 2009/08/24 11:58:56 UTC

Optimizing a query to sort results alphabetically for a determinated field

Hey there, I need to sort my query results alphabetically for a determinated
field called "town". This field is analyzed with a KeywordAnalyzer and isn't
multiValued. Add that some docs doesn't doesn'h have this field.
Doing just:

http://localhost/solr//select/?q=whatever&version=2.2&start=0&rows=10&indent=on&sort=town
asc

Will give me back the results sorted alphabetically but will put the docs
that doesn't have this field (town) at the begining.
I want them at the end or I want them not to apear. This query solves the
problem:

http://localhost/solr//select/?q=whatever&version=2.2&start=0&rows=10&indent=on&sort=town
asc&fq=town:[a TO z]

But applying this filter: fq=town:[a TO z] is definitely not good in terms
of memory, speed and clauses...
Is there any way to do something similar but with a more optimized query?
Thanks in advance!

-- 
View this message in context: http://www.nabble.com/Optimizing-a-query-to-sort-results-alphabetically-for-a-determinated-field-tp25113379p25113379.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Optimizing a query to sort results alphabetically for a determinated field

Posted by Avlesh Singh <av...@gmail.com>.
Ah ... I just got wiser!
Thanks Erik.

Cheers
Avlesh

On Mon, Aug 24, 2009 at 4:39 PM, Erik Hatcher <er...@gmail.com>wrote:

>
> On Aug 24, 2009, at 7:03 AM, Avlesh Singh wrote:
>
>  Can you really sort accurately on tokenized fields?
>>
>
> Yes, as long as there is *one and only one* term emitted from the analyzer.
>  KeywordTokenizer is your friend, and comes in handy to lowercase or pattern
> replace things.
>
>        Erik
>

Re: Optimizing a query to sort results alphabetically for a determinated field

Posted by Erik Hatcher <er...@gmail.com>.
On Aug 24, 2009, at 7:03 AM, Avlesh Singh wrote:

> Can you really sort accurately on tokenized fields?

Yes, as long as there is *one and only one* term emitted from the  
analyzer.  KeywordTokenizer is your friend, and comes in handy to  
lowercase or pattern replace things.

	Erik

Re: Optimizing a query to sort results alphabetically for a determinated field

Posted by Avlesh Singh <av...@gmail.com>.
Can you really sort accurately on tokenized fields?

Cheers
Avlesh

On Mon, Aug 24, 2009 at 3:54 PM, Marc Sturlese <ma...@gmail.com>wrote:

>
> Yes but I thought it was just for sortable fields:
> sint,sfloat,sdouble,slong.
> Can I apply "sortMissingLast"to  text fields analyzed with KeywordAnalyzer?
>
> Constantijn Visinescu wrote:
> >
> > There's a "sortMissingLast" true/false property that you can set on your
> > fielType definitions in the schema.
> >
> > On Mon, Aug 24, 2009 at 11:58 AM, Marc Sturlese
> > <ma...@gmail.com>wrote:
> >
> >>
> >> Hey there, I need to sort my query results alphabetically for a
> >> determinated
> >> field called "town". This field is analyzed with a KeywordAnalyzer and
> >> isn't
> >> multiValued. Add that some docs doesn't doesn'h have this field.
> >> Doing just:
> >>
> >>
> >>
> http://localhost/solr//select/?q=whatever&version=2.2&start=0&rows=10&indent=on&sort=town
> >> asc
> >>
> >> Will give me back the results sorted alphabetically but will put the
> docs
> >> that doesn't have this field (town) at the begining.
> >> I want them at the end or I want them not to apear. This query solves
> the
> >> problem:
> >>
> >>
> >>
> http://localhost/solr//select/?q=whatever&version=2.2&start=0&rows=10&indent=on&sort=town
> >> asc&fq=town:[a<
> http://localhost/solr//select/?q=whatever&version=2.2&start=0&rows=10&indent=on&sort=town%0Aasc&fq=town:%5Ba
> >TO
> >> z]
> >>
> >> But applying this filter: fq=town:[a TO z] is definitely not good in
> >> terms
> >> of memory, speed and clauses...
> >> Is there any way to do something similar but with a more optimized
> query?
> >> Thanks in advance!
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Optimizing-a-query-to-sort-results-alphabetically-for-a-determinated-field-tp25113379p25113379.html
> >> Sent from the Solr - User mailing list archive at Nabble.com.
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Optimizing-a-query-to-sort-results-alphabetically-for-a-determinated-field-tp25113379p25113637.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
>

Re: Optimizing a query to sort results alphabetically for a determinated field

Posted by Marc Sturlese <ma...@gmail.com>.
It just worked. Thanks a lot! Good to know sortMissingLast works not just in
sortable fields

Constantijn Visinescu wrote:
> 
> not 100% sure  but the example schema has:
>     <fieldType name="string" class="solr.StrField" sortMissingLast="true"
> omitNorms="true"/>
> 
> So i'd say give it a go and see what happens ;)
> 
> On Mon, Aug 24, 2009 at 12:24 PM, Marc Sturlese
> <ma...@gmail.com>wrote:
> 
>>
>> Yes but I thought it was just for sortable fields:
>> sint,sfloat,sdouble,slong.
>> Can I apply "sortMissingLast"to  text fields analyzed with
>> KeywordAnalyzer?
>>
>> Constantijn Visinescu wrote:
>> >
>> > There's a "sortMissingLast" true/false property that you can set on
>> your
>> > fielType definitions in the schema.
>> >
>> > On Mon, Aug 24, 2009 at 11:58 AM, Marc Sturlese
>> > <ma...@gmail.com>wrote:
>> >
>> >>
>> >> Hey there, I need to sort my query results alphabetically for a
>> >> determinated
>> >> field called "town". This field is analyzed with a KeywordAnalyzer and
>> >> isn't
>> >> multiValued. Add that some docs doesn't doesn'h have this field.
>> >> Doing just:
>> >>
>> >>
>> >>
>> http://localhost/solr//select/?q=whatever&version=2.2&start=0&rows=10&indent=on&sort=town
>> >> asc
>> >>
>> >> Will give me back the results sorted alphabetically but will put the
>> docs
>> >> that doesn't have this field (town) at the begining.
>> >> I want them at the end or I want them not to apear. This query solves
>> the
>> >> problem:
>> >>
>> >>
>> >>
>> http://localhost/solr//select/?q=whatever&version=2.2&start=0&rows=10&indent=on&sort=town
>> >> asc&fq=town:[a<
>> http://localhost/solr//select/?q=whatever&version=2.2&start=0&rows=10&indent=on&sort=town%0Aasc&fq=town:%5Ba
>> >TO
>> >> z]
>> >>
>> >> But applying this filter: fq=town:[a TO z] is definitely not good in
>> >> terms
>> >> of memory, speed and clauses...
>> >> Is there any way to do something similar but with a more optimized
>> query?
>> >> Thanks in advance!
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/Optimizing-a-query-to-sort-results-alphabetically-for-a-determinated-field-tp25113379p25113379.html
>> >> Sent from the Solr - User mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Optimizing-a-query-to-sort-results-alphabetically-for-a-determinated-field-tp25113379p25113637.html
>> Sent from the Solr - User mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Optimizing-a-query-to-sort-results-alphabetically-for-a-determinated-field-tp25113379p25114941.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Optimizing a query to sort results alphabetically for a determinated field

Posted by Constantijn Visinescu <ba...@gmail.com>.
not 100% sure  but the example schema has:
    <fieldType name="string" class="solr.StrField" sortMissingLast="true"
omitNorms="true"/>

So i'd say give it a go and see what happens ;)

On Mon, Aug 24, 2009 at 12:24 PM, Marc Sturlese <ma...@gmail.com>wrote:

>
> Yes but I thought it was just for sortable fields:
> sint,sfloat,sdouble,slong.
> Can I apply "sortMissingLast"to  text fields analyzed with KeywordAnalyzer?
>
> Constantijn Visinescu wrote:
> >
> > There's a "sortMissingLast" true/false property that you can set on your
> > fielType definitions in the schema.
> >
> > On Mon, Aug 24, 2009 at 11:58 AM, Marc Sturlese
> > <ma...@gmail.com>wrote:
> >
> >>
> >> Hey there, I need to sort my query results alphabetically for a
> >> determinated
> >> field called "town". This field is analyzed with a KeywordAnalyzer and
> >> isn't
> >> multiValued. Add that some docs doesn't doesn'h have this field.
> >> Doing just:
> >>
> >>
> >>
> http://localhost/solr//select/?q=whatever&version=2.2&start=0&rows=10&indent=on&sort=town
> >> asc
> >>
> >> Will give me back the results sorted alphabetically but will put the
> docs
> >> that doesn't have this field (town) at the begining.
> >> I want them at the end or I want them not to apear. This query solves
> the
> >> problem:
> >>
> >>
> >>
> http://localhost/solr//select/?q=whatever&version=2.2&start=0&rows=10&indent=on&sort=town
> >> asc&fq=town:[a<
> http://localhost/solr//select/?q=whatever&version=2.2&start=0&rows=10&indent=on&sort=town%0Aasc&fq=town:%5Ba
> >TO
> >> z]
> >>
> >> But applying this filter: fq=town:[a TO z] is definitely not good in
> >> terms
> >> of memory, speed and clauses...
> >> Is there any way to do something similar but with a more optimized
> query?
> >> Thanks in advance!
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Optimizing-a-query-to-sort-results-alphabetically-for-a-determinated-field-tp25113379p25113379.html
> >> Sent from the Solr - User mailing list archive at Nabble.com.
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Optimizing-a-query-to-sort-results-alphabetically-for-a-determinated-field-tp25113379p25113637.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
>

Re: Optimizing a query to sort results alphabetically for a determinated field

Posted by Marc Sturlese <ma...@gmail.com>.
Yes but I thought it was just for sortable fields: sint,sfloat,sdouble,slong.
Can I apply "sortMissingLast"to  text fields analyzed with KeywordAnalyzer?

Constantijn Visinescu wrote:
> 
> There's a "sortMissingLast" true/false property that you can set on your
> fielType definitions in the schema.
> 
> On Mon, Aug 24, 2009 at 11:58 AM, Marc Sturlese
> <ma...@gmail.com>wrote:
> 
>>
>> Hey there, I need to sort my query results alphabetically for a
>> determinated
>> field called "town". This field is analyzed with a KeywordAnalyzer and
>> isn't
>> multiValued. Add that some docs doesn't doesn'h have this field.
>> Doing just:
>>
>>
>> http://localhost/solr//select/?q=whatever&version=2.2&start=0&rows=10&indent=on&sort=town
>> asc
>>
>> Will give me back the results sorted alphabetically but will put the docs
>> that doesn't have this field (town) at the begining.
>> I want them at the end or I want them not to apear. This query solves the
>> problem:
>>
>>
>> http://localhost/solr//select/?q=whatever&version=2.2&start=0&rows=10&indent=on&sort=town
>> asc&fq=town:[a<http://localhost/solr//select/?q=whatever&version=2.2&start=0&rows=10&indent=on&sort=town%0Aasc&fq=town:%5Ba>TO
>> z]
>>
>> But applying this filter: fq=town:[a TO z] is definitely not good in
>> terms
>> of memory, speed and clauses...
>> Is there any way to do something similar but with a more optimized query?
>> Thanks in advance!
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Optimizing-a-query-to-sort-results-alphabetically-for-a-determinated-field-tp25113379p25113379.html
>> Sent from the Solr - User mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Optimizing-a-query-to-sort-results-alphabetically-for-a-determinated-field-tp25113379p25113637.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Optimizing a query to sort results alphabetically for a determinated field

Posted by Constantijn Visinescu <ba...@gmail.com>.
There's a "sortMissingLast" true/false property that you can set on your
fielType definitions in the schema.

On Mon, Aug 24, 2009 at 11:58 AM, Marc Sturlese <ma...@gmail.com>wrote:

>
> Hey there, I need to sort my query results alphabetically for a
> determinated
> field called "town". This field is analyzed with a KeywordAnalyzer and
> isn't
> multiValued. Add that some docs doesn't doesn'h have this field.
> Doing just:
>
>
> http://localhost/solr//select/?q=whatever&version=2.2&start=0&rows=10&indent=on&sort=town
> asc
>
> Will give me back the results sorted alphabetically but will put the docs
> that doesn't have this field (town) at the begining.
> I want them at the end or I want them not to apear. This query solves the
> problem:
>
>
> http://localhost/solr//select/?q=whatever&version=2.2&start=0&rows=10&indent=on&sort=town
> asc&fq=town:[a<http://localhost/solr//select/?q=whatever&version=2.2&start=0&rows=10&indent=on&sort=town%0Aasc&fq=town:%5Ba>TO z]
>
> But applying this filter: fq=town:[a TO z] is definitely not good in terms
> of memory, speed and clauses...
> Is there any way to do something similar but with a more optimized query?
> Thanks in advance!
>
> --
> View this message in context:
> http://www.nabble.com/Optimizing-a-query-to-sort-results-alphabetically-for-a-determinated-field-tp25113379p25113379.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
>