use of org.apache.solr.update.processor.UpdateRequestProcessor in project SearchServices by Alfresco.
the class SolrInformationServer method hardCommit.
@Override
public void hardCommit() throws IOException {
// avoid multiple commits and warming searchers
commitAndRollbackLock.writeLock().lock();
try {
SolrQueryRequest request = null;
UpdateRequestProcessor processor = null;
try {
request = getLocalSolrQueryRequest();
processor = this.core.getUpdateProcessingChain(null).createProcessor(request, new SolrQueryResponse());
CommitUpdateCommand commitUpdateCommand = new CommitUpdateCommand(request, false);
commitUpdateCommand.openSearcher = false;
commitUpdateCommand.softCommit = false;
commitUpdateCommand.waitSearcher = false;
processor.processCommit(commitUpdateCommand);
} finally {
if (processor != null) {
processor.finish();
}
if (request != null) {
request.close();
}
}
} finally {
commitAndRollbackLock.writeLock().unlock();
}
}
use of org.apache.solr.update.processor.UpdateRequestProcessor in project SearchServices by Alfresco.
the class SolrInformationServer method capIndex.
public void capIndex(long dbid) throws IOException {
SolrQueryRequest request = null;
UpdateRequestProcessor processor = null;
try {
request = getLocalSolrQueryRequest();
processor = this.core.getUpdateProcessingChain(null).createProcessor(request, new SolrQueryResponse());
AddUpdateCommand cmd = new AddUpdateCommand(request);
cmd.overwrite = true;
SolrInputDocument input = new SolrInputDocument();
input.addField(FIELD_SOLR4_ID, indexCapId);
input.addField(FIELD_VERSION, 0);
// Making this negative to ensure it is never confused with node DBID
input.addField(FIELD_DBID, -dbid);
input.addField(FIELD_DOC_TYPE, DOC_TYPE_STATE);
cmd.solrDoc = input;
processor.processAdd(cmd);
} finally {
if (processor != null) {
processor.finish();
}
if (request != null) {
request.close();
}
}
}
use of org.apache.solr.update.processor.UpdateRequestProcessor in project SearchServices by Alfresco.
the class SolrInformationServer method indexTransaction.
@Override
public void indexTransaction(Transaction info, boolean overwrite) throws IOException {
canUpdate();
SolrQueryRequest request = null;
UpdateRequestProcessor processor = null;
try {
request = getLocalSolrQueryRequest();
processor = this.core.getUpdateProcessingChain(null).createProcessor(request, new SolrQueryResponse());
AddUpdateCommand cmd = new AddUpdateCommand(request);
cmd.overwrite = overwrite;
SolrInputDocument input = new SolrInputDocument();
input.addField(FIELD_SOLR4_ID, AlfrescoSolrDataModel.getTransactionDocumentId(info.getId()));
input.addField(FIELD_VERSION, 0);
input.addField(FIELD_TXID, info.getId());
input.addField(FIELD_INTXID, info.getId());
input.addField(FIELD_TXCOMMITTIME, info.getCommitTimeMs());
input.addField(FIELD_DOC_TYPE, DOC_TYPE_TX);
/*
For backwards compat reasons adding 3 new stored fields. 2 of these fields are duplicate data but there are needed so that
we can properly update the transaction record for ACE-4284.
*/
// This fields will be used to update the transaction record
// They will only be on the record until the cascading updates for this transaction are processed
input.addField(FIELD_S_TXID, info.getId());
input.addField(FIELD_S_TXCOMMITTIME, info.getCommitTimeMs());
// Set the cascade flag to 1. This means cascading updates have not been done yet.
input.addField(FIELD_CASCADE_FLAG, 1);
cmd.solrDoc = input;
// System.out.println("############### Adding transaction:"+ input);
processor.processAdd(cmd);
putTransactionState(processor, request, info);
} finally {
if (processor != null) {
processor.finish();
}
if (request != null) {
request.close();
}
}
}
use of org.apache.solr.update.processor.UpdateRequestProcessor in project SearchServices by Alfresco.
the class QueryLoggingComponent method log.
private void log(ResponseBuilder rb) throws IOException {
boolean isShard = rb.req.getParams().getBool(ShardParams.IS_SHARD, false);
if (!isShard) {
CoreContainer container = rb.req.getCore().getCoreContainer();
SolrCore logCore = container.getCore(rb.req.getCore().getName() + "_qlog");
if (logCore != null) {
JSONObject json = (JSONObject) rb.req.getContext().get(AbstractQParser.ALFRESCO_JSON);
SolrQueryRequest request = null;
UpdateRequestProcessor processor = null;
try {
request = new LocalSolrQueryRequest(logCore, new NamedList<>());
processor = logCore.getUpdateProcessingChain(null).createProcessor(request, new SolrQueryResponse());
AddUpdateCommand cmd = new AddUpdateCommand(request);
cmd.overwrite = true;
SolrInputDocument input = new SolrInputDocument();
input.addField("id", GUID.generate());
input.addField("_version_", "1");
input.addField("timestamp", DateTimeFormatter.ISO_INSTANT.format(Instant.now()));
if (json != null) {
try {
ArrayList<String> authorityList = new ArrayList<String>(1);
JSONArray authorities = json.getJSONArray("authorities");
for (int i = 0; i < authorities.length(); i++) {
String authorityString = authorities.getString(i);
authorityList.add(authorityString);
}
for (String authority : authorityList) {
if (AuthorityType.getAuthorityType(authority) == AuthorityType.USER) {
input.addField("user", authority);
break;
}
}
} catch (JSONException e) {
input.addField("user", "<UNKNOWN>");
}
} else {
input.addField("user", "<UNKNOWN>");
}
String userQuery = rb.req.getParams().get(SpellingParams.SPELLCHECK_Q);
if (userQuery == null) {
if (json != null) {
try {
userQuery = json.getString("query");
} catch (JSONException e) {
}
}
}
if (userQuery == null) {
userQuery = rb.req.getParams().get(CommonParams.Q);
}
if (userQuery != null) {
input.addField("user_query", userQuery);
}
Query query = rb.getQuery();
input.addField("query", query.toString());
if (rb.getResults().docList != null) {
input.addField("found", rb.getResults().docList.matches());
}
input.addField("time", rb.req.getRequestTimer().getTime());
cmd.solrDoc = input;
processor.processAdd(cmd);
} finally {
if (processor != null) {
processor.finish();
}
if (request != null) {
request.close();
}
}
}
}
}
use of org.apache.solr.update.processor.UpdateRequestProcessor in project SearchServices by Alfresco.
the class SolrInformationServer method cascadeNodes.
public void cascadeNodes(List<NodeMetaData> nodeMetaDatas, boolean overwrite) throws IOException, AuthenticationException, JSONException {
SolrQueryRequest request = null;
UpdateRequestProcessor processor = null;
try {
request = getLocalSolrQueryRequest();
processor = this.core.getUpdateProcessingChain(null).createProcessor(request, new SolrQueryResponse());
for (NodeMetaData nodeMetaData : nodeMetaDatas) {
if (mayHaveChildren(nodeMetaData)) {
cascadeUpdateV2(nodeMetaData, overwrite, request, processor);
}
}
} catch (Exception e) {
for (NodeMetaData node : nodeMetaDatas) {
// TODO Add a cascadeNode method
}
} finally {
if (processor != null) {
processor.finish();
}
if (request != null) {
request.close();
}
}
}
Aggregations