3

I have a solr index with indexed text. I'd like to query documents that start with a certain term. I didn't find a way to do that with the lucene or dismax query parser.

Is there a way to do that?

A solution I thought of is to index the strings with a special token at the beginning of each line, i.e: "STARTOFTEXT" and then query for "STARTOFTEXT something". Is there a nicer solution?

davidbrai
  • 1,229
  • 1
  • 9
  • 14

1 Answers1

2

What about making a field in the schema that contains the first word? Then when when you build the document you can grab the first word and store it separately from the rest of the text.

d whelan
  • 804
  • 5
  • 8
  • is there an easy way to do that with the existing filters/analyzers? – davidbrai Dec 28 '11 at 21:26
  • 1
    Not sure if it's easy but you might be able to create a field which uses solr.PatternReplaceCharFilterFactory and create a regex to remove everything after the first word. Then just use a copyField directive to copy the chunk of text to this new field. But I would lean toward grabbing the first word in the application which builds the solr document for indexing. – d whelan Dec 29 '11 at 00:52
  • It's a job of the application logic, let it store it into a new field. I guess you intend it to be a keyword. You may have good incentive for a separate field: you can boost that field while searching **and/or** use it to implement faceting. – Jesvin Jose Dec 29 '11 at 05:01