Skip to content
Snippets Groups Projects
Commit 8f574935 authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna
Browse files

Changed add_index method to accept multiple properties

parent 01733f94
No related branches found
No related tags found
No related merge requests found
...@@ -77,7 +77,7 @@ module OrientDb ...@@ -77,7 +77,7 @@ module OrientDb
SELECT EXPAND(rid) SELECT EXPAND(rid)
FROM index:learningobject_search FROM index:learningobject_search
WHERE key LUCENE '#{qry}' WHERE key LUCENE '#{qry}'
", limit: -1 ", limit: 10000
build_objects(learning_objects_hash) || [] build_objects(learning_objects_hash) || []
end end
......
...@@ -35,19 +35,33 @@ module OrientDb ...@@ -35,19 +35,33 @@ module OrientDb
end end
end end
def add_index(klass, property, type, engine=nil, metadata=nil) def add_index(klass, properties, type, name=nil, engine=nil, metadata=nil)
engine = engine.nil? ? "" : " ENGINE #{engine}" engine = engine.nil? ? "" : " ENGINE #{engine}"
metadata = metadata.nil? ? "" : " METADATA #{metadata.to_s}" metadata = metadata.nil? ? "" : " METADATA #{metadata.to_s}"
props = stringify(properties,", ")
name = name.nil? ? "#{klass}."+stringify(properties,"_") : name;
begin begin
@client.command "CREATE INDEX #{klass}.#{property} ON #{klass} (#{property}) #{type}#{engine}#{metadata}" index = "CREATE INDEX #{name} ON #{klass} (#{props}) #{type}#{engine}#{metadata}"
@client.command index
rescue Orientdb4r::ServerError => e rescue Orientdb4r::ServerError => e
# If the index already exists OrientDB will give an error containing this message # If the index already exists OrientDB will give an error containing this message
unless e.message.include? "Index with name #{klass.downcase}.#{property.downcase}" unless e.message.include? "Index with name #{name.downcase}"
puts "Error at index creation" puts "Error at index creation"
p e.message p e.message
p.backtrace p e.backtrace
end end
end end
end end
private
def stringify(array, separator)
str = ""
array.each do |value|
str += value.to_s+separator
end
str[0..-(separator.size+1)]
end
end end
end end
\ No newline at end of file
...@@ -5,9 +5,9 @@ class OrientDb::Migrations::CreateAttribute < OrientDb::Migration ...@@ -5,9 +5,9 @@ class OrientDb::Migrations::CreateAttribute < OrientDb::Migration
c.property 'key', :string c.property 'key', :string
c.property 'value', :string c.property 'value', :string
end end
add_index 'Attribute', 'key', "NOTUNIQUE_HASH_INDEX" add_index 'Attribute', ['key'], "NOTUNIQUE_HASH_INDEX"
metadata = {:analyzer => "org.apache.lucene.analysis.br.BrazilianAnalyzer"} metadata = {:analyzer => "org.apache.lucene.analysis.br.BrazilianAnalyzer"}
add_index 'Attribute', 'value', "FULLTEXT", "LUCENE", metadata.to_json add_index 'Attribute', ['value'], "FULLTEXT", nil, "LUCENE", metadata.to_json
end end
def down def down
......
...@@ -8,7 +8,9 @@ class OrientDb::Migrations::CreateLearningObject < OrientDb::Migration ...@@ -8,7 +8,9 @@ class OrientDb::Migrations::CreateLearningObject < OrientDb::Migration
c.property 'type', :string c.property 'type', :string
c.property 'metadata', :string c.property 'metadata', :string
end end
add_index 'LearningObject', 'id_dspace', :type => "UNIQUE_HASH_INDEX" add_index 'LearningObject', ['id_dspace'], "UNIQUE_HASH_INDEX"
metadata = {:analyzer => "org.apache.lucene.analysis.br.BrazilianAnalyzer"}
add_index 'LearningObject', ['name', 'description'], "FULLTEXT", "learningobject_search", "LUCENE", metadata.to_json
end end
def down def down
......
...@@ -4,7 +4,7 @@ class OrientDb::Migrations::CreateUser < OrientDb::Migration ...@@ -4,7 +4,7 @@ class OrientDb::Migrations::CreateUser < OrientDb::Migration
create_class 'User', 'V' do |c| create_class 'User', 'V' do |c|
c.property 'p_id', :integer, :mandatory => true, :notnull => true c.property 'p_id', :integer, :mandatory => true, :notnull => true
end end
add_index 'User', 'p_id', "UNIQUE_HASH_INDEX" add_index 'User', ['p_id'], "UNIQUE_HASH_INDEX"
end end
def down def down
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment