Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions js/Cypher.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ function CypherJS() {
initializeNodeIdLookup(key, value);
nodeIdLookup[key][value].push(nodeId);
};
var removeLookupNodeId = function(_key, _value, nodeId) {
var key = recode(_key),
value = recode(_value);
if(nodeIdLookup[key] && nodeIdLookup[key][value]) {
var index = nodeIdLookup[key][value].indexOf(nodeId);
if(index !== -1) {
nodeIdLookup[key][value].splice(index, 1);
}
}
};
var addLookupRelationshipId = function(_key, _value, relationshipId) {
var key = recode(_key),
value = recode(_value);
Expand Down Expand Up @@ -519,8 +529,23 @@ function CypherJS() {
key,
node.getLocalProperty(key)
);
if(nodeIds) {
if(nodeIds && nodeIds.length > 0) {
matcher.setMatchingSet(nodeIds);
} else {
// If no nodes found in index, search all nodes directly
var matchingNodeIds = [];
for (var nodeId in nodes) {
var nodeObj = nodes[nodeId];
if (nodeObj && nodeObj.getLocalProperty(key) === node.getLocalProperty(key)) {
matchingNodeIds.push(parseInt(nodeId));

// Also update the index for future queries
addLookupNodeId(key, node.getLocalProperty(key), parseInt(nodeId));
}
}
if (matchingNodeIds.length > 0) {
matcher.setMatchingSet(matchingNodeIds);
}
}

// There are matching node ids that match given patterns so far
Expand Down Expand Up @@ -862,6 +887,18 @@ function CypherJS() {
return relationships[id];
};

this.updateNodePropertyIndex = function(propertyKey, oldValue, newValue, nodeId) {
// Remove the node ID from the old value in the lookup
if (oldValue !== null && oldValue !== undefined) {
removeLookupNodeId(propertyKey, oldValue, nodeId);
}

// Add the node ID to the lookup with the new value
if (newValue !== null && newValue !== undefined) {
addLookupNodeId(propertyKey, newValue, nodeId);
}
};

this.addNode = function(node) {
var n = new Node(this);
n.setProperties(node.properties);
Expand Down Expand Up @@ -971,13 +1008,25 @@ function CypherJS() {
};
this.getId = this.id;
this.setProperty = function(key, expression) {
// Store the old value before updating
var oldValue = properties[key];

properties[key] = null;
propertyExpressions[key] = expression.value;

// Return the old value for index updating
return oldValue;
};
this.setProperties = function(_properties) {
// Store old values for index updating
var oldValues = {};

for(var key in _properties) {
oldValues[key] = properties[key];
properties[key] = _properties[key];
}

return oldValues;
};
this.bindProperty = function(key) {
properties[key] = propertyExpressions[key]();
Expand Down Expand Up @@ -2835,10 +2884,13 @@ function CypherJS() {
throw "Cannot assign to object of type \"" + o.constructor.name + "\".";
}
try {
assignee.setProperty(
// setProperty now returns the old value
var oldValue = assignee.setProperty(
propertyKey,
expression
);

// Bind the property to evaluate the expression
assignee.bindProperty(propertyKey);
} catch(e) {
;
Expand All @@ -2864,6 +2916,8 @@ function CypherJS() {
} else {
throw "Cannot assign to object of type \"" + o.constructor.name + "\".";
}

// setProperties now returns the old values
assignee.setProperties(
mapExpression.value()
);
Expand Down