use of com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField in project orientdb by orientechnologies.
the class OLuceneTextOperator method fields.
// restituisce una lista di nomi
protected Collection<String> fields(OSQLFilterCondition iCondition) {
Object left = iCondition.getLeft();
if (left instanceof String) {
String fName = (String) left;
return Arrays.asList(fName);
}
if (left instanceof Collection) {
Collection<OSQLFilterItemField> f = (Collection<OSQLFilterItemField>) left;
List<String> fields = new ArrayList<String>();
for (OSQLFilterItemField field : f) {
fields.add(field.toString());
}
return fields;
}
if (left instanceof OSQLFilterItemField) {
OSQLFilterItemField fName = (OSQLFilterItemField) left;
if (fName.isFieldChain()) {
int itemCount = fName.getFieldChain().getItemCount();
return Arrays.asList(fName.getFieldChain().getItemName(itemCount - 1));
} else {
return Arrays.asList(fName.toString());
}
}
return Collections.emptyList();
}
use of com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField in project orientdb by orientechnologies.
the class OLuceneTextOperator method involvedIndex.
protected OLuceneFullTextIndex involvedIndex(OIdentifiable iRecord, ODocument iCurrentResult, OSQLFilterCondition iCondition, Object iLeft, Object iRight) {
ODocument doc = iRecord.getRecord();
OClass cls = getDatabase().getMetadata().getSchema().getClass(doc.getClassName());
if (isChained(iCondition.getLeft())) {
OSQLFilterItemField chained = (OSQLFilterItemField) iCondition.getLeft();
OSQLFilterItemField.FieldChain fieldChain = chained.getFieldChain();
OClass oClass = cls;
for (int i = 0; i < fieldChain.getItemCount() - 1; i++) {
oClass = oClass.getProperty(fieldChain.getItemName(i)).getLinkedClass();
}
if (oClass != null) {
cls = oClass;
}
}
Set<OIndex<?>> classInvolvedIndexes = cls.getInvolvedIndexes(fields(iCondition));
OLuceneFullTextIndex idx = null;
for (OIndex<?> classInvolvedIndex : classInvolvedIndexes) {
if (classInvolvedIndex.getInternal() instanceof OLuceneFullTextIndex) {
idx = (OLuceneFullTextIndex) classInvolvedIndex.getInternal();
break;
}
}
return idx;
}
use of com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField in project orientdb by orientechnologies.
the class OFilterAnalyzer method createIndexedProperty.
/**
* Add SQL filter field to the search candidate list.
*
* @param iCondition Condition item
* @param iItem Value to search
* @return true if the property was indexed and found, otherwise false
*/
private OIndexSearchResult createIndexedProperty(final OSQLFilterCondition iCondition, final Object iItem) {
if (iItem == null || !(iItem instanceof OSQLFilterItemField)) {
return null;
}
if (iCondition.getLeft() instanceof OSQLFilterItemField && iCondition.getRight() instanceof OSQLFilterItemField) {
return null;
}
final OSQLFilterItemField item = (OSQLFilterItemField) iItem;
if (item.hasChainOperators() && !item.isFieldChain()) {
return null;
}
final Object origValue = iCondition.getLeft() == iItem ? iCondition.getRight() : iCondition.getLeft();
OQueryOperator operator = iCondition.getOperator();
if (iCondition.getRight() == iItem) {
if (operator instanceof OQueryOperatorIn) {
operator = new OQueryOperatorContains();
} else if (operator instanceof OQueryOperatorContains) {
operator = new OQueryOperatorIn();
}
}
if (iCondition.getOperator() instanceof OQueryOperatorBetween || operator instanceof OQueryOperatorIn) {
return new OIndexSearchResult(operator, item.getFieldChain(), origValue);
}
final Object value = OSQLHelper.getValue(origValue);
return new OIndexSearchResult(operator, item.getFieldChain(), value);
}
use of com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField in project orientdb by orientechnologies.
the class OLuceneOperatorUtil method createIndexedProperty.
public static OIndexSearchResult createIndexedProperty(final OSQLFilterCondition iCondition, final Object iItem) {
if (iItem == null || !(iItem instanceof OSQLFilterItemField))
return null;
if (iCondition.getLeft() instanceof OSQLFilterItemField && iCondition.getRight() instanceof OSQLFilterItemField)
return null;
final OSQLFilterItemField item = (OSQLFilterItemField) iItem;
if (item.hasChainOperators() && !item.isFieldChain())
return null;
final Object origValue = iCondition.getLeft() == iItem ? iCondition.getRight() : iCondition.getLeft();
if (iCondition.getOperator() instanceof OQueryOperatorBetween || iCondition.getOperator() instanceof OQueryOperatorIn) {
return new OIndexSearchResult(iCondition.getOperator(), item.getFieldChain(), origValue);
}
final Object value = OSQLHelper.getValue(origValue);
if (value == null)
return null;
return new OIndexSearchResult(iCondition.getOperator(), item.getFieldChain(), value);
}
use of com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField in project orientdb by orientechnologies.
the class ORuntimeResult method applyRecord.
@SuppressWarnings("unchecked")
public static ODocument applyRecord(final ODocument iValue, final Map<String, Object> iProjections, final OCommandContext iContext, final OIdentifiable iRecord) {
// APPLY PROJECTIONS
ORecord record = (iRecord != null ? iRecord.getRecord() : null);
// MANAGE SPECIFIC CASES FOR RECORD BYTES
if (ORecordBytes.RECORD_TYPE == ORecordInternal.getRecordType(record)) {
for (Entry<String, Object> projection : iProjections.entrySet()) {
if ("@rid".equalsIgnoreCase("" + projection.getValue())) {
iValue.field(projection.getKey(), record.getIdentity());
} else if ("@size".equalsIgnoreCase("" + projection.getValue())) {
iValue.field(projection.getKey(), record.getSize());
} else if ("@version".equalsIgnoreCase("" + projection.getValue())) {
iValue.field(projection.getKey(), record.getVersion());
} else {
Object val = projection.getValue();
if (val instanceof Number || val instanceof String || val instanceof Boolean) {
iValue.field(projection.getKey(), val);
} else {
iValue.field(projection.getKey(), (Object) null);
}
}
}
return iValue;
}
final ODocument inputDocument = (ODocument) record;
if (iProjections.isEmpty())
// SELECT * CASE
inputDocument.copyTo(iValue);
else {
for (Entry<String, Object> projection : iProjections.entrySet()) {
final String prjName = projection.getKey();
final Object v = projection.getValue();
if (v == null && prjName != null) {
iValue.field(prjName, (Object) null);
continue;
}
final Object projectionValue;
if (v != null && v.equals("*")) {
// COPY ALL
inputDocument.copyTo(iValue);
// CONTINUE WITH NEXT ITEM
continue;
} else if (v instanceof OSQLFilterItemVariable || v instanceof OSQLFilterItemField) {
final OSQLFilterItemAbstract var = (OSQLFilterItemAbstract) v;
final OPair<OSQLMethodRuntime, Object[]> last = var.getLastChainOperator();
if (last != null && last.getKey().getMethod() instanceof OSQLMethodField && last.getValue() != null && last.getValue().length == 1 && last.getValue()[0].equals("*")) {
final Object value = ((OSQLFilterItemAbstract) v).getValue(inputDocument, iValue, iContext);
if (inputDocument != null && value != null && inputDocument instanceof ODocument && value instanceof ODocument) {
// COPY FIELDS WITH PROJECTION NAME AS PREFIX
for (String fieldName : ((ODocument) value).fieldNames()) {
iValue.field(prjName + fieldName, ((ODocument) value).field(fieldName));
}
}
projectionValue = null;
} else
// RETURN A VARIABLE FROM THE CONTEXT
projectionValue = ((OSQLFilterItemAbstract) v).getValue(inputDocument, iValue, iContext);
} else if (v instanceof OSQLFunctionRuntime) {
final OSQLFunctionRuntime f = (OSQLFunctionRuntime) v;
projectionValue = f.execute(inputDocument, inputDocument, iValue, iContext);
} else {
if (v == null) {
// SIMPLE NULL VALUE: SET IT IN DOCUMENT
iValue.field(prjName, v);
continue;
}
projectionValue = v;
}
if (projectionValue != null)
if (projectionValue instanceof ORidBag)
iValue.field(prjName, new ORidBag((ORidBag) projectionValue));
else if (projectionValue instanceof OIdentifiable && !(projectionValue instanceof ORID) && !(projectionValue instanceof ORecord))
iValue.field(prjName, ((OIdentifiable) projectionValue).getRecord());
else if (projectionValue instanceof Iterator) {
boolean link = true;
// make temporary value typical case graph database elemenet's iterator edges
if (projectionValue instanceof OResettable)
((OResettable) projectionValue).reset();
final List<Object> iteratorValues = new ArrayList<Object>();
final Iterator projectionValueIterator = (Iterator) projectionValue;
while (projectionValueIterator.hasNext()) {
Object value = projectionValueIterator.next();
if (value instanceof OIdentifiable) {
value = ((OIdentifiable) value).getRecord();
if (value != null && !((OIdentifiable) value).getIdentity().isPersistent())
link = false;
}
if (value != null)
iteratorValues.add(value);
}
iValue.field(prjName, iteratorValues, link ? OType.LINKLIST : OType.EMBEDDEDLIST);
} else if (projectionValue instanceof ODocument && ((ODocument) projectionValue).getIdentity().getClusterId() < 0) {
iValue.field(prjName, projectionValue, OType.EMBEDDED);
} else if (projectionValue instanceof Set<?>) {
OType type = OType.getTypeByValue(projectionValue);
if (type == OType.LINKSET && !entriesPersistent((Collection<OIdentifiable>) projectionValue))
type = OType.EMBEDDEDSET;
iValue.field(prjName, projectionValue, type);
} else if (projectionValue instanceof Map<?, ?>) {
OType type = OType.getTypeByValue(projectionValue);
if (type == OType.LINKMAP && !entriesPersistent(((Map<?, OIdentifiable>) projectionValue).values()))
type = OType.EMBEDDEDMAP;
iValue.field(prjName, projectionValue, type);
} else if (projectionValue instanceof List<?>) {
OType type = OType.getTypeByValue(projectionValue);
if (type == OType.LINKLIST && !entriesPersistent((Collection<OIdentifiable>) projectionValue))
type = OType.EMBEDDEDLIST;
iValue.field(prjName, projectionValue, type);
} else
iValue.field(prjName, projectionValue);
}
}
return iValue;
}
Aggregations