SOLR-157: Fixed NPE caused by index fields which do not appear on schema.xml. (contributed by Ryan McKinley)

Also relocated package from request package to handler package, and removed experimental warning.



git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@506187 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2007-02-12 00:21:36 +00:00
parent da1f585799
commit 2db80e7db1
2 changed files with 26 additions and 35 deletions

View File

@ -80,6 +80,8 @@ New Features
(in ms), using <autoCommit><maxTime>10000</maxTime></autoCommit>.
(Ryan McKinley via klaas).
10. SOLR-116: IndexInfoRequestHandler added. (Erik Hatcher)
Changes in runtime behavior
1. Highlighting using DisMax will only pick up terms from the main
user query, not boost or filter queries (klaas).

View File

@ -15,55 +15,57 @@
* limitations under the License.
*/
package org.apache.solr.request;
package org.apache.solr.handler;
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.util.SimpleOrderedMap;
import org.apache.solr.handler.RequestHandlerBase;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryResponse;
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 class IndexInfoRequestHandler extends RequestHandlerBase {
}
public void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp) {
public void handleRequestBody(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();
Map<String,Object> fields = new HashMap<String,Object>();
IndexSchema schema = req.getSchema();
for (String fieldName : fieldNames) {
Map fieldInfo = new HashMap();
Map<String,String> fieldInfo = new HashMap<String,String>();
FieldType fieldType = schema.getFieldTypeNoEx(fieldName);
fieldInfo.put("type", fieldType.getTypeName());
if( fieldType != null ) {
fieldInfo.put("type", fieldType.getTypeName());
}
else {
// This can happen if you change the schema
fieldInfo.put("type", null ); // "[unknown]"? nothing?
}
fields.put(fieldName, fieldInfo);
}
rsp.add("fields", fields);
Map indexInfo = new HashMap();
Map<String,Number> indexInfo = new HashMap<String,Number>();
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;
@ -76,37 +78,24 @@ public class IndexInfoRequestHandler implements SolrRequestHandler, SolrInfoMBea
//////////////////////// SolrInfoMBeans methods //////////////////////
public String getName() {
return IndexInfoRequestHandler.class.getName();
}
public String getVersion() {
return SolrCore.version;
}
@Override
public String getDescription() {
return "The structure Solr request handler";
}
public Category getCategory() {
return Category.QUERYHANDLER;
@Override
public String getVersion() {
return "$Revision: 501512 $";
}
@Override
public String getSourceId() {
return "$Id: IndexInfoRequestHandler.java 487199 2006-12-14 13:03:40Z bdelacretaz $";
}
@Override
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 SimpleOrderedMap();
}
}