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 Adrian M Bell <di...@amberservices.co.uk> on 2008/07/22 11:08:24 UTC

Alphabetical search on solr

Ok this might be a simple one, or more likely, my understanding of solr is
shot to bits....

We have a catalogue of documents that we have a solr index on.  We need to
provide an alphabetical search, so that a user can list all documents with a
title beginning A, B and so on...

So how do we do this?

Currently we have built up the following query:

<domain>/solr/select/?q=titleLong(a*)&rows=50

Whilst this is fine, it returns ALL documents that have an 'A' anywhere in
the title and as you can imagine, there are quite a few of these!  So
obviously we then strip out the results that don't begin with A.  This seems
to be incredibly wasteful to me.

Any one got any ideas?
-- 
View this message in context: http://www.nabble.com/Alphabetical-search-on-solr-tp18585264p18585264.html
Sent from the Solr - User mailing list archive at Nabble.com.


Re: Alphabetical search on solr

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jul 22, 2008, at 5:08 AM, Adrian M Bell wrote:
> We have a catalogue of documents that we have a solr index on.  We  
> need to
> provide an alphabetical search, so that a user can list all  
> documents with a
> title beginning A, B and so on...
>
> So how do we do this?
>
> Currently we have built up the following query:
>
> <domain>/solr/select/?q=titleLong(a*)&rows=50

I'm assuming that is a typo and the query should be titleLong:a* (w/  
colon).

> Whilst this is fine, it returns ALL documents that have an 'A'  
> anywhere in
> the title

This depends on what analyzer you have set up for titleLong, but it  
probably is only returning back documents that have words in the title  
that begin with "a", correct?

> and as you can imagine, there are quite a few of these!  So
> obviously we then strip out the results that don't begin with A.   
> This seems
> to be incredibly wasteful to me.
>
> Any one got any ideas?


When presented with a situation where you want to look something up by  
part of a field, rather than contorting the query, consider it an  
indexing effort.   Index a firstLetterOfTitle field, such that the  
only values of that field would be A-Z (normalize on case too, so they  
are all either all uppercase or all lowercase).  The indexing client  
could extract that field, or you could use a copyField for the  
longTitle into this new field associated with an analyzer that outputs  
only the first letter.  There is probably a way to configure the built- 
in KeywordTokenizerFactory->PatternReplaceFilterFactory to accomplish  
this.

	Erik