You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by an...@apache.org on 2015/07/07 15:11:39 UTC

svn commit: r1689653 - in /lucene/dev/branches/branch_5x: ./ solr/ solr/CHANGES.txt solr/core/ solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java

Author: andyetitmoves
Date: Tue Jul  7 13:11:39 2015
New Revision: 1689653

URL: http://svn.apache.org/r1689653
Log:
SOLR-7751: Minor optimizations to QueryComponent.process

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/solr/core/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java

Modified: lucene/dev/branches/branch_5x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/CHANGES.txt?rev=1689653&r1=1689652&r2=1689653&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Tue Jul  7 13:11:39 2015
@@ -161,6 +161,9 @@ Optimizations
   from one for each shard and the federator, to just one for the federator.
   (Christine Poerschke via Ramkumar Aiyengar)
 
+* SOLR-7751: Minor optimizations to QueryComponent.process (reduce eager instantiations,
+  cache method calls) (Christine Poerschke via Ramkumar Aiyengar)
+
 Other Changes
 ----------------------
 

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java?rev=1689653&r1=1689652&r2=1689653&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java Tue Jul  7 13:11:39 2015
@@ -296,7 +296,6 @@ public class QueryComponent extends Sear
     LOG.debug("process: {}", rb.req.getParams());
   
     SolrQueryRequest req = rb.req;
-    SolrQueryResponse rsp = rb.rsp;
     SolrParams params = req.getParams();
     if (!params.getBool(COMPONENT_NAME, true)) {
       return;
@@ -316,13 +315,8 @@ public class QueryComponent extends Sear
       statsCache.receiveGlobalStats(req);
     }
 
-    // -1 as flag if not set.
-    long timeAllowed = params.getLong(CommonParams.TIME_ALLOWED, -1L);
-    if (null != rb.getCursorMark() && 0 < timeAllowed) {
-      // fundamentally incompatible
-      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Can not search using both " +
-                              CursorMarkParams.CURSOR_MARK_PARAM + " and " + CommonParams.TIME_ALLOWED);
-    }
+    SolrQueryResponse rsp = rb.rsp;
+    IndexSchema schema = searcher.getSchema();
 
     // Optional: This could also be implemented by the top-level searcher sending
     // a filter that lists the ids... that would be transparent to
@@ -330,12 +324,12 @@ public class QueryComponent extends Sear
     // too if desired).
     String ids = params.get(ShardParams.IDS);
     if (ids != null) {
-      SchemaField idField = searcher.getSchema().getUniqueKeyField();
+      SchemaField idField = schema.getUniqueKeyField();
       List<String> idArr = StrUtils.splitSmart(ids, ",", true);
       int[] luceneIds = new int[idArr.size()];
       int docs = 0;
       for (int i=0; i<idArr.size(); i++) {
-        int id = req.getSearcher().getFirstMatch(
+        int id = searcher.getFirstMatch(
                 new Term(idField.getName(), idField.getType().toInternal(idArr.get(i))));
         if (id >= 0)
           luceneIds[docs++] = id;
@@ -360,6 +354,14 @@ public class QueryComponent extends Sear
       return;
     }
 
+    // -1 as flag if not set.
+    long timeAllowed = params.getLong(CommonParams.TIME_ALLOWED, -1L);
+    if (null != rb.getCursorMark() && 0 < timeAllowed) {
+      // fundamentally incompatible
+      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Can not search using both " +
+                              CursorMarkParams.CURSOR_MARK_PARAM + " and " + CommonParams.TIME_ALLOWED);
+    }
+
     SolrIndexSearcher.QueryCommand cmd = rb.getQueryCommand();
     cmd.setTimeAllowed(timeAllowed);
 
@@ -383,7 +385,7 @@ public class QueryComponent extends Sear
 
           for (String field : groupingSpec.getFields()) {
             topsGroupsActionBuilder.addCommandField(new SearchGroupsFieldCommand.Builder()
-                .setField(searcher.getSchema().getField(field))
+                .setField(schema.getField(field))
                 .setGroupSort(groupingSpec.getGroupSort())
                 .setTopNGroups(cmd.getOffset() + cmd.getLen())
                 .setIncludeGroupCount(groupingSpec.isIncludeGroupCount())
@@ -405,6 +407,7 @@ public class QueryComponent extends Sear
               .setSearcher(searcher);
 
           for (String field : groupingSpec.getFields()) {
+            SchemaField schemaField = schema.getField(field);
             String[] topGroupsParam = params.getParams(GroupParams.GROUP_DISTRIBUTED_TOPGROUPS_PREFIX + field);
             if (topGroupsParam == null) {
               topGroupsParam = new String[0];
@@ -414,14 +417,14 @@ public class QueryComponent extends Sear
             for (String topGroup : topGroupsParam) {
               SearchGroup<BytesRef> searchGroup = new SearchGroup<>();
               if (!topGroup.equals(TopGroupsShardRequestFactory.GROUP_NULL_VALUE)) {
-                searchGroup.groupValue = new BytesRef(searcher.getSchema().getField(field).getType().readableToIndexed(topGroup));
+                searchGroup.groupValue = new BytesRef(schemaField.getType().readableToIndexed(topGroup));
               }
               topGroups.add(searchGroup);
             }
 
             secondPhaseBuilder.addCommandField(
                 new TopGroupsFieldCommand.Builder()
-                    .setField(searcher.getSchema().getField(field))
+                    .setField(schemaField)
                     .setGroupSort(groupingSpec.getGroupSort())
                     .setSortWithinGroup(groupingSpec.getSortWithinGroup())
                     .setFirstPhaseGroups(topGroups)