Skip to content
Browse files

use new getFieldsInfo API to list indexed fields

  • Loading branch information...
1 parent a93c9d3 commit 7c7f1cd6d6edafc4849c3f92417c9a810a774574 Robert Newson committed Apr 12, 2012
Showing with 10 additions and 4 deletions.
  1. +10 −4 src/main/java/com/github/rnewson/couchdb/lucene/DatabaseIndexer.java
View
14 src/main/java/com/github/rnewson/couchdb/lucene/DatabaseIndexer.java
@@ -14,6 +14,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -40,8 +41,8 @@
import org.apache.lucene.document.Fieldable;
import org.apache.lucene.document.MapFieldSelector;
import org.apache.lucene.document.NumericField;
+import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexReader.FieldOption;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.LogByteSizeMergePolicy;
@@ -58,6 +59,7 @@
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.SingleInstanceLockFactory;
+import org.apache.lucene.util.ReaderUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -416,11 +418,15 @@ public void info(final HttpServletRequest req,
result.put("uuid", state.getUuid());
result.put("digest", state.getDigest());
final JSONArray fields = new JSONArray();
- for (final Object field : reader.getFieldNames(FieldOption.INDEXED)) {
- if (((String) field).startsWith("_")) {
+ final Iterator<FieldInfo> it = ReaderUtil.getMergedFieldInfos(reader).iterator();
+ while (it.hasNext()) {
+ final FieldInfo fieldInfo = it.next();
+ if (fieldInfo.name.startsWith("_")) {
continue;
}
- fields.put(field);
+ if (fieldInfo.isIndexed) {
+ fields.put(fieldInfo.name);
+ }
}
result.put("fields", fields);
result.put("last_modified", Long.toString(IndexReader

0 comments on commit 7c7f1cd

Please sign in to comment.
Something went wrong with that request. Please try again.