Java Code Examples for org.apache.solr.handler.component.ResponseBuilder#STAGE_GET_FIELDS

The following examples show how to use org.apache.solr.handler.component.ResponseBuilder#STAGE_GET_FIELDS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MtasSolrComponentPrefix.java    From mtas with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void finishStage(ResponseBuilder rb) {
  if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
      && rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY
      && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
    for (ShardRequest sreq : rb.finished) {
      if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
          && sreq.params.getBool(PARAM_MTAS_PREFIX, false)) {
        for (ShardResponse shardResponse : sreq.responses) {
          NamedList<Object> response = shardResponse.getSolrResponse()
              .getResponse();
          try {
            ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response
                .findRecursive("mtas", NAME);
            if (data != null) {
              MtasSolrResultUtil.decode(data);
            }
          } catch (ClassCastException e) {
            log.debug(e);
            // shouldnt happen
          }
        }
      }
    }
  }
}
 
Example 2
Source File: AsyncBuildSuggestComponent.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Dispatch shard request in <code>STAGE_EXECUTE_QUERY</code> stage */
@Override
public int distributedProcess(ResponseBuilder rb) {
  SolrParams params = rb.req.getParams();
  LOG.debug("SuggestComponent distributedProcess with : " + params);
  if (rb.stage < ResponseBuilder.STAGE_EXECUTE_QUERY) 
    return ResponseBuilder.STAGE_EXECUTE_QUERY;
  if (rb.stage == ResponseBuilder.STAGE_EXECUTE_QUERY) {
    ShardRequest sreq = new ShardRequest();
    sreq.purpose = ShardRequest.PURPOSE_GET_TOP_IDS;
    sreq.params = new ModifiableSolrParams(rb.req.getParams());
    sreq.params.remove(ShardParams.SHARDS);
    rb.addRequest(this, sreq);
    return ResponseBuilder.STAGE_GET_FIELDS;
  }

  return ResponseBuilder.STAGE_DONE;
}
 
Example 3
Source File: MtasSolrComponentStats.java    From mtas with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void finishStage(ResponseBuilder rb) {
  if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
      && rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY
      && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
    for (ShardRequest sreq : rb.finished) {
      if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
          && sreq.params.getBool(PARAM_MTAS_STATS, false)) {
        for (ShardResponse shardResponse : sreq.responses) {
          NamedList<Object> response = shardResponse.getSolrResponse()
              .getResponse();
          try {
            ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response
                .findRecursive("mtas", NAME);
            if (data != null) {
              MtasSolrResultUtil.decode(data);
            }
          } catch (ClassCastException e) {
            log.debug(e);
            // shouldnt happen
          }
        }
      }
    }
  }
}
 
Example 4
Source File: MtasSolrComponentFacet.java    From mtas with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void finishStage(ResponseBuilder rb) {
  if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
      && rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY
      && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
    for (ShardRequest sreq : rb.finished) {
      if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
          && sreq.params.getBool(PARAM_MTAS_FACET, false)) {
        for (ShardResponse shardResponse : sreq.responses) {
          NamedList<Object> response = shardResponse.getSolrResponse()
              .getResponse();
          try {
            ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response
                .findRecursive("mtas", NAME);
            if (data != null) {
              MtasSolrResultUtil.decode(data);
            }
          } catch (ClassCastException e) {
            log.debug(e);
            // shouldn't happen
          }
        }
      }
    }
  }
}
 
Example 5
Source File: MtasSolrComponentKwic.java    From mtas with Apache License 2.0 5 votes vote down vote up
public void finishStage(ResponseBuilder rb) {
  if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
      && rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY
      && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
    for (ShardRequest sreq : rb.finished) {
      if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
          && sreq.params.getBool(PARAM_MTAS_KWIC, false)) {
        // nothing to do
      }
    }
  }
}
 
