1
votes

I have a problem using Lucene.NET 2.9.4. Maybe anybody can help me.

Currently when the user enter the word open i will change the search therm automatically to *open*. I have set QueryParser.SetAllowLeadingWildcard(true); i know, this can be expensive...

My Text is:

"You can use the menu file / open to edit an existing document"

When i use open* or open as a search term, lucene find the text.

When i use *open* lucene doesn't find the text.

Why not? What is problem with a leading wildcard? I want to find the search term on start, at the end and in the middle of a word.

i want to search for open and...

  • foo bar => is not a match
  • opening foo bar => is a match
  • testopen foo bar => is a match
  • testopening foo bar => is a match

How can i do this?

2
I too have experienced some unexpected/inconsistent results when using Lucene, but more often than not they are caused by mismatching the storage and query analyzers. Are you sure you're data was committed to Lucene using the same analyzer that you're attempting to search it with? - M.Babcock
Yes, i'm sure. I only use a StandardAnalyzer in my program ....... new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29, this.StopWordFile); - Healy

2 Answers

1
votes

Per default leading wildcards are disabled, but with Lucene >=2.1 there is a way to enable this.

Leading wildcards (e.g. *ook) are not supported by the QueryParser by default. As of Lucene 2.1, they can be enabled by calling QueryParser.setAllowLeadingWildcard( true ). Note that this can be an expensive operation: it requires scanning the list of tokens in the index in its entirety to look for those that match the pattern.

see:Lucene FAQ

1
votes

2 things:

1) I would verify that Luke gives you the same results as your query code.

2) Does "testopening foo bar" work or fail?