Skip to content

Commit

Permalink
Merge pull request #133 from continuum/extra-config-for-create-node-i…
Browse files Browse the repository at this point in the history
…ndex

Allow to pass extra configuration options when creating indexes
  • Loading branch information
maxdemarzi committed Dec 27, 2013
2 parents 9556d55 + b074c38 commit 16e2f38
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ def list_node_indexes
end
alias_method :list_indexes, :list_node_indexes

def create_node_index(name, type = "exact", provider = "lucene")
@node_indexes.create(name, type, provider)
def create_node_index(name, type = "exact", provider = "lucene", extra_config = nil)
@node_indexes.create(name, type, provider, extra_config)
end

def create_node_auto_index(type = "exact", provider = "lucene")
Expand Down
12 changes: 7 additions & 5 deletions lib/neography/rest/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ def create_node(body)

# NodeIndexes

def create_node_index(name, type = "exact", provider = "lucene")
def create_node_index(name, type = "exact", provider = "lucene", extra_config = nil)
config = {
:type => type,
:provider => provider
}
config.merge!(extra_config) unless extra_config.nil?
post NodeIndexes.all_path do
{ :name => name,
:config => {
:type => type,
:provider => provider
}
:config => config
}
end
end
Expand Down
12 changes: 7 additions & 5 deletions lib/neography/rest/indexes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ def list
@connection.get(all_path)
end

def create(name, type = "exact", provider = "lucene")
def create(name, type = "exact", provider = "lucene", extra_config = nil)
config = {
:type => type,
:provider => provider
}
config.merge!(extra_config) unless extra_config.nil?
options = {
:body => (
{ :name => name,
:config => {
:type => type,
:provider => provider
}
:config => config
}
).to_json,
:headers => json_content_type
Expand Down
10 changes: 10 additions & 0 deletions spec/integration/rest_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@
new_index["type"].should == "fulltext"
end

it "can create a node index with extra configuration options" do
name = generate_text(6)
new_index = @neo.create_node_index(name, "fulltext","lucene", extra: 'extra-value')
new_index.should_not be_nil
new_index["template"].should == "#{@neo.configuration}/index/node/#{name}/{key}/{value}"
new_index["provider"].should == "lucene"
new_index["extra"].should == "extra-value"
new_index["type"].should == "fulltext"
end

it "can create a relationship index" do
name = generate_text(6)
new_index = @neo.create_relationship_index(name)
Expand Down

0 comments on commit 16e2f38

Please sign in to comment.