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

Reply via email to