Example 6
Source File: MergeSearchComponent.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
private boolean doMerge(ResponseBuilder rb) {
  SolrParams params = rb.req.getParams();
  if (! params.getBool(getName(), false)) {
    return false;
  }

  if (rb.stage != ResponseBuilder.STAGE_GET_FIELDS) {
    return false;
  }
  
  return true;
}
 
Example 7
Source File: MtasSolrComponentList.java    From mtas with Apache License 2.0 5 votes vote down vote up
public void finishStage(ResponseBuilder rb) {
  if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
      && rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY
      && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
    for (ShardRequest sreq : rb.finished) {
      if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
          && sreq.params.getBool(PARAM_MTAS_LIST, false)) {
        // nothing to do
      }
    }
  }
}
 
Example 8
Source File: MtasSolrComponentVersion.java    From mtas with Apache License 2.0 5 votes vote down vote up
@Override
public void finishStage(ResponseBuilder rb) {
	if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) {
		if (rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
			for (ShardRequest sreq : rb.finished) {
				if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
						&& sreq.params.getBool(PARAM_MTAS_VERSION, false)) {
					for (ShardResponse shardResponse : sreq.responses) {
						NamedList<Object> solrShardResponse = shardResponse.getSolrResponse().getResponse();
						try {
							SimpleOrderedMap<Object> data = (SimpleOrderedMap<Object>) solrShardResponse
									.findRecursive(MtasSolrSearchComponent.NAME, NAME);
							// create shardInfo
							SimpleOrderedMap<Object> dataShard = new SimpleOrderedMap<>();
							dataShard.add(NAME_MTAS_VERSION_SHARD, shardResponse.getShard());
							dataShard.add(NAME, data.clone());
							List<SimpleOrderedMap> dataShards = new ArrayList<>();
							dataShards.add(dataShard);
							// create main data
							data.clear();
							data.addAll(getVersion());
							// add shardInfo
							data.add(NAME_MTAS_VERSION_SHARDS, dataShards);
						} catch (ClassCastException | IOException e) {
							log.debug(e);
							// shouldn't happen
						}

					}
				}
			}

		}
	}

}
 
Example 9
Source File: MtasSolrComponentDocument.java    From mtas with Apache License 2.0 5 votes vote down vote up
public void finishStage(ResponseBuilder rb) {
  if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
      && rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY
      && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
    for (ShardRequest sreq : rb.finished) {
      if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
          && sreq.params.getBool(PARAM_MTAS_DOCUMENT, false)) {
        // nothing to do
      }
    }
  }
}
 
Example 10
Source File: RewriteFacetCountsComponent.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void finishStage(ResponseBuilder rb)
{
    /// wait until after distributed faceting is done 
    if (!rb.doFacets || rb.stage != ResponseBuilder.STAGE_GET_FIELDS) 
    {
        return;
    }
    else 
    {
        process(rb);
    }
}
 
Example 11
Source File: MtasSolrComponentGroup.java    From mtas with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void finishStage(ResponseBuilder rb) {
  if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
      && rb.stage >= ResponseBuilder.STAGE_EXECUTE_QUERY
      && rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
    // decode finished results
    for (ShardRequest sreq : rb.finished) {
      if (sreq.params.getBool(MtasSolrSearchComponent.PARAM_MTAS, false)
          && sreq.params.getBool(PARAM_MTAS_GROUP, false)) {
        for (ShardResponse shardResponse : sreq.responses) {
          NamedList<Object> response = shardResponse.getSolrResponse()
              .getResponse();
          try {
            ArrayList<NamedList<Object>> data = (ArrayList<NamedList<Object>>) response
                .findRecursive("mtas", NAME);
            if (data != null) {
              MtasSolrResultUtil.decode(data);
            }
          } catch (ClassCastException e) {
            log.debug(e);
            // shouldn't happen
          }
        }
      }
    }
  }
}
 
