Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using Regex in SOLR Query

I have a data set of street names and numbers which I need to search.

eg. 12 HILL STREET
    12A HILL STREET
    12B HILL STREET
    123 HILL STREET
    12 HILARY STREET

If I search as follows q=(street_name:12\ HILL*), I get

12 HILL STREET

I want to obtain the following results:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

12 HILL STREET
12A HILL STREET
12B HILL STREET

Is there a way to query in SOLR to return the results as the above example shows?

I have tried querying as:

q=(street_name:/12[A-Z]\ HILL*/)

but don’t get anything back.

>Solution :

You can use

q=(street_name:/12[A-Z]* HILL.*/)

Here, the pattern means

  • 12 – string starts with 12
  • [A-Z]* – zero or more ASCII uppercase letters
  • – a space
  • HILLHILL char sequence
  • .* – any zero or more chars other than line break chars as many as possible (so, the rest of the line).
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading