Skip to content

Commit

Permalink
Add new db.queryNodeIndex() method.
Browse files Browse the repository at this point in the history
For more complex queries instead of single key-value lookups.
  • Loading branch information
aseemk committed Aug 26, 2011
1 parent 2ac618f commit 9b51794
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/GraphDatabase_.coffee
Expand Up @@ -197,3 +197,25 @@ module.exports = class GraphDatabase

catch error
throw adjustError error

# executes a query against the given node index. lucene syntax reference:
# http://lucene.apache.org/java/3_1_0/queryparsersyntax.html
queryNodeIndex: (index, query, _) ->
try
services = @getServices _
url = "#{services.node_index}/#{index}?query=#{encodeURIComponent query}"

response = request.get url, _

if response.statusCode isnt status.OK
# Database error
throw response.statusCode

# Success
nodeArray = JSON.parse response.body
nodes = nodeArray.map (node) =>
new Node this, node
return nodes

catch error
throw adjustError error

0 comments on commit 9b51794

Please sign in to comment.