use of org.alfresco.solr.AlfrescoSolrDataModel.FieldInstance in project SearchServices by Alfresco.
the class SolrInformationServer method addContentPropertyToDocUsingCache.
private static void addContentPropertyToDocUsingCache(SolrInputDocument newDoc, SolrInputDocument cachedDoc, QName propertyQName, ContentPropertyValue contentPropertyValue, boolean transformContentFlag) throws IOException {
addContentPropertyMetadata(newDoc, propertyQName, contentPropertyValue, AlfrescoSolrDataModel.ContentFieldType.DOCID);
addContentPropertyMetadata(newDoc, propertyQName, contentPropertyValue, AlfrescoSolrDataModel.ContentFieldType.SIZE);
addContentPropertyMetadata(newDoc, propertyQName, contentPropertyValue, AlfrescoSolrDataModel.ContentFieldType.LOCALE);
addContentPropertyMetadata(newDoc, propertyQName, contentPropertyValue, AlfrescoSolrDataModel.ContentFieldType.MIMETYPE);
addContentPropertyMetadata(newDoc, propertyQName, contentPropertyValue, AlfrescoSolrDataModel.ContentFieldType.ENCODING);
if (false == transformContentFlag) {
// Marks it as Clean so we do not get the actual content
markFTSStatus(newDoc, FTSStatus.Clean);
return;
}
if (cachedDoc != null) {
// Builds up the new solr doc from the cached content regardless of whether or not it is current
List<FieldInstance> fields = AlfrescoSolrDataModel.getInstance().getIndexedFieldNamesForProperty(propertyQName).getFields();
for (FieldInstance field : fields) {
String fieldName = field.getField();
Object cachedFieldValue = cachedDoc.getFieldValue(fieldName);
newDoc.addField(fieldName, cachedFieldValue);
addFieldIfNotSet(newDoc, field);
}
String transformationStatusFieldName = getSolrFieldNameForContentPropertyMetadata(propertyQName, AlfrescoSolrDataModel.ContentFieldType.TRANSFORMATION_STATUS);
newDoc.addField(transformationStatusFieldName, cachedDoc.getFieldValue(transformationStatusFieldName));
String transformationExceptionFieldName = getSolrFieldNameForContentPropertyMetadata(propertyQName, AlfrescoSolrDataModel.ContentFieldType.TRANSFORMATION_EXCEPTION);
newDoc.addField(transformationExceptionFieldName, cachedDoc.getFieldValue(transformationExceptionFieldName));
String transformationTimeFieldName = getSolrFieldNameForContentPropertyMetadata(propertyQName, AlfrescoSolrDataModel.ContentFieldType.TRANSFORMATION_TIME);
newDoc.addField(transformationTimeFieldName, cachedDoc.getFieldValue(transformationTimeFieldName));
// Gets the new content docid and compares to that of the cachedDoc to mark the content as clean/dirty
String fldName = getSolrFieldNameForContentPropertyMetadata(propertyQName, AlfrescoSolrDataModel.ContentFieldType.DOCID);
if (newDoc.getFieldValue(FIELD_FTSSTATUS) == null) {
newDoc.addField(FIELD_FTSSTATUS, cachedDoc.getFieldValue(FIELD_FTSSTATUS));
}
if (cachedDoc.getFieldValue(fldName) != null) {
long cachedDocContentDocid = Long.valueOf(String.valueOf(cachedDoc.getFieldValue(fldName)));
long currentContentDocid = contentPropertyValue.getId();
if (cachedDocContentDocid != currentContentDocid) {
// The cached content is out of date
markFTSStatus(newDoc, FTSStatus.Dirty);
}
} else {
markFTSStatus(newDoc, FTSStatus.Dirty);
}
} else {
// There is not a SolrInputDocument in the solrContentStore, so no content is added now to the new solr doc
markFTSStatus(newDoc, FTSStatus.New);
}
}
use of org.alfresco.solr.AlfrescoSolrDataModel.FieldInstance in project SearchServices by Alfresco.
the class Solr4QueryParser method addMLTextOrTextSpanQuery.
private void addMLTextOrTextSpanQuery(String afield, PropertyDefinition pDef, String first, String last, int slop, boolean inOrder, String expandedFieldName, IndexTokenisationMode tokenisationMode, Builder booleanQuery, Locale locale) {
try {
if (locale.toString().length() == 0) {
IndexedField indexedField = AlfrescoSolrDataModel.getInstance().getQueryableFields(pDef.getName(), null, FieldUse.FTS);
for (FieldInstance field : indexedField.getFields()) {
if (!field.isLocalised()) {
SpanQuery firstQuery = buildSpanOrQuery(first, field);
SpanQuery lastQuery = buildSpanOrQuery(last, field);
SpanNearQuery result = new SpanNearQuery(new SpanQuery[] { firstQuery, lastQuery }, slop, inOrder);
booleanQuery.add(result, Occur.SHOULD);
}
}
} else {
IndexedField indexedField = AlfrescoSolrDataModel.getInstance().getQueryableFields(pDef.getName(), null, FieldUse.FTS);
for (FieldInstance field : indexedField.getFields()) {
if (field.isLocalised()) {
SpanQuery firstQuery = buildSpanOrQuery(getLocalePrefixedText(first, locale), field);
SpanQuery lastQuery = buildSpanOrQuery(getLocalePrefixedText(last, locale), field);
SpanNearQuery result = new SpanNearQuery(new SpanQuery[] { firstQuery, lastQuery }, slop, inOrder);
booleanQuery.add(result, Occur.SHOULD);
}
}
}
} catch (IOException ioe) {
}
}
use of org.alfresco.solr.AlfrescoSolrDataModel.FieldInstance in project SearchServices by Alfresco.
the class Solr4QueryParser method addContentSpanQuery.
protected org.apache.lucene.search.Query addContentSpanQuery(String afield, PropertyDefinition pDef, String first, String last, int slop, boolean inOrder, String expandedFieldName, List<Locale> expandedLocales) {
try {
BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
for (Locale locale : expandedLocales) {
if (locale.toString().length() == 0) {
IndexedField indexedField = AlfrescoSolrDataModel.getInstance().getQueryableFields(pDef.getName(), null, FieldUse.FTS);
for (FieldInstance field : indexedField.getFields()) {
if (!field.isLocalised()) {
SpanQuery firstQuery = buildSpanOrQuery(first, field);
SpanQuery lastQuery = buildSpanOrQuery(last, field);
SpanNearQuery result = new SpanNearQuery(new SpanQuery[] { firstQuery, lastQuery }, slop, inOrder);
booleanQuery.add(result, Occur.SHOULD);
}
}
} else {
IndexedField indexedField = AlfrescoSolrDataModel.getInstance().getQueryableFields(pDef.getName(), null, FieldUse.FTS);
for (FieldInstance field : indexedField.getFields()) {
if (field.isLocalised()) {
SpanQuery firstQuery = buildSpanOrQuery(getLocalePrefixedText(first, locale), field);
SpanQuery lastQuery = buildSpanOrQuery(getLocalePrefixedText(last, locale), field);
SpanNearQuery result = new SpanNearQuery(new SpanQuery[] { firstQuery, lastQuery }, slop, inOrder);
booleanQuery.add(result, Occur.SHOULD);
}
}
}
}
return getNonEmptyBooleanQuery(booleanQuery.build());
} catch (IOException ioe) {
return createNoMatchQuery();
}
}
use of org.alfresco.solr.AlfrescoSolrDataModel.FieldInstance in project SearchServices by Alfresco.
the class Solr4QueryParser method getRangeQuery.
/**
* @param field
* @param part1
* @param part2
* @param includeLower
* @param includeUpper
* @param analysisMode
* @param luceneFunction
* @return the query
* @exception ParseException
* throw in overridden method to disallow
*/
public Query getRangeQuery(String field, String part1, String part2, boolean includeLower, boolean includeUpper, AnalysisMode analysisMode, LuceneFunction luceneFunction) throws ParseException {
if (field.equals(FIELD_PATH)) {
throw new UnsupportedOperationException("Range Queries are not support for " + FIELD_PATH);
} else if (field.equals(FIELD_PATHWITHREPEATS)) {
throw new UnsupportedOperationException("Range Queries are not support for " + FIELD_PATHWITHREPEATS);
} else if (field.equals(FIELD_TEXT)) {
Set<String> text = searchParameters.getTextAttributes();
if ((text == null) || (text.size() == 0)) {
Query query = getRangeQuery(PROPERTY_FIELD_PREFIX + ContentModel.PROP_CONTENT.toString(), part1, part2, includeLower, includeUpper, analysisMode, luceneFunction);
if (query == null) {
return createNoMatchQuery();
}
return query;
} else {
BooleanQuery.Builder query = new BooleanQuery.Builder();
for (String fieldName : text) {
Query part = getRangeQuery(fieldName, part1, part2, includeLower, includeUpper, analysisMode, luceneFunction);
if (part != null) {
query.add(part, Occur.SHOULD);
} else {
query.add(createNoMatchQuery(), Occur.SHOULD);
}
}
return query.build();
}
} else if (field.equals(FIELD_CASCADETX)) {
SchemaField sf = schema.getField(FIELD_CASCADETX);
if (sf != null) {
String start = null;
try {
analyzeMultitermTerm(FIELD_CASCADETX, part1);
start = part1;
} catch (Exception e) {
}
String end = null;
try {
analyzeMultitermTerm(FIELD_CASCADETX, part2);
end = part2;
} catch (Exception e) {
}
return sf.getType().getRangeQuery(null, sf, start, end, includeLower, includeUpper);
} else {
throw new UnsupportedOperationException();
}
}
// FIELD_TYPE uses the default
if (isPropertyField(field)) {
Pair<String, String> fieldNameAndEnding = QueryParserUtils.extractFieldNameAndEnding(field);
String expandedFieldName = null;
PropertyDefinition propertyDef = QueryParserUtils.matchPropertyDefinition(searchParameters.getNamespace(), namespacePrefixResolver, dictionaryService, fieldNameAndEnding.getFirst());
IndexTokenisationMode tokenisationMode = IndexTokenisationMode.TRUE;
if (propertyDef != null) {
tokenisationMode = propertyDef.getIndexTokenisationMode();
if (tokenisationMode == null) {
tokenisationMode = IndexTokenisationMode.TRUE;
}
} else {
expandedFieldName = expandAttributeFieldName(field);
}
if (propertyDef != null) {
// LOWER AND UPPER
if (luceneFunction != LuceneFunction.FIELD) {
if (luceneFunction == LuceneFunction.LOWER) {
if ((false == part1.toLowerCase().equals(part1)) || (false == part2.toLowerCase().equals(part2))) {
return createNoMatchQuery();
}
}
if (luceneFunction == LuceneFunction.UPPER) {
if ((false == part1.toUpperCase().equals(part1)) || (false == part2.toUpperCase().equals(part2))) {
return createNoMatchQuery();
}
}
if (propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT)) {
BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
List<Locale> locales = searchParameters.getLocales();
List<Locale> expandedLocales = new ArrayList<Locale>();
for (Locale locale : (((locales == null) || (locales.size() == 0)) ? Collections.singletonList(I18NUtil.getLocale()) : locales)) {
expandedLocales.addAll(MLAnalysisMode.getLocales(mlAnalysisMode, locale, false));
}
for (Locale locale : (((expandedLocales == null) || (expandedLocales.size() == 0)) ? Collections.singletonList(I18NUtil.getLocale()) : expandedLocales)) {
addLocaleSpecificUntokenisedTextRangeFunction(expandedFieldName, propertyDef, part1, part2, includeLower, includeUpper, luceneFunction, booleanQuery, locale, tokenisationMode);
}
return booleanQuery.build();
} else {
throw new UnsupportedOperationException("Lucene Function");
}
}
if (propertyDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT)) {
return buildTextMLTextOrContentRange(field, part1, part2, includeLower, includeUpper, analysisMode, expandedFieldName, propertyDef, tokenisationMode);
} else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.CONTENT)) {
String solrField = null;
switch(fieldNameAndEnding.getSecond()) {
case FIELD_SIZE_SUFFIX:
solrField = AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyDef.getName(), ContentFieldType.SIZE, FieldUse.ID).getFields().get(0).getField();
break;
case FIELD_MIMETYPE_SUFFIX:
solrField = AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyDef.getName(), ContentFieldType.MIMETYPE, FieldUse.ID).getFields().get(0).getField();
break;
case FIELD_ENCODING_SUFFIX:
solrField = AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyDef.getName(), ContentFieldType.ENCODING, FieldUse.ID).getFields().get(0).getField();
break;
case FIELD_LOCALE_SUFFIX:
solrField = AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyDef.getName(), ContentFieldType.LOCALE, FieldUse.ID).getFields().get(0).getField();
break;
}
if (solrField != null) {
String start = null;
try {
analyzeMultitermTerm(solrField, part1);
start = part1;
} catch (Exception e) {
}
String end = null;
try {
analyzeMultitermTerm(solrField, part2);
end = part2;
} catch (Exception e) {
}
SchemaField sf = schema.getField(solrField);
return sf.getType().getRangeQuery(null, sf, start, end, includeLower, includeUpper);
} else {
return buildTextMLTextOrContentRange(field, part1, part2, includeLower, includeUpper, analysisMode, expandedFieldName, propertyDef, tokenisationMode);
}
} else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.TEXT)) {
return buildTextMLTextOrContentRange(field, part1, part2, includeLower, includeUpper, analysisMode, expandedFieldName, propertyDef, tokenisationMode);
} else if (propertyDef.getDataType().getName().equals(DataTypeDefinition.DATETIME) || propertyDef.getDataType().getName().equals(DataTypeDefinition.DATE)) {
Pair<Date, Integer> dateAndResolution1 = parseDateString(part1);
Pair<Date, Integer> dateAndResolution2 = parseDateString(part2);
BooleanQuery.Builder bQuery = new BooleanQuery.Builder();
IndexedField indexedField = AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyDef.getName(), null, FieldUse.ID);
for (FieldInstance instance : indexedField.getFields()) {
String start = dateAndResolution1 == null ? part1 : (includeLower ? getDateStart(dateAndResolution1) : getDateEnd(dateAndResolution1));
String end = dateAndResolution2 == null ? part2 : (includeUpper ? getDateEnd(dateAndResolution2) : getDateStart(dateAndResolution2));
if (start.equals("*")) {
start = null;
}
if (end.equals("*")) {
end = null;
}
SchemaField sf = schema.getField(instance.getField());
Query query = sf.getType().getRangeQuery(null, sf, start, end, includeLower, includeUpper);
if (query != null) {
bQuery.add(query, Occur.SHOULD);
}
}
return bQuery.build();
} else {
String solrField = AlfrescoSolrDataModel.getInstance().getQueryableFields(propertyDef.getName(), null, FieldUse.ID).getFields().get(0).getField();
String start = null;
try {
analyzeMultitermTerm(solrField, part1);
start = part1;
} catch (Exception e) {
}
String end = null;
try {
analyzeMultitermTerm(solrField, part2);
end = part2;
} catch (Exception e) {
}
SchemaField sf = schema.getField(solrField);
return sf.getType().getRangeQuery(null, sf, start, end, includeLower, includeUpper);
}
} else {
throw new UnsupportedOperationException();
}
} else if (field.equals(FIELD_ALL)) {
Set<String> all = searchParameters.getAllAttributes();
if ((all == null) || (all.size() == 0)) {
Collection<QName> contentAttributes = dictionaryService.getAllProperties(null);
BooleanQuery.Builder query = new BooleanQuery.Builder();
for (QName qname : contentAttributes) {
Query part = getRangeQuery(PROPERTY_FIELD_PREFIX + qname.toString(), part1, part2, includeLower, includeUpper, analysisMode, luceneFunction);
query.add(part, Occur.SHOULD);
}
return query.build();
} else {
BooleanQuery.Builder query = new BooleanQuery.Builder();
for (String fieldName : all) {
Query part = getRangeQuery(fieldName, part1, part2, includeLower, includeUpper, analysisMode, luceneFunction);
query.add(part, Occur.SHOULD);
}
return query.build();
}
} else // FIELD_EXISTS uses the default
if (QueryParserUtils.matchDataTypeDefinition(searchParameters.getNamespace(), namespacePrefixResolver, dictionaryService, field) != null) {
Collection<QName> contentAttributes = dictionaryService.getAllProperties(QueryParserUtils.matchDataTypeDefinition(searchParameters.getNamespace(), namespacePrefixResolver, dictionaryService, field).getName());
BooleanQuery.Builder query = new BooleanQuery.Builder();
for (QName qname : contentAttributes) {
Query part = getRangeQuery(PROPERTY_FIELD_PREFIX + qname.toString(), part1, part2, includeLower, includeUpper, analysisMode, luceneFunction);
query.add(part, Occur.SHOULD);
}
return query.build();
}
// FIELD_FTSSTATUS uses the default
if (field.equals(FIELD_TAG)) {
throw new UnsupportedOperationException("Range Queries are not support for " + FIELD_TAG);
} else {
// None property - leave alone
throw new UnsupportedOperationException();
}
}
use of org.alfresco.solr.AlfrescoSolrDataModel.FieldInstance in project SearchServices by Alfresco.
the class Solr4QueryParser method addLocaleSpecificMLOrTextAttribute.
private void addLocaleSpecificMLOrTextAttribute(PropertyDefinition pDef, String queryText, SubQuery subQueryBuilder, AnalysisMode analysisMode, LuceneFunction luceneFunction, Builder booleanQuery, Locale locale, String textFieldName, IndexTokenisationMode tokenisationMode, IndexTokenisationMode preferredTokenisationMode) throws ParseException {
FieldInstance fieldInstance = getFieldInstance(textFieldName, pDef, locale, preferredTokenisationMode);
StringBuilder builder = new StringBuilder(queryText.length() + 10);
if (fieldInstance.isLocalised()) {
builder.append("\u0000").append(locale.toString()).append("\u0000");
}
builder.append(queryText);
Query subQuery = subQueryBuilder.getQuery(fieldInstance.getField(), builder.toString(), analysisMode, luceneFunction);
if (subQuery != null) {
booleanQuery.add(subQuery, Occur.SHOULD);
}
}
Aggregations