sandy
sandy

Reputation: 1158

Solr lucene search only first word in a sentence - need query

I am searching data which matches only that sentence which starts with the search key.

Ex:

search key "what"

result : DESIRED ONE

**what** is your name
**what** are you doing
**what** is that

etc.

How i am getting now is

Is that **what** you want 
some text before **what** 

etc.

i am using EdgeNGram as well..But it is giving me the second one. Any help appreciated....

Upvotes: 1

Views: 1842

Answers (3)

todd
todd

Reputation: 193

You can use a regex 'starts with query' q:(name:/what.*/) will yield results where the name field start with 'what'

Upvotes: 2

JustAC0der
JustAC0der

Reputation: 3149

I think you can use the following trick: add the following line to your field definition:

<charFilter class="solr.PatternReplaceCharFilterFactory"
  pattern="^(.*)$" replacement="AAAA $1" />

This will add the "AAAA" token to both your index and query. This way you can match the beginning of an indexed string.

More info here:

Upvotes: 0

rounak
rounak

Reputation: 9397

I think you're using the WhitespaceTokenizer. You should try using the KeywordTokenizer with EdgeNGram from the left end.

If you're trying to implement auto suggest, have a look at the Suggester component.

Upvotes: 1

Related Questions