Example 12
Source File: AbstractReSearcherComponent.java    From solr-researcher with Apache License 2.0 5 votes vote down vote up
@Override
public void finishStage(ResponseBuilder rb) {
  if (!checkComponentShouldProcess(rb)) {
    return;
  }

  if (rb.stage == ResponseBuilder.STAGE_GET_FIELDS) {
    doProcess(rb);
  }
}
 
Example 13
Source File: FacetModule.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void finishStage(ResponseBuilder rb) {
  if (rb.stage != ResponseBuilder.STAGE_GET_FIELDS) return;

  FacetComponentState facetState = getFacetComponentState(rb);
  if (facetState == null) return;

  if (facetState.merger != null) {
    // TODO: merge any refinements
    rb.rsp.add("facets", facetState.merger.getMergedResult());
  }
}
 
Example 14
Source File: ClusteringComponent.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public void finishStage(ResponseBuilder rb) {
  SolrParams params = rb.req.getParams();
  if (!params.getBool(COMPONENT_NAME, false) || 
      !params.getBool(ClusteringParams.USE_SEARCH_RESULTS, false)) {
    return;
  }

  if (rb.stage == ResponseBuilder.STAGE_GET_FIELDS) {
    String name = getClusteringEngineName(rb);
    SearchClusteringEngine engine = searchClusteringEngines.get(name);
    if (engine != null) {
      checkAvailable(name, engine);
      SolrDocumentList solrDocList = (SolrDocumentList) rb.rsp.getResponse();
      // TODO: Currently, docIds is set to null in distributed environment.
      // This causes CarrotParams.PRODUCE_SUMMARY doesn't work.
      // To work CarrotParams.PRODUCE_SUMMARY under distributed mode, we can choose either one of:
      // (a) In each shard, ClusteringComponent produces summary and finishStage()
      //     merges these summaries.
      // (b) Adding doHighlighting(SolrDocumentList, ...) method to SolrHighlighter and
      //     making SolrHighlighter uses "external text" rather than stored values to produce snippets.
      Map<SolrDocument,Integer> docIds = null;
      Object clusters = engine.cluster(rb.getQuery(), solrDocList, docIds, rb.req);
      rb.rsp.add("clusters", clusters);
    } else {
      log.warn("No engine named: {}", name);
    }
  }
}
 
Example 15
Source File: AsyncBuildSuggestComponent.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
/** 
 * Used in Distributed Search, merges the suggestion results from every shard
 * */
@Override
public void finishStage(ResponseBuilder rb) {
  SolrParams params = rb.req.getParams();
  LOG.debug("SuggestComponent finishStage with : " + params);
  if (!params.getBool(COMPONENT_NAME, false) || rb.stage != ResponseBuilder.STAGE_GET_FIELDS)
    return;
  int count = params.getInt(SUGGEST_COUNT, 1);
  
  List<SuggesterResult> suggesterResults = new ArrayList<>();
  
  // Collect Shard responses
  for (ShardRequest sreq : rb.finished) {
    for (ShardResponse srsp : sreq.responses) {
      NamedList<Object> resp;
      if((resp = srsp.getSolrResponse().getResponse()) != null) {
        @SuppressWarnings("unchecked")
        Map<String, SimpleOrderedMap<NamedList<Object>>> namedList = 
            (Map<String, SimpleOrderedMap<NamedList<Object>>>) resp.get(SuggesterResultLabels.SUGGEST);
        LOG.debug(srsp.getShard() + " : " + namedList);
        suggesterResults.add(toSuggesterResult(namedList));
      }
    }
  }
  
  // Merge Shard responses
  SuggesterResult suggesterResult = merge(suggesterResults, count);
  Map<String, SimpleOrderedMap<NamedList<Object>>> namedListResults = 
      new HashMap<>();
  toNamedList(suggesterResult, namedListResults);
  
  rb.rsp.add(SuggesterResultLabels.SUGGEST, namedListResults);
}
 
