Kratos85
Kratos85

Reputation: 193

Apply regex on Solr query?

I have got indexes created on tables having data of the form: indexname='text'---->Today is a great day for running in the park. Now i want to perform a search on the indexes where only 'day' or 'run' is appearing in the text.

I have implemented query like : q = 'text:(day or run*)' But this query is not returning me any results from indexes.Is this correct way?or how can i improve my query by applying regex ?

Upvotes: 1

Views: 677

Answers (2)

Walter Underwood
Walter Underwood

Reputation: 1221

Regex and wildcards are slow in search engines. You'll get better performance by pre-processing the terms in a language-sensitive way.

You can match "run" to "running" with a stemmer, an analysis step that reduces different forms of a word to a common stem. When the query and the index term are both stemmed, then they will match.

You should also look into the Extended Dismax (edismax) search handler. That will do some of the work of turning "day run" into a search for the individual words and the phrase, something like 'day OR run OR "day run"'. Then it can further expand that against multiple fields with different weights, all automatically.

Upvotes: 0

LAW
LAW

Reputation: 1171

Your use case is very basic and doesn't require regex at all with Solr. It looks like you just may have a syntax issue. q=text:day OR text:run should do exactly what you're looking for.

Upvotes: 1

Related Questions