From cf2486ef655907a744c0fa7a7d131d9333797246 Mon Sep 17 00:00:00 2001 From: Radu Kopetz Date: Wed, 30 Apr 2014 16:00:17 +0200 Subject: [PATCH] encode query when sending to auto_index --- lib/neography/rest/node_auto_indexes.rb | 2 +- spec/integration/rest_index_spec.rb | 5 ++++- spec/unit/rest/node_auto_indexes_spec.rb | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/neography/rest/node_auto_indexes.rb b/lib/neography/rest/node_auto_indexes.rb index ae7ec85..6eb63db 100644 --- a/lib/neography/rest/node_auto_indexes.rb +++ b/lib/neography/rest/node_auto_indexes.rb @@ -23,7 +23,7 @@ def find_node_auto_index_by_value(key, value) end def query_node_auto_index(query_expression) - @connection.get("/index/auto/node/?query=%{query}" % {:query => query_expression}) || [] + @connection.get("/index/auto/node/?query=%{query}" % {:query => encode(query_expression)}) || [] end def get_node_auto_index_status diff --git a/spec/integration/rest_index_spec.rb b/spec/integration/rest_index_spec.rb index 519d468..0da8de3 100644 --- a/spec/integration/rest_index_spec.rb +++ b/spec/integration/rest_index_spec.rb @@ -420,7 +420,10 @@ it "can query a node from an automatic index" do new_node = @neo.create_node("name" => "Max") existing_nodes = @neo.find_node_auto_index("name:Max") - existing_nodes.collect{|n| n["self"]}.include?(new_node["self"]).should be_true + existing_nodes.collect{|n| n["self"]}.include?(new_node["self"]).should be_true + # check that more complex queries are correctly handled + existing_nodes = @neo.find_node_auto_index("name:Max OR name:Max") + existing_nodes.collect{|n| n["self"]}.include?(new_node["self"]).should be_true end it "can get a relationship from an automatic index" do diff --git a/spec/unit/rest/node_auto_indexes_spec.rb b/spec/unit/rest/node_auto_indexes_spec.rb index 8a5f8fa..be73a53 100644 --- a/spec/unit/rest/node_auto_indexes_spec.rb +++ b/spec/unit/rest/node_auto_indexes_spec.rb @@ -24,6 +24,10 @@ class Rest it "finds by query if no value passed to #find_or_query" do subject.connection.should_receive(:get).with("/index/auto/node/?query=some_query") subject.find_node_auto_index("some_query") + + query = "some_query AND another_one" + subject.connection.should_receive(:get).with("/index/auto/node/?query=#{URI.encode(query)}") + subject.find_node_auto_index(query) end it "finds by key and value" do