mirror of https://github.com/apache/lucene.git
SOLR-13643:add Getter/Setter in ResponseBuilder to handle analytic res
This commit is contained in:
parent
68ec328807
commit
64357bc913
|
@ -71,6 +71,8 @@ Other Changes
|
||||||
|
|
||||||
* SOLR-13629: Clean trailing whitespace from 'analytics' contrib (Neal Sidhwaney via Jason Gerlowski)
|
* SOLR-13629: Clean trailing whitespace from 'analytics' contrib (Neal Sidhwaney via Jason Gerlowski)
|
||||||
|
|
||||||
|
* SOLR-13643: Add Getters/Setters in ResponseBuilder for analytics response handling (Neal Sidhwaney via Munendra S N)
|
||||||
|
|
||||||
================== 8.2.0 ==================
|
================== 8.2.0 ==================
|
||||||
|
|
||||||
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
|
||||||
|
|
|
@ -23,10 +23,10 @@ import org.apache.solr.analytics.AnalyticsRequestManager;
|
||||||
import org.apache.solr.analytics.AnalyticsRequestParser;
|
import org.apache.solr.analytics.AnalyticsRequestParser;
|
||||||
import org.apache.solr.analytics.ExpressionFactory;
|
import org.apache.solr.analytics.ExpressionFactory;
|
||||||
import org.apache.solr.analytics.stream.AnalyticsShardRequestManager;
|
import org.apache.solr.analytics.stream.AnalyticsShardRequestManager;
|
||||||
|
import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
|
||||||
import org.apache.solr.analytics.util.OldAnalyticsParams;
|
import org.apache.solr.analytics.util.OldAnalyticsParams;
|
||||||
import org.apache.solr.analytics.util.OldAnalyticsRequestConverter;
|
import org.apache.solr.analytics.util.OldAnalyticsRequestConverter;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.analytics.util.AnalyticsResponseHeadings;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes analytics requests.
|
* Computes analytics requests.
|
||||||
|
@ -43,23 +43,31 @@ public class AnalyticsComponent extends SearchComponent {
|
||||||
public void prepare(ResponseBuilder rb) throws IOException {
|
public void prepare(ResponseBuilder rb) throws IOException {
|
||||||
// First check to see if there is an analytics request using the current format
|
// First check to see if there is an analytics request using the current format
|
||||||
String analyticsRequest = rb.req.getParams().get(AnalyticsRequestParser.analyticsParamName);
|
String analyticsRequest = rb.req.getParams().get(AnalyticsRequestParser.analyticsParamName);
|
||||||
rb._isOlapAnalytics = false;
|
rb.setOlapAnalytics(false);
|
||||||
rb.doAnalytics = false;
|
rb.setAnalytics(false);
|
||||||
|
boolean isDistributed = rb.isDistributed();
|
||||||
if (analyticsRequest != null) {
|
if (analyticsRequest != null) {
|
||||||
rb.doAnalytics = true;
|
rb.setAnalytics(true);
|
||||||
rb._analyticsRequestManager = AnalyticsRequestParser.parse(analyticsRequest, new ExpressionFactory(rb.req.getSchema()), rb.isDistrib);
|
rb.setAnalyticsRequestManager(
|
||||||
|
AnalyticsRequestParser.parse(
|
||||||
|
analyticsRequest,
|
||||||
|
new ExpressionFactory(rb.req.getSchema()), isDistributed));
|
||||||
}
|
}
|
||||||
// If there is no request in the current format, check for the old olap-style format
|
// If there is no request in the current format, check for the old olap-style format
|
||||||
else if (rb.req.getParams().getBool(OldAnalyticsParams.OLD_ANALYTICS,false)) {
|
else if (rb.req.getParams().getBool(OldAnalyticsParams.OLD_ANALYTICS,false)) {
|
||||||
rb._analyticsRequestManager = AnalyticsRequestParser.parse(OldAnalyticsRequestConverter.convert(rb.req.getParams()), new ExpressionFactory(rb.req.getSchema()), rb.isDistrib);
|
rb.setAnalyticsRequestManager(
|
||||||
rb._isOlapAnalytics = true;
|
AnalyticsRequestParser.parse(
|
||||||
rb.doAnalytics = true;
|
OldAnalyticsRequestConverter.convert(rb.req.getParams()),
|
||||||
|
new ExpressionFactory(rb.req.getSchema()), isDistributed));
|
||||||
|
rb.setOlapAnalytics(true);
|
||||||
|
rb.setAnalytics(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rb.doAnalytics) {
|
if (rb.isAnalytics()) {
|
||||||
AnalyticsRequestManager reqManager = (AnalyticsRequestManager)rb._analyticsRequestManager;
|
AnalyticsRequestManager reqManager = getAnalyticsRequestManager(rb);
|
||||||
|
|
||||||
// Check to see if the request is distributed
|
// Check to see if the request is distributed
|
||||||
if (rb.isDistrib) {
|
if (isDistributed) {
|
||||||
reqManager.sendShards = true;
|
reqManager.sendShards = true;
|
||||||
reqManager.shardStream = new AnalyticsShardRequestManager(rb.req.getParams(), reqManager);
|
reqManager.shardStream = new AnalyticsShardRequestManager(rb.req.getParams(), reqManager);
|
||||||
} else {
|
} else {
|
||||||
|
@ -71,29 +79,29 @@ public class AnalyticsComponent extends SearchComponent {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(ResponseBuilder rb) throws IOException {
|
public void process(ResponseBuilder rb) throws IOException {
|
||||||
if (!rb.doAnalytics) {
|
if (!rb.isAnalytics()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AnalyticsRequestManager reqManager = (AnalyticsRequestManager)rb._analyticsRequestManager;
|
AnalyticsRequestManager reqManager = getAnalyticsRequestManager(rb);
|
||||||
// Collect the data and generate a response
|
// Collect the data and generate a response
|
||||||
AnalyticsDriver.drive(reqManager, rb.req.getSearcher(), rb.getResults().docSet.getTopFilter(), rb.req);
|
AnalyticsDriver.drive(reqManager, rb.req.getSearcher(), rb.getResults().docSet.getTopFilter(), rb.req);
|
||||||
|
|
||||||
if (rb._isOlapAnalytics) {
|
if (rb.isOlapAnalytics()) {
|
||||||
rb.rsp.add(AnalyticsResponseHeadings.COMPLETED_OLD_HEADER, reqManager.createOldResponse());
|
rb.rsp.add(AnalyticsResponseHeadings.COMPLETED_OLD_HEADER, reqManager.createOldResponse());
|
||||||
} else {
|
} else {
|
||||||
rb.rsp.add(AnalyticsResponseHeadings.COMPLETED_HEADER, reqManager.createResponse());
|
rb.rsp.add(AnalyticsResponseHeadings.COMPLETED_HEADER, reqManager.createResponse());
|
||||||
}
|
}
|
||||||
|
|
||||||
rb.doAnalytics = false;
|
rb.setAnalytics(false);
|
||||||
|
rb.setOlapAnalytics(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int distributedProcess(ResponseBuilder rb) throws IOException {
|
public int distributedProcess(ResponseBuilder rb) throws IOException {
|
||||||
if (!rb.doAnalytics || rb.stage != ResponseBuilder.STAGE_EXECUTE_QUERY) {
|
if (!rb.isAnalytics() || rb.stage != ResponseBuilder.STAGE_EXECUTE_QUERY) {
|
||||||
return ResponseBuilder.STAGE_DONE;
|
return ResponseBuilder.STAGE_DONE;
|
||||||
}
|
}
|
||||||
AnalyticsRequestManager reqManager = (AnalyticsRequestManager)rb._analyticsRequestManager;
|
AnalyticsRequestManager reqManager = getAnalyticsRequestManager(rb);
|
||||||
if (!reqManager.sendShards){
|
if (!reqManager.sendShards){
|
||||||
return ResponseBuilder.STAGE_DONE;
|
return ResponseBuilder.STAGE_DONE;
|
||||||
}
|
}
|
||||||
|
@ -127,10 +135,10 @@ public class AnalyticsComponent extends SearchComponent {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void finishStage(ResponseBuilder rb) {
|
public void finishStage(ResponseBuilder rb) {
|
||||||
if (rb.doAnalytics && rb.stage == ResponseBuilder.STAGE_GET_FIELDS) {
|
if (rb.isAnalytics() && rb.stage == ResponseBuilder.STAGE_GET_FIELDS) {
|
||||||
AnalyticsRequestManager reqManager = (AnalyticsRequestManager)rb._analyticsRequestManager;
|
AnalyticsRequestManager reqManager = getAnalyticsRequestManager(rb);
|
||||||
// Generate responses from the merged shard data
|
// Generate responses from the merged shard data
|
||||||
if (rb._isOlapAnalytics) {
|
if (rb.isOlapAnalytics()) {
|
||||||
rb.rsp.add(AnalyticsResponseHeadings.COMPLETED_OLD_HEADER, reqManager.createOldResponse());
|
rb.rsp.add(AnalyticsResponseHeadings.COMPLETED_OLD_HEADER, reqManager.createOldResponse());
|
||||||
} else {
|
} else {
|
||||||
rb.rsp.add(AnalyticsResponseHeadings.COMPLETED_HEADER, reqManager.createResponse());
|
rb.rsp.add(AnalyticsResponseHeadings.COMPLETED_HEADER, reqManager.createResponse());
|
||||||
|
@ -140,7 +148,6 @@ public class AnalyticsComponent extends SearchComponent {
|
||||||
super.finishStage(rb);
|
super.finishStage(rb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return COMPONENT_NAME;
|
return COMPONENT_NAME;
|
||||||
|
@ -151,6 +158,10 @@ public class AnalyticsComponent extends SearchComponent {
|
||||||
return "Perform analytics";
|
return "Perform analytics";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AnalyticsRequestManager getAnalyticsRequestManager(ResponseBuilder rb) {
|
||||||
|
return (AnalyticsRequestManager)rb.getAnalyticsRequestManager();
|
||||||
|
}
|
||||||
|
|
||||||
/*@Override
|
/*@Override
|
||||||
public NamedList getStatistics() {
|
public NamedList getStatistics() {
|
||||||
return analyticsCollector.getStatistics();
|
return analyticsCollector.getStatistics();
|
||||||
|
|
|
@ -16,6 +16,13 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.handler.component;
|
package org.apache.solr.handler.component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.apache.lucene.search.grouping.SearchGroup;
|
import org.apache.lucene.search.grouping.SearchGroup;
|
||||||
import org.apache.lucene.search.grouping.TopGroups;
|
import org.apache.lucene.search.grouping.TopGroups;
|
||||||
|
@ -23,7 +30,6 @@ import org.apache.lucene.util.BytesRef;
|
||||||
import org.apache.solr.common.SolrDocument;
|
import org.apache.solr.common.SolrDocument;
|
||||||
import org.apache.solr.common.SolrDocumentList;
|
import org.apache.solr.common.SolrDocumentList;
|
||||||
import org.apache.solr.common.util.NamedList;
|
import org.apache.solr.common.util.NamedList;
|
||||||
import org.apache.solr.util.RTimer;
|
|
||||||
import org.apache.solr.common.util.SimpleOrderedMap;
|
import org.apache.solr.common.util.SimpleOrderedMap;
|
||||||
import org.apache.solr.request.SolrQueryRequest;
|
import org.apache.solr.request.SolrQueryRequest;
|
||||||
import org.apache.solr.request.SolrRequestInfo;
|
import org.apache.solr.request.SolrRequestInfo;
|
||||||
|
@ -34,17 +40,11 @@ import org.apache.solr.search.DocSlice;
|
||||||
import org.apache.solr.search.QParser;
|
import org.apache.solr.search.QParser;
|
||||||
import org.apache.solr.search.QueryCommand;
|
import org.apache.solr.search.QueryCommand;
|
||||||
import org.apache.solr.search.QueryResult;
|
import org.apache.solr.search.QueryResult;
|
||||||
import org.apache.solr.search.SortSpec;
|
|
||||||
import org.apache.solr.search.RankQuery;
|
import org.apache.solr.search.RankQuery;
|
||||||
|
import org.apache.solr.search.SortSpec;
|
||||||
import org.apache.solr.search.grouping.GroupingSpecification;
|
import org.apache.solr.search.grouping.GroupingSpecification;
|
||||||
import org.apache.solr.search.grouping.distributed.command.QueryCommandResult;
|
import org.apache.solr.search.grouping.distributed.command.QueryCommandResult;
|
||||||
|
import org.apache.solr.util.RTimer;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is experimental and will be changing in the future.
|
* This class is experimental and will be changing in the future.
|
||||||
|
@ -497,4 +497,28 @@ public class ResponseBuilder
|
||||||
public void setNextCursorMark(CursorMark nextCursorMark) {
|
public void setNextCursorMark(CursorMark nextCursorMark) {
|
||||||
this.nextCursorMark = nextCursorMark;
|
this.nextCursorMark = nextCursorMark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAnalytics(boolean doAnalytics) {
|
||||||
|
this.doAnalytics = doAnalytics;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAnalytics() {
|
||||||
|
return this.doAnalytics;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAnalyticsRequestManager(Object analyticsRequestManager) {
|
||||||
|
this._analyticsRequestManager = analyticsRequestManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getAnalyticsRequestManager() {
|
||||||
|
return this._analyticsRequestManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOlapAnalytics(boolean isOlapAnalytics) {
|
||||||
|
this._isOlapAnalytics = isOlapAnalytics;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOlapAnalytics() {
|
||||||
|
return this._isOlapAnalytics;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,9 @@ import org.junit.BeforeClass;
|
||||||
|
|
||||||
public class ResponseBuilderTest extends SolrTestCaseJ4 {
|
public class ResponseBuilderTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
|
SolrQueryRequest req = req("q", "title:test");
|
||||||
|
SolrQueryResponse rsp = new SolrQueryResponse();
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeClass() throws Exception {
|
public static void beforeClass() throws Exception {
|
||||||
initCore("solrconfig.xml", "schema.xml");
|
initCore("solrconfig.xml", "schema.xml");
|
||||||
|
@ -33,13 +36,33 @@ public class ResponseBuilderTest extends SolrTestCaseJ4 {
|
||||||
|
|
||||||
//This test is being added to verify responseBuilder.isDistributed() exists and is visible.
|
//This test is being added to verify responseBuilder.isDistributed() exists and is visible.
|
||||||
public void testIsDistrib(){
|
public void testIsDistrib(){
|
||||||
|
|
||||||
SolrQueryRequest req = req("q", "title:test");
|
|
||||||
SolrQueryResponse rsp = new SolrQueryResponse();
|
|
||||||
|
|
||||||
ResponseBuilder responseBuilder = new ResponseBuilder(req, rsp, new ArrayList<>(0));
|
ResponseBuilder responseBuilder = new ResponseBuilder(req, rsp, new ArrayList<>(0));
|
||||||
assertFalse(responseBuilder.isDistributed());
|
assertFalse(responseBuilder.isDistributed());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testDoAnalyticsAccessors() {
|
||||||
|
ResponseBuilder rb = new ResponseBuilder(req, rsp, new ArrayList<>(0));
|
||||||
|
assertFalse(rb.isAnalytics());
|
||||||
|
rb.setAnalytics(true);
|
||||||
|
assertTrue(rb.isAnalytics());
|
||||||
|
rb.setAnalytics(false);
|
||||||
|
assertFalse(rb.isAnalytics());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIsOlapAnalyticsAccessors() {
|
||||||
|
ResponseBuilder rb = new ResponseBuilder(req, rsp, new ArrayList<>(0));
|
||||||
|
assertFalse(rb.isOlapAnalytics());
|
||||||
|
rb.setOlapAnalytics(true);
|
||||||
|
assertTrue(rb.isOlapAnalytics());
|
||||||
|
rb.setOlapAnalytics(false);
|
||||||
|
assertFalse(rb.isOlapAnalytics());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAnalyticsRequestManagerAccessors() {
|
||||||
|
ResponseBuilder rb = new ResponseBuilder(req, rsp, new ArrayList<>(0));
|
||||||
|
assertNull(rb.getAnalyticsRequestManager());
|
||||||
|
rb.setAnalyticsRequestManager(this);
|
||||||
|
assertNotNull(rb.getAnalyticsRequestManager());
|
||||||
|
assertEquals(rb.getAnalyticsRequestManager(), this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue