I want to match prefixes near the start of a field. I have this, but it's not matching the prefix; it only matches the whole word if the search term matches it. It seems like there's no way to combine SpanTermQuery and PrefixQuery.
var nameTerm = new Term("name", searchTerm);
var prefixName = new PrefixQuery(nameTerm);
var prefixAtStart = new BooleanQuery
{
{ prefixName, Occur.MUST },
{ new SpanFirstQuery(new SpanTermQuery(nameTerm), 0), Occur.MUST }
};
For example:
- Search term:
"Comp" - Want to find:
"Computer science class"and"Comp Sci" - Only finding:
"Comp Sci" - Don't want to find:
"Apple's latest computer"
Can the RegexpQuery be made to understand positions?
When you only want to match prefixes, you can do it by having below field type for your field.
then in this case the query would be like :
Now you have a second for which you need NGramFilter, so you can use the below field type for your field.