vector
vector

Reputation: 7576

solr query for field value starting with a number

I have to modify a query that searches for a value starting with a letter (relevant snippet fo the query): &fq=Organization:"+letter+"*&

If I pass 'A' as the letter param I'll get 'ABC Hardware', something that start with an A.

How would i modify the letter variable to return only something that starts with a number, as '1A Widgets'.

Tried things like letter = '[0 TO 5]', but I honestly have no idea if I'm on the right track with that.

Upvotes: 0

Views: 1296

Answers (1)

brian519
brian519

Reputation: 318

Seems like a dupe of this question

For cases like this, my favourite approach is to index another boolean field called "StartsWithNumber" and then it's a simple boolean filter. This might not work for you if you can't reindex all of your documents.

For a brute force approach, you could do something like:

fq=Organization:0* OR Organization:1* OR Organization:2* OR .. etc

Not pretty, but fq's get cached so at least it should be fast.

Upvotes: 2

Related Questions