我正在基于Spring-MVC的应用程序中集成Lucene搜索和索引,目前我正在使用Wild-card查询搜索,但它不是以不区分大小写的方式工作。有任何想法吗?
当我输入Ideas时,我会得到结果,但不是想法。
代码:
String var1 = vars.get("var1");
String var2 = vars.get("var2");
vars.put("var3", var1+"."+var2);
//搜索代码
@Override
public synchronized void saveIndexes(String text, String tagFileName, String filePath, long groupId, boolean type, int objectId) {
try {
Directory directory = org.apache.lucene.store.FSDirectory.open(path);
IndexWriterConfig config = new IndexWriterConfig(new SimpleAnalyzer());
IndexWriter indexWriter = new IndexWriter(directory, config);
org.apache.lucene.document.Document doc = new org.apache.lucene.document.Document();
if (filePath != null) {
File file = new File(filePath); // current directory
doc.add(new TextField("path", file.getPath(), Field.Store.YES));
}
doc.add(new StringField("id", String.valueOf(objectId), Field.Store.YES));
// doc.add(new TextField("id",String.valueOf(objectId),Field.Store.YES));
if (text == null) {
if (filePath != null) {
FileInputStream is = new FileInputStream(filePath);
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder stringBuffer = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
stringBuffer.append(line).append("\n");
}
stringBuffer.append("\n").append(tagFileName);
if(groupNotes!=null){
stringBuffer.append(String.valueOf(groupNotes.getNoteNumber()));
}
reader.close();
doc.add(new TextField("contents", stringBuffer.toString(), Field.Store.YES));
}
}
}
谢谢。
答案 0 :(得分:2)
我会尝试将小写文本存储到索引中。 当用户搜索文本时,在搜索索引之前,将搜索查询文本设置为小写。