How to make field case insensitive in lucene? Suppose, I have a following document:
User:xyz
Now, the document should be returned as a result for queries "user:xyz", "uSer:xyz", or "usEr:xyz".
The possible solution is to lowercasing the field while indexing and searching. But I need the exact value of the field when retrieving the document. Also, the other solution is to index the field twice, but that is also not the proper solution.
Here is the lucene example. When the query is "user:xyz" the document doesn't match. But if I use query "User:xyz" then the document matches because while indexing I have field as "User".
public void testFieldCaseSensitive() throws ParseException,
QueryNodeException {
StandardQueryParser parser = new StandardQueryParser();
Query luceneQuery = parser.parse("user:xyz","");
MemoryIndex memoryIndex = new MemoryIndex();
memoryIndex.addField("User", "xyz", new StandardAnalyzer(
Version.LUCENE_43));
memoryIndex.search(luceneQuery);
Assert.assertTrue(memoryIndex.search(luceneQuery) > 0);
}