mirror of https://github.com/apache/lucene.git
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:
parent
da1f585799
commit
2db80e7db1
|
@ -80,6 +80,8 @@ New Features
|
||||||
(in ms), using <autoCommit><maxTime>10000</maxTime></autoCommit>.
|
(in ms), using <autoCommit><maxTime>10000</maxTime></autoCommit>.
|
||||||
(Ryan McKinley via klaas).
|
(Ryan McKinley via klaas).
|
||||||
|
|
||||||
|
10. SOLR-116: IndexInfoRequestHandler added. (Erik Hatcher)
|
||||||
|
|
||||||
Changes in runtime behavior
|
Changes in runtime behavior
|
||||||
1. Highlighting using DisMax will only pick up terms from the main
|
1. Highlighting using DisMax will only pick up terms from the main
|
||||||
user query, not boost or filter queries (klaas).
|
user query, not boost or filter queries (klaas).
|
||||||
|
|
|
@ -15,47 +15,50 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.solr.request;
|
package org.apache.solr.handler;
|
||||||
|
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.solr.core.SolrCore;
|
import org.apache.solr.core.SolrCore;
|
||||||
import org.apache.solr.core.SolrException;
|
import org.apache.solr.core.SolrException;
|
||||||
import org.apache.solr.core.SolrInfoMBean;
|
import org.apache.solr.handler.RequestHandlerBase;
|
||||||
import org.apache.solr.util.NamedList;
|
|
||||||
import org.apache.solr.util.SimpleOrderedMap;
|
|
||||||
import org.apache.solr.schema.IndexSchema;
|
import org.apache.solr.schema.IndexSchema;
|
||||||
import org.apache.solr.schema.FieldType;
|
import org.apache.solr.schema.FieldType;
|
||||||
|
import org.apache.solr.schema.SchemaField;
|
||||||
import org.apache.solr.search.SolrIndexSearcher;
|
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.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class IndexInfoRequestHandler implements SolrRequestHandler, SolrInfoMBean {
|
public class IndexInfoRequestHandler extends RequestHandlerBase {
|
||||||
public void init(NamedList args) {
|
|
||||||
|
|
||||||
}
|
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) {
|
||||||
|
|
||||||
public void handleRequest(SolrQueryRequest req, SolrQueryResponse rsp) {
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SolrIndexSearcher searcher = req.getSearcher();
|
SolrIndexSearcher searcher = req.getSearcher();
|
||||||
IndexReader reader = searcher.getReader();
|
IndexReader reader = searcher.getReader();
|
||||||
Collection<String> fieldNames = reader.getFieldNames(IndexReader.FieldOption.ALL);
|
Collection<String> fieldNames = reader.getFieldNames(IndexReader.FieldOption.ALL);
|
||||||
Map fields = new HashMap();
|
Map<String,Object> fields = new HashMap<String,Object>();
|
||||||
IndexSchema schema = req.getSchema();
|
IndexSchema schema = req.getSchema();
|
||||||
for (String fieldName : fieldNames) {
|
for (String fieldName : fieldNames) {
|
||||||
Map fieldInfo = new HashMap();
|
Map<String,String> fieldInfo = new HashMap<String,String>();
|
||||||
|
|
||||||
FieldType fieldType = schema.getFieldTypeNoEx(fieldName);
|
FieldType fieldType = schema.getFieldTypeNoEx(fieldName);
|
||||||
|
if( fieldType != null ) {
|
||||||
fieldInfo.put("type", fieldType.getTypeName());
|
fieldInfo.put("type", fieldType.getTypeName());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// This can happen if you change the schema
|
||||||
|
fieldInfo.put("type", null ); // "[unknown]"? nothing?
|
||||||
|
}
|
||||||
|
|
||||||
fields.put(fieldName, fieldInfo);
|
fields.put(fieldName, fieldInfo);
|
||||||
}
|
}
|
||||||
rsp.add("fields", fields);
|
rsp.add("fields", fields);
|
||||||
|
|
||||||
Map indexInfo = new HashMap();
|
Map<String,Number> indexInfo = new HashMap<String,Number>();
|
||||||
indexInfo.put("numDocs", reader.numDocs());
|
indexInfo.put("numDocs", reader.numDocs());
|
||||||
indexInfo.put("maxDoc", reader.maxDoc());
|
indexInfo.put("maxDoc", reader.maxDoc());
|
||||||
indexInfo.put("version", reader.getVersion());
|
indexInfo.put("version", reader.getVersion());
|
||||||
|
@ -63,7 +66,6 @@ public class IndexInfoRequestHandler implements SolrRequestHandler, SolrInfoMBea
|
||||||
|
|
||||||
rsp.add("index", indexInfo);
|
rsp.add("index", indexInfo);
|
||||||
|
|
||||||
rsp.add("NOTICE","This interface is experimental and may be changing");
|
|
||||||
} catch (SolrException e) {
|
} catch (SolrException e) {
|
||||||
rsp.setException(e);
|
rsp.setException(e);
|
||||||
return;
|
return;
|
||||||
|
@ -76,37 +78,24 @@ public class IndexInfoRequestHandler implements SolrRequestHandler, SolrInfoMBea
|
||||||
|
|
||||||
//////////////////////// SolrInfoMBeans methods //////////////////////
|
//////////////////////// SolrInfoMBeans methods //////////////////////
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getName() {
|
|
||||||
return IndexInfoRequestHandler.class.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVersion() {
|
|
||||||
return SolrCore.version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return "The structure Solr request handler";
|
return "The structure Solr request handler";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Category getCategory() {
|
@Override
|
||||||
return Category.QUERYHANDLER;
|
public String getVersion() {
|
||||||
|
return "$Revision: 501512 $";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getSourceId() {
|
public String getSourceId() {
|
||||||
return "$Id: IndexInfoRequestHandler.java 487199 2006-12-14 13:03:40Z bdelacretaz $";
|
return "$Id: IndexInfoRequestHandler.java 487199 2006-12-14 13:03:40Z bdelacretaz $";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getSource() {
|
public String getSource() {
|
||||||
return "$URL: https://svn.apache.org/repos/asf/lucene/solr/trunk/src/java/org/apache/solr/request/IndexInfoRequestHandler.java $";
|
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue