本文整理汇总了Java中org.apache.solr.request.SolrQueryRequest.getParams方法的典型用法代码示例。如果您正苦于以下问题:Java SolrQueryRequest.getParams方法的具体用法?Java SolrQueryRequest.getParams怎么用?Java SolrQueryRequest.getParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.solr.request.SolrQueryRequest
的用法示例。
在下文中一共展示了SolrQueryRequest.getParams方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doHighlighting
import org.apache.solr.request.SolrQueryRequest; //导入方法依赖的package包/类
@Override
public NamedList<Object> doHighlighting(DocList docs, Query query, SolrQueryRequest req, String[] defaultFields) throws IOException {
final SolrParams params = req.getParams();
// if highlighting isnt enabled, then why call doHighlighting?
if (!isHighlightingEnabled(params))
return null;
SolrIndexSearcher searcher = req.getSearcher();
int[] docIDs = toDocIDs(docs);
// fetch the unique keys
String[] keys = getUniqueKeys(searcher, docIDs);
// query-time parameters
String[] fieldNames = getHighlightFields(query, req, defaultFields);
int maxPassages[] = new int[fieldNames.length];
for (int i = 0; i < fieldNames.length; i++) {
maxPassages[i] = params.getFieldInt(fieldNames[i], HighlightParams.SNIPPETS, 1);
}
PostingsHighlighter highlighter = getHighlighter(req);
Map<String,String[]> snippets = highlighter.highlightFields(fieldNames, query, searcher, docIDs, maxPassages);
return encodeSnippets(keys, fieldNames, snippets);
}
示例2: ExtractingDocumentLoader
import org.apache.solr.request.SolrQueryRequest; //导入方法依赖的package包/类
public ExtractingDocumentLoader(SolrQueryRequest req, UpdateRequestProcessor processor,
TikaConfig config, SolrContentHandlerFactory factory) {
this.params = req.getParams();
this.core = req.getCore();
this.config = config;
this.processor = processor;
templateAdd = new AddUpdateCommand(req);
templateAdd.overwrite = params.getBool(UpdateParams.OVERWRITE, true);
templateAdd.commitWithin = params.getInt(UpdateParams.COMMIT_WITHIN, -1);
//this is lightweight
autoDetectParser = new AutoDetectParser(config);
this.factory = factory;
ignoreTikaException = params.getBool(ExtractingParams.IGNORE_TIKA_EXCEPTION, false);
}
示例3: getFieldsForClustering
import org.apache.solr.request.SolrQueryRequest; //导入方法依赖的package包/类
/**
* Returns the names of fields that will be delivering the actual
* content for clustering. Currently, there are two such fields: document
* title and document content.
*/
private Set<String> getFieldsForClustering(SolrQueryRequest sreq) {
SolrParams solrParams = sreq.getParams();
String titleFieldSpec = solrParams.get(CarrotParams.TITLE_FIELD_NAME, "title");
String snippetFieldSpec = solrParams.get(CarrotParams.SNIPPET_FIELD_NAME, titleFieldSpec);
if (StringUtils.isBlank(snippetFieldSpec)) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, CarrotParams.SNIPPET_FIELD_NAME
+ " must not be blank.");
}
final Set<String> fields = Sets.newHashSet();
fields.addAll(Arrays.asList(titleFieldSpec.split("[, ]")));
fields.addAll(Arrays.asList(snippetFieldSpec.split("[, ]")));
return fields;
}
示例4: handleRequestBody
import org.apache.solr.request.SolrQueryRequest; //导入方法依赖的package包/类
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
rsp.setHttpCaching(false);
final SolrParams solrParams = req.getParams();
String dicPath = solrParams.get("dicPath");
Dictionary dict = Utils.getDict(dicPath, loader);
NamedList<Object> result = new NamedList<Object>();
result.add("dicPath", dict.getDicPath().toURI());
boolean check = solrParams.getBool("check", false); //仅仅用于检测词库是否有变化
//用于尝试加载词库,有此参数, check 参数可以省略。
boolean reload = solrParams.getBool("reload", false);
check |= reload;
boolean changed = false;
boolean reloaded = false;
if(check) {
changed = dict.wordsFileIsChange();
result.add("changed", changed);
}
if(changed && reload) {
reloaded = dict.reload();
result.add("reloaded", reloaded);
}
rsp.add("result", result);
}
示例5: handleRequestBody
import org.apache.solr.request.SolrQueryRequest; //导入方法依赖的package包/类
@Override
public void handleRequestBody(
final SolrQueryRequest request,
final SolrQueryResponse response) throws Exception {
final SolrParams params = request.getParams();
response.setAllValues(
chain.stream()
.map(refName -> { return requestHandler(request, refName); })
.filter(SearchHandler.class::isInstance)
.map(handler -> { return executeQuery(request, response, params, handler); })
.filter(qresponse -> howManyFound(qresponse) > 0)
.findFirst()
.orElse(emptyResponse(request, response)));
}
开发者ID:spaziocodice,项目名称:invisible-queries-request-handler,代码行数:16,代码来源:InvisibleQueriesRequestHandler.java
示例6: handleRequestBody
import org.apache.solr.request.SolrQueryRequest; //导入方法依赖的package包/类
@Override
public void handleRequestBody(SolrQueryRequest solrReq, SolrQueryResponse solrRsp)
throws Exception {
KnowledgeGraphRequest request = parsePost(solrReq);
new RequestValidator(solrReq, request).validate();
ParameterSet parameterSet = new ParameterSet(solrReq.getParams(), defaults, invariants);
NodeContext context = new NodeContext(request, solrReq, parameterSet);
RequestTreeRecurser recurser = new RequestTreeRecurser(context);
KnowledgeGraphResponse response = new KnowledgeGraphResponse();
response.data = recurser.score();
solrRsp.add("relatednessResponse", response);
}
示例7: testFusionResponseProcessing
import org.apache.solr.request.SolrQueryRequest; //导入方法依赖的package包/类
public void testFusionResponseProcessing() throws Exception {
String typicalFusionResponse = "{ \n" +
" \"fusion\" : {\n" +
" \"query-params\": {\n" +
" \"extra\": [\"test\"],\n" +
" \"extrarray\": [\"test1\",\"test2\"]\n" +
" },\n" +
" \"landing-pages\": [\n" +
" \"www.lucidworks.com\"\n" +
" ]\n" +
" }\n" +
"}";
SolrQueryRequest req = new LocalSolrQueryRequest(null, new NamedList());
SolrQueryResponse rsp = new SolrQueryResponse();
FusionQPSearchComponent.overlayFusionData(typicalFusionResponse, req, rsp);
// test query params made it to the request
SolrParams p = req.getParams();
assertEquals("test", p.getParams("extra")[0]);
assertEquals("test1", p.getParams("extrarray")[0]);
assertEquals("test2", p.getParams("extrarray")[1]);
// check that everything else passed through into the response
NamedList nl = rsp.getValues();
ArrayList landingPages = (ArrayList)((NamedList)nl.get("fusion")).get("landing-pages");
assertNotNull(landingPages);
assertEquals("www.lucidworks.com", landingPages.get(0));
}
示例8: handleSwapAction
import org.apache.solr.request.SolrQueryRequest; //导入方法依赖的package包/类
/**
* Handle "SWAP" action
*/
protected void handleSwapAction(SolrQueryRequest req, SolrQueryResponse rsp) {
final SolrParams params = req.getParams();
final SolrParams required = params.required();
final String cname = params.get(CoreAdminParams.CORE);
String other = required.get(CoreAdminParams.OTHER);
coreContainer.swap(cname, other);
}
示例9: doDebugTrack
import org.apache.solr.request.SolrQueryRequest; //导入方法依赖的package包/类
private void doDebugTrack(ResponseBuilder rb) {
SolrQueryRequest req = rb.req;
String rid = req.getParams().get(CommonParams.REQUEST_ID);
if(rid == null || "".equals(rid)) {
rid = generateRid(rb);
ModifiableSolrParams params = new ModifiableSolrParams(req.getParams());
params.add(CommonParams.REQUEST_ID, rid);//add rid to the request so that shards see it
req.setParams(params);
}
rb.addDebug(rid, "track", CommonParams.REQUEST_ID);//to see it in the response
rb.rsp.addToLog(CommonParams.REQUEST_ID, rid); //to see it in the logs of the landing core
}
示例10: handlePing
import org.apache.solr.request.SolrQueryRequest; //导入方法依赖的package包/类
protected void handlePing(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception
{
SolrParams params = req.getParams();
SolrCore core = req.getCore();
// Get the RequestHandler
String qt = params.get( CommonParams.QT );//optional; you get the default otherwise
SolrRequestHandler handler = core.getRequestHandler( qt );
if( handler == null ) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
"Unknown RequestHandler (qt): "+qt );
}
if( handler instanceof PingRequestHandler ) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
"Cannot execute the PingRequestHandler recursively" );
}
// Execute the ping query and catch any possible exception
Throwable ex = null;
try {
SolrQueryResponse pingrsp = new SolrQueryResponse();
core.execute(handler, req, pingrsp );
ex = pingrsp.getException();
}
catch( Exception e ) {
ex = e;
}
// Send an error or an 'OK' message (response code will be 200)
if( ex != null ) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
"Ping query caused exception: "+ex.getMessage(), ex );
}
rsp.add( "status", "OK" );
}
示例11: getHighlighter
import org.apache.solr.request.SolrQueryRequest; //导入方法依赖的package包/类
/**
* Return a {@link org.apache.lucene.search.highlight.Highlighter} appropriate for this field.
* @param query The current Query
* @param fieldName The name of the field
* @param request The current SolrQueryRequest
*/
protected Highlighter getHighlighter(Query query, String fieldName, SolrQueryRequest request) {
SolrParams params = request.getParams();
Highlighter highlighter = new Highlighter(
getFormatter(fieldName, params),
getEncoder(fieldName, params),
getQueryScorer(query, fieldName, request));
highlighter.setTextFragmenter(getFragmenter(fieldName, params));
return highlighter;
}
示例12: handleRequestBody
import org.apache.solr.request.SolrQueryRequest; //导入方法依赖的package包/类
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
// Make sure the cores is enabled
CoreContainer cores = getCoreContainer();
if (cores == null) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
"Core container instance missing");
}
//boolean doPersist = false;
String taskId = req.getParams().get("async");
TaskObject taskObject = new TaskObject(taskId);
if(taskId != null) {
// Put the tasks into the maps for tracking
if (getMap(RUNNING).containsKey(taskId) || getMap(COMPLETED).containsKey(taskId) || getMap(FAILED).containsKey(taskId)) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
"Duplicate request with the same requestid found.");
}
addTask(RUNNING, taskObject);
}
// Pick the action
SolrParams params = req.getParams();
CoreAdminAction action = CoreAdminAction.STATUS;
String a = params.get(CoreAdminParams.ACTION);
if (a != null) {
action = CoreAdminAction.get(a);
if (action == null) {
this.handleCustomAction(req, rsp);
}
}
if (taskId == null) {
handleRequestInternal(req, rsp, action);
} else {
ParallelCoreAdminHandlerThread parallelHandlerThread = new ParallelCoreAdminHandlerThread(req, rsp, action, taskObject);
parallelExecutor.execute(parallelHandlerThread);
}
}
示例13: handleRequestBody
import org.apache.solr.request.SolrQueryRequest; //导入方法依赖的package包/类
/**
* Expands aliases into queries for thematic collections.
*
* Operates by taking apart the passed request, scanning it for thematic-collection keywords,
* and replacing those it finds with the appropriate expanded query.
*
* @author thill
* @version 2017.11.14
*/
@Override
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp)
throws Exception {
AliasConfig aliasConfig = req.getCore().getAliasConfig();
HashMap<String, HashMap<String, String>> aliases = aliasConfig.getAliases();
SolrParams params = req.getParams();
Iterator<String> pnit = params.getParameterNamesIterator();
Map<String, String[]> modifiedParams = new HashMap<String, String[]>();
String paramnames = "";
while(pnit.hasNext()) {
String pname = pnit.next();
paramnames += pname + " ";
String[] pvalues = params.getParams(pname);
if(!pname.equals("q") && !pname.equals("fq")) {
modifiedParams.put(pname, pvalues);
}
else {
String[] modifiedValues = this.modifyValues(aliases, pvalues);
modifiedParams.put(pname, modifiedValues);
}
}
MultiMapSolrParams newParams = new MultiMapSolrParams(modifiedParams);
req.setParams(newParams);
// a little debugging check
//String paramCheck = outputParams(newParams);
// rsp.add("test", paramCheck);
super.handleRequestBody(req, rsp);
}
示例14: createSuggestions
import org.apache.solr.request.SolrQueryRequest; //导入方法依赖的package包/类
@Override
public Set<RelaxerSuggestion> createSuggestions(SolrQueryRequest req) {
List<String> tokens = new ArrayList<String>();
int countOfQuotes = 0;
SolrParams params = req.getParams();
String userQuery = params.get(CommonParams.Q);
countOfQuotes = ReSearcherUtils.tokenizeQueryString(userQuery, tokens);
if ((tokens.size() - countOfQuotes) <= 1) {
// nothing to offer, there were 1 or 0 terms in the query
return null;
} else {
Set<RelaxerSuggestion> suggestions = new LinkedHashSet<RelaxerSuggestion>();
for (int i = 0; i < tokens.size(); i++) {
StringBuilder sug = new StringBuilder();
if (tokens.get(i).equals("\"")) {
// quotes will not be treated as a separate term
continue;
}
int startingQuoteOpened = 0;
boolean startingQuoteOmitted = false;
for (int j = 0; j < tokens.size(); j++) {
if (tokens.get(j).equals("\"")) {
startingQuoteOpened++;
if ((startingQuoteOpened % 2) == 1) {
// if this was starting quote, we have to look for ending quote and compare
if ((tokens.size() > (j + 3)) && (tokens.get(j + 3).equals("\"")) && ((j + 1 == i) || (j + 2 == i))) {
// if there are just two terms under this quote, and we are currently removing one of them, no need to add quotes
startingQuoteOmitted = true;
}
else if ((tokens.size() > (j + 2)) && (tokens.get(j + 2).equals("\"")) && ((j + 1 == i))) {
// if there is just one terms under this quote, and we are currently removing it, no need to add quotes
startingQuoteOmitted = true;
}
else {
sug.append("\"");
}
}
else {
// this was ending quote, so we have to check if we should write it or not
if (startingQuoteOmitted == false) {
// since all tokens append blank to the end, if we add quote, it should replace that blank
sug.setCharAt(sug.length() - 1, '\"');
sug.append(" ");
}
// reset the flag in any case
startingQuoteOmitted = false;
}
}
else if (j != i) {
sug.append(tokens.get(j).trim());
sug.append(" ");
}
}
String relaxedUserQuery = sug.toString().trim();
suggestions.add(new QueryRelaxerSuggestion(relaxedUserQuery, userQuery, relaxedUserQuery));
}
return suggestions;
}
}
示例15: handleUrlSearch
import org.apache.solr.request.SolrQueryRequest; //导入方法依赖的package包/类
/**
* Searches for an image given by an URL. Note that (i) extracting image features takes time and
* (ii) not every image is readable by Java.
*
* @param req
* @param rsp
* @throws IOException
* @throws InstantiationException
* @throws IllegalAccessException
*/
private void handleUrlSearch(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException, InstantiationException, IllegalAccessException {
SolrParams params = req.getParams();
String paramUrl = params.get("url");
String paramField = req.getParams().get("field", "cl_ha");
if (!paramField.endsWith("_ha")) paramField += "_ha";
int paramRows = params.getInt("rows", defaultNumberOfResults);
numberOfQueryTerms = req.getParams().getDouble("accuracy", DEFAULT_NUMBER_OF_QUERY_TERMS);
numberOfCandidateResults = req.getParams().getInt("candidates", DEFAULT_NUMBER_OF_CANDIDATES);
useMetricSpaces = req.getParams().getBool("ms", DEFAULT_USE_METRIC_SPACES);
GlobalFeature feat = null;
int[] hashes = null;
Query query = null;
// wrapping the whole part in the try
try {
BufferedImage img = ImageIO.read(new URL(paramUrl).openStream());
img = ImageUtils.trimWhiteSpace(img);
// getting the right feature per field:
if (FeatureRegistry.getClassForHashField(paramField) == null) // if the feature is not registered.
feat = new ColorLayout();
else {
feat = (GlobalFeature) FeatureRegistry.getClassForHashField(paramField).newInstance();
}
feat.extract(img);
if (!useMetricSpaces) {
// Re-generating the hashes to save space (instead of storing them in the index)
HashTermStatistics.addToStatistics(req.getSearcher(), paramField);
hashes = BitSampling.generateHashes(feat.getFeatureVector());
query = createQuery(hashes, paramField, numberOfQueryTerms);
} else if (MetricSpaces.supportsFeature(feat)) {
// ----< Metric Spaces >-----
int queryLength = (int) StatsUtils.clamp(numberOfQueryTerms * MetricSpaces.getPostingListLength(feat), 3, MetricSpaces.getPostingListLength(feat));
String msQuery = MetricSpaces.generateBoostedQuery(feat, queryLength);
QueryParser qp = new QueryParser(paramField.replace("_ha", "_ms"), new WhitespaceAnalyzer());
query = qp.parse(msQuery);
} else {
rsp.add("Error", "Feature not supported by MetricSpaces: " + feat.getClass().getSimpleName());
query = new MatchAllDocsQuery();
}
} catch (Exception e) {
rsp.add("Error", "Error reading image from URL: " + paramUrl + ": " + e.getMessage());
e.printStackTrace();
}
// search if the feature has been extracted and query is there.
if (feat != null && query != null) {
doSearch(req, rsp, req.getSearcher(), paramField, paramRows, getFilterQueries(req), query, feat);
}
}