List of usage examples for org.apache.solr.handler.component ResponseBuilder STAGE_GET_FIELDS
int STAGE_GET_FIELDS
To view the source code for org.apache.solr.handler.component ResponseBuilder STAGE_GET_FIELDS.
Click Source Link
From source file:org.alfresco.solr.component.AsyncBuildSuggestComponent.java
License:Open Source License
/** Dispatch shard request in <code>STAGE_EXECUTE_QUERY</code> stage */ @Override// w w w .ja va 2 s. c o m 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; }
From source file:org.alfresco.solr.component.AsyncBuildSuggestComponent.java
License:Open Source License
/** * Used in Distributed Search, merges the suggestion results from every shard * *//*from w w w. j a v a2 s. c o m*/ @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); }
From source file:org.alfresco.solr.component.ConsistencyComponent.java
License:Open Source License
@Override public void finishStage(ResponseBuilder rb) { super.finishStage(rb); if (rb.stage != ResponseBuilder.STAGE_GET_FIELDS) return;// w w w. j a va 2 s.c o m try { process(rb); } catch (IOException e) { LOG.error(e.getMessage()); } }
From source file:org.alfresco.solr.component.QueryLoggingComponent.java
License:Open Source License
@Override public void finishStage(ResponseBuilder rb) { super.finishStage(rb); if (rb.stage != ResponseBuilder.STAGE_GET_FIELDS) return;//www.j a va 2s. c o m try { log(rb); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.alfresco.solr.component.RewriteFacetCountsComponent.java
License:Open Source License
@Override public void finishStage(ResponseBuilder rb) { /// wait until after distributed faceting is done if (!rb.doFacets || rb.stage != ResponseBuilder.STAGE_GET_FIELDS) { return;// w w w. j a v a2s .c o m } else { process(rb); } }
From source file:org.alfresco.solr.component.SetProcessedDeniesComponent.java
License:Open Source License
@Override public void finishStage(ResponseBuilder rb) { if (rb.stage != ResponseBuilder.STAGE_GET_FIELDS) { return;/*from ww w. j a v a 2 s .com*/ } Boolean processedDenies = (Boolean) rb.req.getContext().get(PROCESSED_DENIES); processedDenies = (processedDenies == null) ? false : processedDenies; rb.rsp.add(PROCESSED_DENIES, processedDenies); }
From source file:org.alfresco.solr.component.spellcheck.AlfrescoSpellCheckBackCompatComponent.java
License:Open Source License
public void finishStage(ResponseBuilder rb) { if (!rb.req.getParams().getBool(SpellCheckComponent.COMPONENT_NAME, false) || rb.stage != ResponseBuilder.STAGE_GET_FIELDS) return;//w w w .jav a 2s . co m Map extras = new HashMap(); for (ShardRequest sreq : rb.finished) { for (ShardResponse srsp : sreq.responses) { NamedList nl = null; try { nl = (NamedList) srsp.getSolrResponse().getResponse().get("spellcheck-extras"); } catch (Exception e) { if (rb.req.getParams().getBool(ShardParams.SHARDS_TOLERANT, false)) { continue; // looks like a shard did not return anything } throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unable to read spelling info for shard: " + srsp.getShard(), e); } if (nl != null) { collectExtras(nl, extras); } } } if (extras.size() == 0) { return; } NamedList response = rb.rsp.getValues(); NamedList spellcheck = (NamedList) response.get("spellcheck"); if (spellcheck == null) { return; } NamedList collations = (NamedList) spellcheck.get("collations"); NamedList suggestions = (NamedList) spellcheck.get("suggestions"); if (collations != null) { //Fix up the collationQueryString in Solr 6 for (int i = 0; i < collations.size(); i++) { if ("collation".equals(collations.getName(i))) { NamedList collation = (NamedList) collations.getVal(i); String collationQuery = (String) collation.get("collationQuery"); String collationQueryString = (String) extras.get(collationQuery); collation.add("collationQueryString", collationQueryString); } } //Add the collations to the suggestions to support the Solr 4 format suggestions.addAll(collations); } else { //Fix up the collationQueryString Solr4 for (int i = 0; i < suggestions.size(); i++) { if ("collation".equals(suggestions.getName(i))) { NamedList collation = (NamedList) suggestions.getVal(i); String collationQuery = (String) collation.get("collationQuery"); String collationQueryString = (String) extras.get(collationQuery); collation.add("collationQueryString", collationQueryString); } } } }
From source file:org.dice.solrenhancements.spellchecker.DiceSpellCheckComponent.java
License:Apache License
@Override
@SuppressWarnings({ "unchecked", "deprecation" })
public void finishStage(ResponseBuilder rb) {
SolrParams params = rb.req.getParams();
if (!params.getBool(COMPONENT_NAME, false) || rb.stage != ResponseBuilder.STAGE_GET_FIELDS)
return;//from ww w. ja v a 2 s . co m
boolean extendedResults = params.getBool(SPELLCHECK_EXTENDED_RESULTS, false);
boolean collate = params.getBool(SPELLCHECK_COLLATE, false);
boolean collationExtendedResults = params.getBool(SPELLCHECK_COLLATE_EXTENDED_RESULTS, false);
int maxCollationTries = params.getInt(SPELLCHECK_MAX_COLLATION_TRIES, 0);
int maxCollations = params.getInt(SPELLCHECK_MAX_COLLATIONS, 1);
Integer maxResultsForSuggest = params.getInt(SpellingParams.SPELLCHECK_MAX_RESULTS_FOR_SUGGEST);
int count = rb.req.getParams().getInt(SPELLCHECK_COUNT, 1);
int numSug = Math.max(count, AbstractLuceneSpellChecker.DEFAULT_SUGGESTION_COUNT);
String origQuery = params.get(SPELLCHECK_Q);
if (origQuery == null) {
origQuery = rb.getQueryString();
if (origQuery == null) {
origQuery = params.get(CommonParams.Q);
}
}
long hits = rb.grouping() ? rb.totalHitCount : rb.getNumberDocumentsFound();
boolean isCorrectlySpelled = hits > (maxResultsForSuggest == null ? 0 : maxResultsForSuggest);
SpellCheckMergeData mergeData = new SpellCheckMergeData();
if (maxResultsForSuggest == null || !isCorrectlySpelled) {
for (ShardRequest sreq : rb.finished) {
for (ShardResponse srsp : sreq.responses) {
NamedList nl = (NamedList) srsp.getSolrResponse().getResponse().get("spellcheck");
LOG.info(srsp.getShard() + " " + nl);
if (nl != null) {
mergeData.totalNumberShardResponses++;
collectShardSuggestions(nl, mergeData);
collectShardCollations(mergeData, nl, maxCollationTries);
}
}
}
}
// all shard responses have been collected
// create token and get top suggestions
SolrSpellChecker checker = getSpellChecker(rb.req.getParams());
SpellingResult result = checker.mergeSuggestions(mergeData, numSug, count, extendedResults);
NamedList response = new SimpleOrderedMap();
NamedList suggestions = toNamedList(false, result, origQuery, extendedResults, collate, isCorrectlySpelled);
if (collate) {
SpellCheckCollation[] sortedCollations = mergeData.collations.values()
.toArray(new SpellCheckCollation[mergeData.collations.size()]);
Arrays.sort(sortedCollations);
int i = 0;
while (i < maxCollations && i < sortedCollations.length) {
SpellCheckCollation collation = sortedCollations[i];
i++;
if (collationExtendedResults) {
NamedList extendedResult = new NamedList();
extendedResult.add("collationQuery", collation.getCollationQuery());
extendedResult.add("hits", collation.getHits());
extendedResult.add("misspellingsAndCorrections", collation.getMisspellingsAndCorrections());
suggestions.add("collation", extendedResult);
} else {
suggestions.add("collation", collation.getCollationQuery());
}
}
}
response.add("suggestions", suggestions);
rb.rsp.add("spellcheck", response);
}
From source file:org.tallison.solr.search.concordance.KeywordCooccurComponent.java
License:Apache License
@Override public int distributedProcess(ResponseBuilder rb) throws IOException { if (rb.stage == ResponseBuilder.STAGE_GET_FIELDS) process(rb); //run this locally instead of through the request pump return ResponseBuilder.STAGE_DONE; }
From source file:org.tallison.solr.search.concordance.KeywordCooccurComponent.java
License:Apache License
@Override public void finishStage(ResponseBuilder rb) { SolrParams params = rb.req.getParams(); System.out.println("FINISH STAGE: " + params.toNamedList().size()); if (rb.stage != ResponseBuilder.STAGE_GET_FIELDS) return;/*from w w w. jav a 2 s . co m*/ System.out.println("FINISH STAGE2: " + params.toNamedList().size()); /** * it'd be awesome if this code worked, but it doesn't because * I couldn't figure out how to make ShardRequest make requests * that were not document-list based without editing the * ResponseBuilder class. * ResponseBuilder.doFacets, ResponseBuilder.doTerms, * ResponseBuilder.doHighlights, ResponseBuilder.doWHAT !?! * for (ShardRequest sreq : rb.finished) { for (ShardResponse srsp : sreq.responses) { System.out.println("xx99"); NamedList<Object> nl = (NamedList)srsp.getSolrResponse().getResponse(); if(nl != null) results.add(nl, "extra"); } } /**/ if (!isLocal && requestPump != null) { KeywordCooccurRankHandler.Results results = new KeywordCooccurRankHandler.Results( requestPump.getMetadata()); results.add(rb.rsp.getValues(), "local"); //remove previous result node to replace with the one's below if (results.numResults > 0) rb.rsp.getValues().remove(KeywordCooccurRankHandler.NODE); if (!isLocal) results = KeywordCooccurRankHandler.spinWait(requestPump, results); rb.rsp.add(KeywordCooccurRankHandler.NODE, results.toNamedList()); isLocal = null; requestPump = null; } }