Parse params in Solr config file
Made same error again, time to write it down:
<requestHandler ...>
<lst name="defaults">
<str name="dataFolder">data-folder</str>
</lst>
</requestHandler>
This code doesn't work, dataFolder would be null: the data in params is: defaults={dataFolder=data-folder}
public void init(NamedList args) {
SolrParams params = SolrParams.toSolrParams(args);
dataFolder = params.get(PARAM_DATA_FOLDER);
}
Should use:
super.init(args);
if (defaults != null) {
dataFolder = defaults.get(PARAM_DATA_FOLDER);
}
Be sure to close SolrQueryRequest
org.apache.solr.request.SolrQueryRequestBase
The close() method must be called on any instance of this class once it is no longer in use.
org.apache.solr.core.SolrResourceLoader.normalizeDir(String)
org.apache.solr.core.CoreDescriptor.getDataDir()
if (new File(instanceDir).isAbsolute()) {
result= SolrResourceLoader.normalizeDir(SolrResourceLoader.normalizeDir(instanceDir) + dataDir);
} else {
result= SolrResourceLoader.normalizeDir(coreContainer.getSolrHome() +
SolrResourceLoader.normalizeDir(instanceDir) + dataDir);
}
Using QParser to parse query string
QueryResponseWriter responseWriter = core.getQueryResponseWriter(solrReq);
QParser qparser = QParser.getParser(tmpQuery, "lucene", req);
SolrQueryParser parser = new SolrQueryParser(qparser, req
.getSchema().getDefaultSearchFieldName());
Query query = parser.parse(tmpQuery);
DocSet docSet = searcher.getDocSet(query);
DocSet interSection = docs.intersection(docSet);
Run Query in Solr Server
how solr returnFields defined
ReturnFields returnFields = new SolrReturnFields( req );
rsp.setReturnFields( returnFields );
Using getStatistics to add stats info
public NamedList<Object> getStatistics() {}
private final AtomicLong numTimeouts = new AtomicLong();
private final Timer requestTimes = new Timer();
numErrors.incrementAndGet();
Parse Queries in SolrConfig: org.apache.solr.core.QuerySenderListener.newSearcher(SolrIndexSearcher, SolrIndexSearcher)
try
{
List<NamedList> allLists = (List<NamedList>)args.get("queries");
if (allLists == null) return;
for (NamedList nlst : allLists) {
NamedList result = new NamedList();
if (params.get("distrib") == null) {
params.add("distrib", false);
}
SolrQueryRequest req = new LocalSolrQueryRequest(core,params);
SolrQueryResponse rsp = new SolrQueryResponse();
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
core.execute(core.getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp);
}
} finally {
if (req != null) req.close();
SolrRequestInfo.clearRequestInfo();
}
Using SolrPluginUtils.docListToSolrDocumentList to convert Lucene DocList to SolrDocumentList
SolrPluginUtils.docListToSolrDocumentList(docList,req.getSearcher(), fieldSet, null)
LocalParams
SolrParams localParams = QueryParsing.getLocalParams(param, req.getParams());
key = localParams.get(CommonParams.OUTPUT_KEY, key);
String excludeStr = localParams.get(CommonParams.EXCLUDE);
Map<?,?> tagMap = (Map<?,?>)req.getContext().get("tags");
Made same error again, time to write it down:
<requestHandler ...>
<lst name="defaults">
<str name="dataFolder">data-folder</str>
</lst>
</requestHandler>
This code doesn't work, dataFolder would be null: the data in params is: defaults={dataFolder=data-folder}
public void init(NamedList args) {
SolrParams params = SolrParams.toSolrParams(args);
dataFolder = params.get(PARAM_DATA_FOLDER);
}
Should use:
super.init(args);
if (defaults != null) {
dataFolder = defaults.get(PARAM_DATA_FOLDER);
}
Be sure to close SolrQueryRequest
org.apache.solr.request.SolrQueryRequestBase
The close() method must be called on any instance of this class once it is no longer in use.
org.apache.solr.core.SolrResourceLoader.normalizeDir(String)
org.apache.solr.core.CoreDescriptor.getDataDir()
if (new File(instanceDir).isAbsolute()) {
result= SolrResourceLoader.normalizeDir(SolrResourceLoader.normalizeDir(instanceDir) + dataDir);
} else {
result= SolrResourceLoader.normalizeDir(coreContainer.getSolrHome() +
SolrResourceLoader.normalizeDir(instanceDir) + dataDir);
}
Using QParser to parse query string
QueryResponseWriter responseWriter = core.getQueryResponseWriter(solrReq);
QParser qparser = QParser.getParser(tmpQuery, "lucene", req);
SolrQueryParser parser = new SolrQueryParser(qparser, req
.getSchema().getDefaultSearchFieldName());
Query query = parser.parse(tmpQuery);
DocSet docSet = searcher.getDocSet(query);
DocSet interSection = docs.intersection(docSet);
Run Query in Solr Server
final SolrQueryRequest newReq = new LocalSolrQueryRequest(core, newParams);
final SolrQueryResponse newResp = new SolrQueryResponse();
SolrRequestHandler handler = core.getRequestHandler("/select");
core.execute(handler, newReq, newResp);
SolrIndexSearcher searcher = newReq.getSearcher();
NamedList<Object> valuesNL = newResp.getValues();
Object rspObj = (Object) valuesNL.get("response");
if (rspObj instanceof ResultContext) {
ResultContext rc = (ResultContext) rspObj;
DocList docList = rc.docs;
DocIterator dit = docList.iterator();
while (dit.hasNext()) {
int docid = dit.nextDoc();
Document doc = searcher.doc(docid, (Set<String>) null);
//
}
} else if (rspObj instanceof SolrDocumentList) {
SolrDocumentList docList = (SolrDocumentList) rspObj;
long size = docList.size();
Iterator<SolrDocument> docIt = docList.iterator();
while (docIt.hasNext()) {
SolrDocument doc = docIt.next();
docIt.remove();
//
}
} else {
throw new RuntimeException("Unkown response type: "
+ ((rspObj != null) ? rspObj.getClass() : "null"));
}
how solr returnFields defined
ReturnFields returnFields = new SolrReturnFields( req );
rsp.setReturnFields( returnFields );
Using getStatistics to add stats info
public NamedList<Object> getStatistics() {}
private final AtomicLong numTimeouts = new AtomicLong();
private final Timer requestTimes = new Timer();
numErrors.incrementAndGet();
Parse Queries in SolrConfig: org.apache.solr.core.QuerySenderListener.newSearcher(SolrIndexSearcher, SolrIndexSearcher)
try
{
List<NamedList> allLists = (List<NamedList>)args.get("queries");
if (allLists == null) return;
for (NamedList nlst : allLists) {
NamedList result = new NamedList();
if (params.get("distrib") == null) {
params.add("distrib", false);
}
SolrQueryRequest req = new LocalSolrQueryRequest(core,params);
SolrQueryResponse rsp = new SolrQueryResponse();
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(req, rsp));
core.execute(core.getRequestHandler(req.getParams().get(CommonParams.QT)), req, rsp);
}
} finally {
if (req != null) req.close();
SolrRequestInfo.clearRequestInfo();
}
Using SolrPluginUtils.docListToSolrDocumentList to convert Lucene DocList to SolrDocumentList
SolrPluginUtils.docListToSolrDocumentList(docList,req.getSearcher(), fieldSet, null)
LocalParams
SolrParams localParams = QueryParsing.getLocalParams(param, req.getParams());
key = localParams.get(CommonParams.OUTPUT_KEY, key);
String excludeStr = localParams.get(CommonParams.EXCLUDE);
Map<?,?> tagMap = (Map<?,?>)req.getContext().get("tags");
No comments:
Post a Comment