In Lucene, wenn ich ein Feld mit Großbuchstaben indexiere, werden sie bei einer Suche nicht gefunden. Hier ist ein Beispielcode:Was macht LOWERCASE_EXPANDED_TERMS in Lucene?
public static void main(String[] args) throws Exception{
//Create an index
Directory index=new RAMDirectory();
IndexWriter indexWriter = new IndexWriter(index, new IndexWriterConfig(new KeywordAnalyzer()));
//Add a document to the index
Document document=new Document();
document.add(new StringField("path","/home/user/file1", Field.Store.YES));
document.add(new StringField("id","file1", Field.Store.YES));
indexWriter.addDocument(document);
//Add a document to the index
document=new Document();
document.add(new StringField("path","/HOME/user/file2", Field.Store.YES));
document.add(new StringField("id","file2", Field.Store.YES));
indexWriter.addDocument(document);
//Close the index.
indexWriter.close();
//Create a query parser.
StandardQueryParser standardQueryParser=new StandardQueryParser(new KeywordAnalyzer());
StandardQueryConfigHandler config=(StandardQueryConfigHandler)standardQueryParser.getQueryConfigHandler();
config.set(StandardQueryConfigHandler.ConfigurationKeys.ANALYZER, new KeywordAnalyzer());
config.set(StandardQueryConfigHandler.ConfigurationKeys.ALLOW_LEADING_WILDCARD,true);
config.set(StandardQueryConfigHandler.ConfigurationKeys.LOWERCASE_EXPANDED_TERMS,true);
//Run a query
Query query=standardQueryParser.parse("path: \\/HOME*","path");
IndexSearcher indexSearcher=new IndexSearcher(DirectoryReader.open(index));
TopDocs topDocs=indexSearcher.search(query,Integer.MAX_VALUE);
//Iterate thru results
for (ScoreDoc scoreDoc:topDocs.scoreDocs){
String id=indexSearcher.doc(scoreDoc.doc).get("id");
System.out.println(id);
}
}
Ausgang:
file1
Ich erwartete etwas wie folgt aus:
file1 file2
Wenn ich LOWERCASE_EXPANDED_TERMS auf false gesetzt, das Ergebnis ist:
file2
Die Lucene Documentation für LOWERCASE_EXPANDED_TERMS sagt: "Schlüssel verwendet, um festzulegen, ob erweiterte Begriffe kleiner sein sollten". Kann jemand genau klären, was das bedeutet? Warum werden meine Großbuchstaben ignoriert? Soll ich einfach einen .toLowerCase() auf jeden Wert anwenden, um ihn durchsuchbar zu machen?