psq-dm-xapian 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dm-xapian/merbtasks.rb +61 -0
- metadata +2 -1
@@ -0,0 +1,61 @@
|
|
1
|
+
namespace :xapian do
|
2
|
+
# Parameters - specify "flush=true" to save changes to the Xapian database
|
3
|
+
# after each model that is updated. This is safer, but slower. Specify
|
4
|
+
# "verbose=true" to print model name as it is run.
|
5
|
+
desc 'Updates Xapian search index with changes to models since last call'
|
6
|
+
task(:update_index => [:merb_env]) do
|
7
|
+
# require 'ruby-debug'
|
8
|
+
# Debugger.start
|
9
|
+
# Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)
|
10
|
+
|
11
|
+
ActsAsXapian.configure(Merb.env||'development', Merb.root)
|
12
|
+
ActsAsXapian.update_index(ENV['flush'] ? true : false, ENV['verbose'] ? true : false)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Parameters - specify 'models="PublicBody User"' to say which models
|
16
|
+
# you index with Xapian.
|
17
|
+
# This totally rebuilds the database, so you will want to restart any
|
18
|
+
# web server afterwards to make sure it gets the changes, rather than
|
19
|
+
# still pointing to the old deleted database. Specify "verbose=true" to
|
20
|
+
# print model name as it is run.
|
21
|
+
desc 'Completely rebuilds Xapian search index (must specify all models)'
|
22
|
+
task(:rebuild_index => [:merb_env]) do
|
23
|
+
# require 'ruby-debug'
|
24
|
+
# Debugger.start
|
25
|
+
# Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)
|
26
|
+
|
27
|
+
raise "specify ALL your models with models=\"ModelName1 ModelName2\" as parameter" if ENV['models'].nil?
|
28
|
+
ActsAsXapian.configure(Merb.env||'development', Merb.root)
|
29
|
+
# Transform the array of model strings into an array of resource classes
|
30
|
+
# Only retain resources which have been indexed by Xapian
|
31
|
+
indexed_models = DataMapper::Resource.descendants.select { |m| m.include?(DataMapper::Xapian::InstanceMethods) }
|
32
|
+
models_for_rebuild = []
|
33
|
+
found_models = nil
|
34
|
+
ENV['models'].split(" ").each do |m_name|
|
35
|
+
found_models = indexed_models.select { |m| m.name == m_name }
|
36
|
+
unless found_models.empty?
|
37
|
+
models_for_rebuild << found_models.first
|
38
|
+
else
|
39
|
+
raise "The model name #{m_name} is either unknown to " +
|
40
|
+
"DataMapper or not indexed by Xapian"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
ActsAsXapian.rebuild_index(models_for_rebuild, ENV['verbose'] ? true : false)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Parameters - are models, query, offset, limit, sort_by_prefix,
|
47
|
+
# collapse_by_prefix
|
48
|
+
desc 'Run a query, return YAML of results'
|
49
|
+
task(:query => [:merb_env]) do
|
50
|
+
ActsAsXapian.configure(Merb.env||'development', Merb.root)
|
51
|
+
raise "specify models=\"ModelName1 ModelName2\" as parameter" if ENV['models'].nil?
|
52
|
+
raise "specify query=\"your terms\" as parameter" if ENV['query'].nil?
|
53
|
+
s = ActsAsXapian::Search.new(ENV['models'].split(" "),
|
54
|
+
ENV['query'],
|
55
|
+
:offset => (ENV['offset'] || 0), :limit => (ENV['limit'] || 10),
|
56
|
+
:sort_by_prefix => (ENV['sort_by_prefix'] || nil),
|
57
|
+
:collapse_by_prefix => (ENV['collapse_by_prefix'] || nil)
|
58
|
+
)
|
59
|
+
STDOUT.puts(s.results.to_yaml)
|
60
|
+
end
|
61
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: psq-dm-xapian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshaven Potter, Pascal Belloncle
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- Rakefile
|
40
40
|
- TODO
|
41
41
|
- lib/dm-xapian.rb
|
42
|
+
- lib/dm-xapian/merbtasks.rb
|
42
43
|
- SETUP.txt
|
43
44
|
- CHANGES.txt
|
44
45
|
has_rdoc: true
|