lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christopher Kolstad" <chri...@ovitas.no>
Subject PrefixQuery's rewrite method does not work as expected when used under .Net 2.0
Date Thu, 25 Oct 2007 09:02:01 GMT
Hi.

I'm currently using the latest version from SVN of Lucene.Net 2.1. When
compiling it for .Net 2.0 I ran into an interesting "feature".
Query expansion stops before expected. After a lot of debugging, I found the
culprit to be PrefixQuery's Rewrite method. It uses string.StartsWith
(string);
However in .Net 2.0 this will then break on any box with different culture
settings than English. Since .Net 2.0 StartsWith has the overload
StartsWith(string, StringComparisonType) and this is set to default to
StringComparison.CurrentCulture

Norwegian culture for instance states that 'aa' is the same as the single
letter 'å'

So when my index contains para-orange, paraaminosyre para.... and I do the
PrefixQuery para*

this method fails on the if(term.Text().StartsWith(prefixText)) test. on
paraaminosyre.StartsWith(para).

The fix for me was to change the line in PrefixQuery.cs::Rewrite() from

if(term != null && term.Text().StartsWith(prefixText) && term.Field() ==
prefixField)

to

if (term != null && term.Text().StartsWith(prefixText,
StringComparison.Ordinal) && term.Field() == prefixField)

This is a new "feature" in .Net 2.0 and did not affect my .Net 1.1 projects
which still uses the .Net 1.1 library.


Conditional compilation might be required.
-- 
Regards,
Christopher Kolstad
E-mail: chriswk@ifi.uio.no (University)
christopher.kolstad@gmail.com (Home)
chriswk@ovitas.no (Job)

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message