Apache Solr open-source search software
SOLR-7751: Minor optimizations to QueryComponent.process
Ramkumar Aiyengar6571cd9fe359
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 6c042bfb11e..0d1f9c50d8a 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -221,6 +221,9 @@ Optimizationsfrom 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----------------------diff --git a/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java b/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.javaindex 80f03f2b6f6..7f9dc665c92 100644--- a/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java+++ b/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java@@ -297,7 +297,6 @@ public class QueryComponent extends SearchComponentLOG.debug("process: {}", rb.req.getParams());SolrQueryRequest req = rb.req;- SolrQueryResponse rsp = rb.rsp;SolrParams params = req.getParams();if (!params.getBool(COMPONENT_NAME, true)) {return;@@ -317,13 +316,8 @@ public class QueryComponent extends SearchComponentstatsCache.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@@ -331,12 +325,12 @@ public class QueryComponent extends SearchComponent// 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;@@ -361,6 +355,14 @@ public class QueryComponent extends SearchComponentreturn;}+ // -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);@@ -384,7 +386,7 @@ public class QueryComponent extends SearchComponentfor (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())@@ -406,6 +408,7 @@ public class QueryComponent extends SearchComponent.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];@@ -415,14 +418,14 @@ public class QueryComponent extends SearchComponentfor (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)