mirror of
https://github.com/apache/lucene.git
synced 2025-02-21 01:18:45 +00:00
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. git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@498345 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b631c61ad3
commit
bd5ef854d9
@ -241,6 +241,8 @@
|
||||
</lst>
|
||||
</requestHandler>
|
||||
|
||||
<requestHandler name="indexinfo" class="solr.IndexInfoRequestHandler"/>
|
||||
|
||||
<!-- DisMaxRequestHandler allows easy searching across multiple fields
|
||||
for simple user-entered phrases.
|
||||
see http://wiki.apache.org/solr/DisMaxRequestHandler
|
||||
|
111
src/java/org/apache/solr/request/IndexInfoRequestHandler.java
Normal file
111
src/java/org/apache/solr/request/IndexInfoRequestHandler.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
|
57
src/test/org/apache/solr/IndexInfoRequestHandlerTest.java
Normal file
57
src/test/org/apache/solr/IndexInfoRequestHandlerTest.java
Normal file
@ -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']"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -151,7 +151,7 @@
|
||||
into cached filters if the number of docs selected by the clause exceeds
|
||||
the 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user