Example 16
Source File: SetProcessedDeniesComponent.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void finishStage(ResponseBuilder rb) {
  if (rb.stage != ResponseBuilder.STAGE_GET_FIELDS) {
    return;
  }
  
  Boolean processedDenies = (Boolean) rb.req.getContext().get(PROCESSED_DENIES);
  processedDenies = (processedDenies == null) ? false : processedDenies;
  rb.rsp.add(PROCESSED_DENIES, processedDenies);
}
 
Example 17
Source File: ConsistencyComponent.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void finishStage(ResponseBuilder rb)
{
    super.finishStage(rb);
    if (rb.stage != ResponseBuilder.STAGE_GET_FIELDS)
        return;
    try {
        process(rb);
    } catch (IOException e) {
        LOG.error(e.getMessage());
    }
}
 
Example 18
Source File: QueryLoggingComponent.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void finishStage(ResponseBuilder rb)
{
    super.finishStage(rb);
    if (rb.stage != ResponseBuilder.STAGE_GET_FIELDS)
        return;
    try
    {
        log(rb);
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
}
 
Example 19
Source File: MtasSolrResultMerge.java    From mtas with Apache License 2.0 4 votes vote down vote up
/**
 * Merge.
 *
 * @param rb
 *            the rb
 */
@SuppressWarnings("unchecked")
public void merge(ResponseBuilder rb) {
	if (rb.req.getParams().getBool(MtasSolrSearchComponent.PARAM_MTAS, false)) {
		// mtas response
		NamedList<Object> mtasResponse = null;
		boolean newResponse = false;
		try {
			mtasResponse = (NamedList<Object>) rb.rsp.getValues().get(MtasSolrSearchComponent.NAME);
		} catch (ClassCastException e) {
			log.debug(e);
			mtasResponse = null;
		}
		if (mtasResponse == null) {
			newResponse = true;
			mtasResponse = new SimpleOrderedMap<>();
		}

		for (ShardRequest sreq : rb.finished) {
			if (rb.stage == ResponseBuilder.STAGE_EXECUTE_QUERY) {
				// merge version
				if (rb.req.getParams().getBool(MtasSolrComponentVersion.PARAM_MTAS_VERSION, false)) {
					mergeNamedList(sreq, mtasResponse, MtasSolrComponentVersion.NAME, null);
				}
				// merge stats
				if (rb.req.getParams().getBool(MtasSolrComponentStats.PARAM_MTAS_STATS, false)) {
					mergeNamedList(sreq, mtasResponse, MtasSolrComponentStats.NAME, null);
				}
				// merge group
				if (rb.req.getParams().getBool(MtasSolrComponentGroup.PARAM_MTAS_GROUP, false)) {
					mergeArrayList(sreq, mtasResponse, MtasSolrComponentGroup.NAME, null, false);
				}
				// merge facet
				if (rb.req.getParams().getBool(MtasSolrComponentFacet.PARAM_MTAS_FACET, false)) {
					mergeArrayList(sreq, mtasResponse, MtasSolrComponentFacet.NAME, null, false);
				}
				// merge collection
				if (rb.req.getParams().getBool(MtasSolrComponentCollection.PARAM_MTAS_COLLECTION, false)) {
					mergeArrayList(sreq, mtasResponse, MtasSolrComponentCollection.NAME, null, false);
				}
				// merge prefix
				if (rb.req.getParams().getBool(MtasSolrComponentPrefix.PARAM_MTAS_PREFIX, false)) {
					mergeArrayList(sreq, mtasResponse, MtasSolrComponentPrefix.NAME, null, false);
				}
			} else if (rb.stage == MtasSolrSearchComponent.STAGE_COLLECTION_INIT) {
				// merge collection
				if (rb.req.getParams().getBool(MtasSolrComponentCollection.PARAM_MTAS_COLLECTION, false)) {
					mergeArrayList(sreq, mtasResponse, MtasSolrComponentCollection.NAME, null, false);
				}
			} else if (rb.stage == MtasSolrSearchComponent.STAGE_TERMVECTOR_MISSING_KEY) {
				// merge termvector
				if (rb.req.getParams().getBool(MtasSolrComponentTermvector.PARAM_MTAS_TERMVECTOR, false)) {
					mergeArrayList(sreq, mtasResponse, MtasSolrComponentTermvector.NAME, null, false);
				}
			} else if (rb.stage == MtasSolrSearchComponent.STAGE_LIST) {
				// merge list
				if (rb.req.getParams().getBool(MtasSolrComponentList.PARAM_MTAS_LIST, false)) {
					mergeArrayList(sreq, mtasResponse, MtasSolrComponentList.NAME, ShardRequest.PURPOSE_PRIVATE,
							true);
				}
			} else if (rb.stage == ResponseBuilder.STAGE_GET_FIELDS) {
				// merge document
				if (rb.req.getParams().getBool(MtasSolrComponentDocument.PARAM_MTAS_DOCUMENT, false)) {
					mergeArrayList(sreq, mtasResponse, MtasSolrComponentDocument.NAME, ShardRequest.PURPOSE_PRIVATE,
							true);
				}
				// merge kwic
				if (rb.req.getParams().getBool(MtasSolrComponentKwic.PARAM_MTAS_KWIC, false)) {
					mergeArrayList(sreq, mtasResponse, MtasSolrComponentKwic.NAME, ShardRequest.PURPOSE_PRIVATE,
							true);
				}
			}
		}
		if (newResponse && mtasResponse.size() > 0) {
			rb.rsp.add(MtasSolrSearchComponent.NAME, mtasResponse);
		}
	}
}
 
Example 20
Source File: MtasSolrSearchComponent.java    From mtas with Apache License 2.0 4 votes vote down vote up
@Override
public void finishStage(ResponseBuilder rb) {
	 // System.out
	 // .println(System.nanoTime() + " - " + Thread.currentThread().getId()
	 //  + " - " + rb.req.getParams().getBool(ShardParams.IS_SHARD, false)
	 // + " FINISHRESPONSES " + rb.stage + " " + rb.req.getParamString());
	MtasSolrStatus solrStatus = Objects
			.requireNonNull((MtasSolrStatus) rb.req.getContext().get(MtasSolrStatus.class), "couldn't find status");
	solrStatus.setStage(rb.stage);
	try {
		if (rb.stage == ResponseBuilder.STAGE_EXECUTE_QUERY) {
			Status status = solrStatus.status();
			if (status.numberDocumentsFound == null) {
				status.numberDocumentsFound = rb.getNumberDocumentsFound();
			}
			// try to finish status from get fields stage
		} else if (rb.stage >= ResponseBuilder.STAGE_GET_FIELDS) {
			finishStatus(solrStatus);
		}
		if (rb.req.getParams().getBool(PARAM_MTAS, false)) {
			if (rb.req.getParams().getBool(MtasSolrComponentVersion.PARAM_MTAS_VERSION, false)) {
				searchVersion.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentStats.PARAM_MTAS_STATS, false)) {
				searchStats.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentTermvector.PARAM_MTAS_TERMVECTOR, false)) {
				searchTermvector.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentPrefix.PARAM_MTAS_PREFIX, false)) {
				searchPrefix.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentFacet.PARAM_MTAS_FACET, false)) {
				searchFacet.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentCollection.PARAM_MTAS_COLLECTION, false)) {
				searchCollection.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentGroup.PARAM_MTAS_GROUP, false)) {
				searchGroup.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentList.PARAM_MTAS_LIST, false)) {
				searchList.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentDocument.PARAM_MTAS_DOCUMENT, false)) {
				searchDocument.finishStage(rb);
			}
			if (rb.req.getParams().getBool(MtasSolrComponentKwic.PARAM_MTAS_KWIC, false)) {
				searchKwic.finishStage(rb);
			}
			mtasSolrResultMerge.merge(rb);
		}
	} catch (ExitableDirectoryReader.ExitingReaderException e) {
		solrStatus.setError(e.getMessage());
	}
}