use of org.alfresco.solr.AlfrescoSolrDataModel.FieldInstance in project SearchServices by Alfresco.
the class SolrInformationServer method getCascadeNodes.
public List<NodeMetaData> getCascadeNodes(List<Long> txnIds) throws AuthenticationException, IOException, JSONException {
List<FieldInstance> list = AlfrescoSolrDataModel.getInstance().getIndexedFieldNamesForProperty(ContentModel.PROP_CASCADE_TX).getFields();
FieldInstance fieldInstance = list.get(0);
RefCounted<SolrIndexSearcher> refCounted = null;
IntArrayList docList = null;
HashSet<Long> childIds = new HashSet();
try {
refCounted = core.getSearcher();
SolrIndexSearcher searcher = refCounted.get();
String field = fieldInstance.getField();
SchemaField schemaField = searcher.getSchema().getField(field);
FieldType fieldType = schemaField.getType();
BooleanQuery.Builder builder = new BooleanQuery.Builder();
BooleanQuery booleanQuery = null;
for (Long l : txnIds) {
BytesRefBuilder bytesRefBuilder = new BytesRefBuilder();
fieldType.readableToIndexed(l.toString(), bytesRefBuilder);
TermQuery termQuery = new TermQuery(new Term(field, bytesRefBuilder.toBytesRef()));
BooleanClause booleanClause = new BooleanClause(termQuery, BooleanClause.Occur.SHOULD);
builder.add(booleanClause);
}
booleanQuery = builder.build();
DocListCollector collector = new DocListCollector();
searcher.search(booleanQuery, collector);
docList = collector.getDocs();
// System.out.println("################ CASCASDE Parent Nodes:"+docList.size());
int size = docList.size();
Set set = new HashSet();
set.add(FIELD_SOLR4_ID);
for (int i = 0; i < size; i++) {
int docId = docList.get(i);
Document document = searcher.doc(docId, set);
IndexableField indexableField = document.getField(FIELD_SOLR4_ID);
String id = indexableField.stringValue();
TenantAclIdDbId ids = AlfrescoSolrDataModel.decodeNodeDocumentId(id);
// System.out.println("################## Cascade Parent:"+ ids.dbId);
childIds.add(ids.dbId);
}
} finally {
refCounted.decref();
}
List<NodeMetaData> allNodeMetaDatas = new ArrayList();
for (Long childId : childIds) {
NodeMetaDataParameters nmdp = new NodeMetaDataParameters();
nmdp.setFromNodeId(childId);
nmdp.setToNodeId(childId);
nmdp.setIncludeAclId(false);
nmdp.setIncludeAspects(false);
nmdp.setIncludeChildAssociations(false);
nmdp.setIncludeChildIds(true);
nmdp.setIncludeNodeRef(false);
nmdp.setIncludeOwner(false);
nmdp.setIncludeParentAssociations(false);
// We only care about the path and ancestors (which is included) for this case
nmdp.setIncludePaths(true);
nmdp.setIncludeProperties(false);
nmdp.setIncludeType(false);
nmdp.setIncludeTxnId(true);
// Gets only one
List<NodeMetaData> nodeMetaDatas = repositoryClient.getNodesMetaData(nmdp, 1);
allNodeMetaDatas.addAll(nodeMetaDatas);
}
return allNodeMetaDatas;
}
use of org.alfresco.solr.AlfrescoSolrDataModel.FieldInstance in project SearchServices by Alfresco.
the class SolrInformationServer method addPropertiesToDoc.
static void addPropertiesToDoc(Map<QName, PropertyValue> properties, boolean isContentIndexedForNode, SolrInputDocument newDoc, SolrInputDocument cachedDoc, boolean transformContentFlag) throws IOException {
for (QName propertyQName : properties.keySet()) {
newDoc.addField(FIELD_PROPERTIES, propertyQName.toString());
newDoc.addField(FIELD_PROPERTIES, propertyQName.getPrefixString());
PropertyValue value = properties.get(propertyQName);
// System.out.println("####### indexing prop:"+propertyQName.toString()+":"+value.toString());
if (value != null) {
if (value instanceof StringPropertyValue) {
for (FieldInstance field : AlfrescoSolrDataModel.getInstance().getIndexedFieldNamesForProperty(propertyQName).getFields()) {
// System.out.println("####### field:"+field.getField()+":"+value.toString());
addStringPropertyToDoc(newDoc, field, (StringPropertyValue) value, properties);
}
} else if (value instanceof MLTextPropertyValue) {
for (FieldInstance field : AlfrescoSolrDataModel.getInstance().getIndexedFieldNamesForProperty(propertyQName).getFields()) {
addMLTextPropertyToDoc(newDoc, field, (MLTextPropertyValue) value);
}
} else if (value instanceof ContentPropertyValue) {
boolean transform = transformContentFlag;
if (!isContentIndexedForNode) {
transform = false;
}
addContentPropertyToDocUsingCache(newDoc, cachedDoc, propertyQName, (ContentPropertyValue) value, transform);
} else if (value instanceof MultiPropertyValue) {
MultiPropertyValue typedValue = (MultiPropertyValue) value;
for (PropertyValue singleValue : typedValue.getValues()) {
if (singleValue instanceof StringPropertyValue) {
for (FieldInstance field : AlfrescoSolrDataModel.getInstance().getIndexedFieldNamesForProperty(propertyQName).getFields()) {
addStringPropertyToDoc(newDoc, field, (StringPropertyValue) singleValue, properties);
}
} else if (singleValue instanceof MLTextPropertyValue) {
for (FieldInstance field : AlfrescoSolrDataModel.getInstance().getIndexedFieldNamesForProperty(propertyQName).getFields()) {
addMLTextPropertyToDoc(newDoc, field, (MLTextPropertyValue) singleValue);
}
} else if (singleValue instanceof ContentPropertyValue) {
boolean transform = transformContentFlag;
if (!isContentIndexedForNode) {
transform = false;
}
addContentPropertyToDocUsingCache(newDoc, cachedDoc, propertyQName, (ContentPropertyValue) singleValue, transform);
}
}
}
} else {
// NULL property
newDoc.addField(FIELD_NULLPROPERTIES, propertyQName.toString());
}
}
}
use of org.alfresco.solr.AlfrescoSolrDataModel.FieldInstance in project SearchServices by Alfresco.
the class SolrInformationServer method addContentPropertyToDocUsingAlfrescoRepository.
private void addContentPropertyToDocUsingAlfrescoRepository(SolrInputDocument doc, QName propertyQName, long dbId, String locale) throws AuthenticationException, IOException, UnsupportedEncodingException {
long start = System.nanoTime();
// Expensive call to be done with ContentTracker
GetTextContentResponse response = repositoryClient.getTextContent(dbId, propertyQName, null);
addContentPropertyMetadata(doc, propertyQName, AlfrescoSolrDataModel.ContentFieldType.TRANSFORMATION_STATUS, response);
addContentPropertyMetadata(doc, propertyQName, AlfrescoSolrDataModel.ContentFieldType.TRANSFORMATION_EXCEPTION, response);
addContentPropertyMetadata(doc, propertyQName, AlfrescoSolrDataModel.ContentFieldType.TRANSFORMATION_TIME, response);
InputStream ris = response.getContent();
String textContent = "";
try {
if (ris != null) {
// Get and copy content
byte[] bytes = FileCopyUtils.copyToByteArray(new BoundedInputStream(ris, contentStreamLimit));
textContent = new String(bytes, "UTF8");
}
} finally {
// release the response only when the content has been read
response.release();
}
if (minHash && textContent.length() > 0) {
Analyzer analyzer = core.getLatestSchema().getFieldType("min_hash").getIndexAnalyzer();
TokenStream ts = analyzer.tokenStream("min_hash", textContent);
CharTermAttribute termAttribute = ts.getAttribute(CharTermAttribute.class);
ts.reset();
while (ts.incrementToken()) {
StringBuilder tokenBuff = new StringBuilder();
char[] buff = termAttribute.buffer();
for (int i = 0; i < termAttribute.length(); i++) {
tokenBuff.append(Integer.toHexString(buff[i]));
}
doc.addField(FINGERPRINT_FIELD, tokenBuff.toString());
}
ts.end();
ts.close();
}
long end = System.nanoTime();
this.getTrackerStats().addDocTransformationTime(end - start);
StringBuilder builder = new StringBuilder(textContent.length() + 16);
builder.append("\u0000").append(locale).append("\u0000");
builder.append(textContent);
String localisedText = builder.toString();
for (FieldInstance field : AlfrescoSolrDataModel.getInstance().getIndexedFieldNamesForProperty(propertyQName).getFields()) {
doc.removeField(field.getField());
if (field.isLocalised()) {
doc.addField(field.getField(), localisedText);
} else {
doc.addField(field.getField(), textContent);
}
addFieldIfNotSet(doc, field);
}
}
use of org.alfresco.solr.AlfrescoSolrDataModel.FieldInstance in project SearchServices by Alfresco.
the class SolrInformationServer method getSolrFieldNameForContentPropertyMetadata.
/**
* Gets the field name used in Solr for the specified content property.
* Assumes that the first defined field in Solr is the "right one".
* @param propertyQName the content property qualified name
* @param type the content property field type, i.e. DOCID
* @return a String representing the name of the field in Solr or null if not found
*/
private static String getSolrFieldNameForContentPropertyMetadata(QName propertyQName, AlfrescoSolrDataModel.ContentFieldType type) {
IndexedField indexedField = AlfrescoSolrDataModel.getInstance().getIndexedFieldForContentPropertyMetadata(propertyQName, type);
List<FieldInstance> fields = indexedField.getFields();
String fieldName = null;
if (fields != null && !fields.isEmpty()) {
FieldInstance instance = fields.get(0);
if (instance != null) {
fieldName = instance.getField();
}
}
return fieldName;
}
use of org.alfresco.solr.AlfrescoSolrDataModel.FieldInstance in project SearchServices by Alfresco.
the class SolrInformationServer method indexNonShardCascade.
private void indexNonShardCascade(NodeMetaData nodeMetaData) throws IOException {
canUpdate();
SolrQueryRequest request = null;
UpdateRequestProcessor processor = null;
try {
request = getLocalSolrQueryRequest();
processor = this.core.getUpdateProcessingChain(null).createProcessor(request, new SolrQueryResponse());
StringPropertyValue stringPropertyValue = (StringPropertyValue) nodeMetaData.getProperties().get(ContentModel.PROP_CASCADE_TX);
List<FieldInstance> fieldInstances = AlfrescoSolrDataModel.getInstance().getIndexedFieldNamesForProperty(ContentModel.PROP_CASCADE_TX).getFields();
FieldInstance fieldInstance = fieldInstances.get(0);
AddUpdateCommand cmd = new AddUpdateCommand(request);
SolrInputDocument input = new SolrInputDocument();
input.addField(FIELD_SOLR4_ID, AlfrescoSolrDataModel.getNodeDocumentId(nodeMetaData.getTenantDomain(), nodeMetaData.getAclId(), nodeMetaData.getId()));
input.addField(FIELD_VERSION, 0);
input.addField(fieldInstance.getField(), stringPropertyValue.toString());
cmd.solrDoc = input;
processor.processAdd(cmd);
} finally {
if (processor != null) {
processor.finish();
}
if (request != null) {
request.close();
}
}
}
Aggregations