From c0959adbfcbcdc8363c420d3564bd34905757272 Mon Sep 17 00:00:00 2001
From: Erick Erickson
Date: Fri, 6 Jan 2012 01:25:12 +0000
Subject: [PATCH] SOLR-1931, speeding up the LukeRequestHandler
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1227924 13f79535-47bb-0310-9956-ffa450edef68
---
.../handler/admin/LukeRequestHandler.java | 476 +++++++++---------
.../org/apache/solr/MinimalSchemaTest.java | 1 -
.../handler/admin/LukeRequestHandlerTest.java | 52 +-
3 files changed, 255 insertions(+), 274 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java
index 0342243850e..740074a19b9 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/LukeRequestHandler.java
@@ -20,33 +20,16 @@ package org.apache.solr.handler.admin;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
-import org.apache.lucene.index.Fields;
-import org.apache.lucene.index.FieldsEnum;
+import org.apache.lucene.index.*;
import org.apache.lucene.index.FieldInfo.IndexOptions;
import static org.apache.lucene.index.FieldInfo.IndexOptions.DOCS_ONLY;
import static org.apache.lucene.index.FieldInfo.IndexOptions.DOCS_AND_FREQS;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexableField;
-import org.apache.lucene.index.MultiFields;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.index.Terms;
-import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.search.Query;
-import org.apache.lucene.search.TermRangeQuery;
-import org.apache.lucene.search.TopDocs;
+
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.CharsRef;
@@ -72,6 +55,7 @@ import org.apache.solr.schema.SchemaField;
import org.apache.solr.search.SolrIndexSearcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.apache.lucene.index.DocsEnum;
/**
* This handler exposes the internal lucene index. It is inspired by and
@@ -82,33 +66,45 @@ import org.slf4j.LoggerFactory;
* that it works nicely with an XSLT transformation. Until we have a nice
* XSLT front end for /admin, the format is still open to change.
*
- *
+ *
* For more documentation see:
* http://wiki.apache.org/solr/LukeRequestHandler
- *
+ *
*
* @since solr 1.2
*/
-public class LukeRequestHandler extends RequestHandlerBase
+public class LukeRequestHandler extends RequestHandlerBase
{
private static Logger log = LoggerFactory.getLogger(LukeRequestHandler.class);
-
+
public static final String NUMTERMS = "numTerms";
public static final String DOC_ID = "docId";
public static final String ID = "id";
public static final int DEFAULT_COUNT = 10;
+ static final int HIST_ARRAY_SIZE = 33;
+
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception
- {
+ {
IndexSchema schema = req.getSchema();
SolrIndexSearcher searcher = req.getSearcher();
IndexReader reader = searcher.getIndexReader();
SolrParams params = req.getParams();
int numTerms = params.getInt( NUMTERMS, DEFAULT_COUNT );
-
+
// Always show the core lucene info
- rsp.add("index", getIndexInfo(reader, numTerms>0 ) );
+ Map topTerms = new TreeMap();
+
+ // If no doc is given, show all fields and top terms
+ Set fields = null;
+ if( params.get( CommonParams.FL ) != null ) {
+ fields = new TreeSet(Arrays.asList(params.getParams( CommonParams.FL )));
+ }
+ if ( "schema".equals( params.get( "show" ))) {
+ numTerms = 0; // Abort any statistics gathering.
+ }
+ rsp.add("index", getIndexInfo(reader, numTerms, topTerms, fields ));
Integer docId = params.getInt( DOC_ID );
if( docId == null && params.get( ID ) != null ) {
@@ -121,7 +117,7 @@ public class LukeRequestHandler extends RequestHandlerBase
throw new SolrException( SolrException.ErrorCode.NOT_FOUND, "Can't find document: "+params.get( ID ) );
}
}
-
+
// Read the document from the index
if( docId != null ) {
Document doc = null;
@@ -132,9 +128,9 @@ public class LukeRequestHandler extends RequestHandlerBase
if( doc == null ) {
throw new SolrException( SolrException.ErrorCode.NOT_FOUND, "Can't find document: "+docId );
}
-
+
SimpleOrderedMap