Apache Lucene open-source search software
Add indexinfo request handler, which returns field information (currently type only) and index state information such as number of documents and Lucene index version. This details about fields and the index returned are still being developed, so the response may change format until this is finalized.
Erik Hatcherbd5ef854d914
diff --git a/example/solr/conf/solrconfig.xml b/example/solr/conf/solrconfig.xmlindex 18dfc0a6082..dc4791e8155 100755--- a/example/solr/conf/solrconfig.xml+++ b/example/solr/conf/solrconfig.xml@@ -241,6 +241,8 @@</lst></requestHandler>+ <requestHandler name="indexinfo" class="solr.IndexInfoRequestHandler"/>+<!-- DisMaxRequestHandler allows easy searching across multiple fieldsfor simple user-entered phrases.see http://wiki.apache.org/solr/DisMaxRequestHandlerdiff --git a/src/java/org/apache/solr/request/IndexInfoRequestHandler.java b/src/java/org/apache/solr/request/IndexInfoRequestHandler.javanew file mode 100644index 00000000000..9797e4a89d9--- /dev/null+++ b/src/java/org/apache/solr/request/IndexInfoRequestHandler.java@@ -0,0 +1,111 @@+/**+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.request;++import org.apache.lucene.index.IndexReader;+import org.apache.solr.core.SolrCore;+import org.apache.solr.core.SolrException;+import org.apache.solr.core.SolrInfoMBean;+import org.apache.solr.util.NamedList;+import org.apache.solr.schema.IndexSchema;+import org.apache.solr.schema.FieldType;+import org.apache.solr.search.SolrIndexSearcher;++import java.net.URL;+import java.util.Collection;+import java.util.Map;+import java.util.HashMap;++public class IndexInfoRequestHandler implements SolrRequestHandler, SolrInfoMBean {+ public void init(NamedList args) {++ }++ public void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp) {++ try {+ SolrIndexSearcher searcher = req.getSearcher();+ IndexReader reader = searcher.getReader();+ Collection<String> fieldNames = reader.getFieldNames(IndexReader.FieldOption.ALL);+ Map fields = new HashMap();+ IndexSchema schema = req.getSchema();+ for (String fieldName : fieldNames) {+ Map fieldInfo = new HashMap();++ FieldType fieldType = schema.getFieldTypeNoEx(fieldName);+ fieldInfo.put("type", fieldType.getTypeName());++ fields.put(fieldName, fieldInfo);+ }+ rsp.add("fields", fields);++ Map indexInfo = new HashMap();+ indexInfo.put("numDocs", reader.numDocs());+ indexInfo.put("maxDoc", reader.maxDoc());+ indexInfo.put("version", reader.getVersion());+ // indexInfo.put("age", ); // computed from SolrIndexSearcher.openedAt?++ rsp.add("index", indexInfo);++ rsp.add("NOTICE","This interface is experimental and may be changing");+ } catch (SolrException e) {+ rsp.setException(e);+ return;+ } catch (Exception e) {+ SolrException.log(SolrCore.log, e);+ rsp.setException(e);+ return;+ }+ }++ //////////////////////// SolrInfoMBeans methods //////////////////////+++ public String getName() {+ return IndexInfoRequestHandler.class.getName();+ }++ public String getVersion() {+ return SolrCore.version;+ }++ public String getDescription() {+ return "The structure Solr request handler";+ }++ public Category getCategory() {+ return Category.QUERYHANDLER;+ }++ public String getSourceId() {+ return "$Id: IndexInfoRequestHandler.java 487199 2006-12-14 13:03:40Z bdelacretaz $";+ }++ public String getSource() {+ return "$URL: https://svn.apache.org/repos/asf/lucene/solr/trunk/src/java/org/apache/solr/request/IndexInfoRequestHandler.java $";+ }++ public URL[] getDocs() {+ return null;+ }++ public NamedList getStatistics() {+ return new NamedList();+ }+}+diff --git a/src/test/org/apache/solr/IndexInfoRequestHandlerTest.java b/src/test/org/apache/solr/IndexInfoRequestHandlerTest.javanew file mode 100644index 00000000000..748674111b7--- /dev/null+++ b/src/test/org/apache/solr/IndexInfoRequestHandlerTest.java@@ -0,0 +1,57 @@+/**+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr;++import org.apache.solr.request.*;+import org.apache.solr.util.*;+import org.w3c.dom.Document;++import javax.xml.parsers.DocumentBuilderFactory;+import javax.xml.parsers.DocumentBuilder;+import java.io.IOException;+import java.io.StringWriter;+import java.io.ByteArrayInputStream;+import java.io.UnsupportedEncodingException;+import java.util.Map;+import java.util.HashMap;++public class IndexInfoRequestHandlerTest extends AbstractSolrTestCase {++ public String getSchemaFile() { return "schema.xml"; }+ public String getSolrConfigFile() { return "solrconfig.xml"; }+ public void setUp() throws Exception {+ super.setUp();+ lrf = h.getRequestFactory("indexinfo", 0, 0);+ }++ public void testIndexInfo() throws Exception {++ assertU(adoc("id", "529",+ "field_t", "what's inside?",+ "subject", "info"+ ));+ assertU(commit());++ assertQ("index info",+ req("foo")+ ,"//lst[@name='fields']/lst[@name='field_t']"+ ,"//lst[@name='index']/int[@name='numDocs'][.='1']"+ );+ }++}diff --git a/src/test/test-files/solr/conf/solrconfig.xml b/src/test/test-files/solr/conf/solrconfig.xmlindex c591bd334a9..379b4cbc620 100644--- a/src/test/test-files/solr/conf/solrconfig.xml+++ b/src/test/test-files/solr/conf/solrconfig.xml@@ -151,7 +151,7 @@into cached filters if the number of docs selected by the clause exceedsthe threshold (represented as a fraction of the total index)-->- <boolTofilterOptimizer enabled="true" cacheSize="32" threshold=".05"/>+ <boolTofilterOptimizer enabled="false" cacheSize="32" threshold=".05"/><!-- a newSearcher event is fired whenever a new searcher is being prepared@@ -193,6 +193,7 @@is not specified in the request.--><requestHandler name="standard" class="solr.StandardRequestHandler"/>+ <requestHandler name="indexinfo" class="solr.IndexInfoRequestHandler"/><requestHandler name="dismaxOldStyleDefaults"class="solr.DisMaxRequestHandler" ><!-- for historic reasons, DisMaxRequestHandler will use all of