Akeem
Akeem

Reputation: 8227

Lucene search where a field MUST start with certain letters

I'm trying to search for results within a range e.g. A TO C. However the results are coming in with results that contain letters within the range but I only want results that START with letters within the range.

Upvotes: 0

Views: 2441

Answers (2)

Akeem
Akeem

Reputation: 8227

I ended up using frange provided by the QParser plugin available for solr 1.4

{!frange l=A u=C}fieldname

I got the info from here

Upvotes: 0

bajafresh4life
bajafresh4life

Reputation: 12883

Easiest way -- During index time, create another field that contains only the first letter. So if the field currently contains:

Alpha
Beta
Charlie

then index this in a separate field (non-analyzed):

A
B
C

Then use range query as usual

myFieldFirstLetter:[A TO C]

Upvotes: 1

Related Questions