0

I'm using Lucene.NET version 4.8 (beta) for a little search task in a solution I'm doing, but have problems searching case insensitive. I know that Lucene isn't case insensitive, but when using the StandardAnalyzer, it should lowercase the data stored (according to the documentation here StandardAnalyzer), as long as you make sure the queries are done right.

So any idea what I'm doing wrong here? I've stored the data "Kirsten" in a field in 4 different documents, and when searching for (lowercased) "kirsten" I get no hits, but when searching for "Kirsten" I get the expected 4.

Here's my query code:

        query = query.ToLowerInvariant();
        BooleanQuery q = new BooleanQuery {
            new BooleanClause(new WildcardQuery(new Term(FieldNames.Name, query + WildcardQuery.WILDCARD_STRING)), Occur.SHOULD),
            new BooleanClause(new WildcardQuery(new Term("mt-year", query)), Occur.SHOULD),
            new BooleanClause(new WildcardQuery(new Term("mt-class", query + WildcardQuery.WILDCARD_STRING)), Occur.SHOULD)
        };

And the issue is that the users would always write the lowercase version, and expect it to find both lower- and upper-case.

Steen Tøttrup
  • 3,755
  • 2
  • 22
  • 36
  • 3
    You have to show us, how you are creating your document. You are using `TextField` or `StringField`? Check this answer: https://stackoverflow.com/a/32011823/7225096 – Peska May 31 '19 at 11:43
  • That seems indeed to be the issue! I was using StringField, and I should be using TextField it seems! It's been too long since I worked with Lucene.NET it seems! Thank you! – Steen Tøttrup Jun 01 '19 at 15:19

1 Answers1

0

As @Peska wrote in the comments, this was a case of using StringField instead of TextField when adding the document (and data) to Lucene.

Once I switched to using TextField, everything worked as expected.

Steen Tøttrup
  • 3,755
  • 2
  • 22
  • 36
  • If the solution exists within another answer (as it does in this case), we don't post an answer, we use the built-in "Vote/Flag to close as a duplicate". – Asons Oct 09 '19 at 20:55