Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
386 views
in Technique[技术] by (71.8m points)

lucene.net - Wildcard at the Beginning of a searchterm -Lucene

As far as i know lucene(.net) doesn't support the wildcard at the beginning of a searchterm --> http://lucene.apache.org/java/2_0_0/queryparsersyntax.html "Note: You cannot use a * or ? symbol as the first character of a search."

for example *myword

maybe because it's quiet difficult to search "everything" before the searchterm.

Despite that, We are looknig for a way to use the wildcard at the beginning. Does anyone know if this is possible?

One Thought was asearchterm, bsearchterm, ....z*searchterm ... but that seems a bit random to me.

thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your question is tagged with Lucene.NET so I assume you mean the .NET version rather than the Java version.

Yes, you can have wildcards at the beginning of a search term by via

var queryParser = new QueryParser(LuceneVersion, "content", new StandardAnalyzer(LuceneVersion));
queryParser.SetAllowLeadingWildcard(true);

but you need to be aware of the performance consequences. Find more detailed source code in this blog.

Since Lucene.NET is a port of the Java version, I suspect you could use the same approach for the Java version. I didn't verify this, though.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...