1

In Luke, if I enter the search expression docfile:Tomatoes.jpg* the parsed query is docfile:Tomatoes.jpg*. When the search expression is docfile:Tomatoes.jpg, (no asterisk *) the parsed query is docfile:tomatoes.jpg with a lowercase 't'.

  1. Why?
  2. How can I change this?

BTW, using org.apache.lucene.analysis.standard.StandardAnalyzer.

Dzejms
  • 3,108
  • 2
  • 30
  • 40

2 Answers2

4

StandardAnalyzer uses LowerCaseFilter which means it lowercases your queries and data. This is described in the Javadocs http://lucene.apache.org/java/3_0_1/api/core/org/apache/lucene/analysis/standard/StandardAnalyzer.html.

If I remember correctly WhitespaceAnalyzer does not lowercase, but verify it suits your needs http://lucene.apache.org/java/3_0_1/api/core/org/apache/lucene/analysis/WhitespaceAnalyzer.html.

ponzao
  • 20,684
  • 3
  • 41
  • 58
  • StandardAnalyzer doesn't seem to be lowering the case of my data. docfile:Tomatoes.jpg* returns the expected results, while docfile:Tomatoes.jpg returns 0. docfile:Tomatoes.jpg, using WhitespaceAnalyzer or KeywordAnalyzer does return the expected results. The data was indexed with StandardAnalyzer. Not being too experienced with Lucene, I don't know if it's ok to use a different analyzer while searching or not. Is this a common practice? – Dzejms May 19 '11 at 18:05
  • Are you certain the data is not lowercased in the index? Did you run it through an analyzer? – ponzao May 19 '11 at 18:45
  • You usually should use the same analyzer your storing and searching. – ponzao May 19 '11 at 18:45
  • It was indexed with StandardAnalyzer. – Dzejms May 24 '11 at 15:36
  • 1
    I am having the same issue, items are indexed with standard analyzer and lowercase queries do not return results but same case queries do return results – devshorts Feb 10 '12 at 21:28
  • As said before, docs have to be indexed with the same analyzer you are pulling data out of it. – Younes Apr 02 '13 at 18:19
1

For Lucene 5.3.0 the problem was solved by using the SimpleAnalyzer.

Example:

Analyzer analyzer = new org.apache.lucene.analysis.core.SimpleAnalyzer();

Finally, use the same analyzer for building the index and searching.

MobileMateo
  • 424
  • 5
  • 4