cl-console 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/cl_console.rb +13 -4
  2. metadata +13 -4
data/lib/cl_console.rb CHANGED
@@ -24,8 +24,10 @@ class CLConsole
24
24
  res = JSON.parse(open(url).string)
25
25
  puts ">> q: #{res["q"]} (#{res["search_duration"]}ms / #{res["fetch_duration"]}ms)"
26
26
  res
27
+ rescue Exception => e
28
+ puts "An exception occurred: #{e.message}"
27
29
  end
28
-
30
+
29
31
  # do the query, and only give me the rows
30
32
  def qr(query, opts={})
31
33
  q(query,opts)["rows"]
@@ -47,11 +49,12 @@ class CLConsole
47
49
  # helper to escape searchterms properly for lucene search queries
48
50
  def escape(str)
49
51
  lucene_chars = %w{+ - & | ! ( ) { } [ ] ^ " ~ * ? : \\}.collect {|e| Regexp.escape(e)}
50
- str.gsub!(/(#{lucene_chars.join("|")})/, '\\\\\1')
52
+ str.gsub(/(#{lucene_chars.join("|")})/, '\\\\\1')
51
53
  end
54
+ alias :e :escape
52
55
 
53
56
  # display help message
54
- def help
57
+ def self.help
55
58
  puts <<-HELP_MSG
56
59
  ------------------------------------------------------------------------------
57
60
  CL-Console Help
@@ -62,7 +65,10 @@ Example usage:
62
65
  cl = CLConsole.new("db/ddoc/index")
63
66
 
64
67
  # or initialize with a full url
65
- cl = CLConsole.new("http://localhost:5984/db/_fti/_design/ddoc/index")
68
+ cl = CLConsole.new("http://localhost:5984/db/_fti/_design/ddoc/index")
69
+
70
+ # you can also access couchdb-lucene direct:
71
+ cl = CLConsole.new("http://localhost:5985/local/dewiki/_design/wiki/all")
66
72
 
67
73
  # You can also pass a hash with options to be passed to couchdb-lucene, like
68
74
  # limit, sorting, debug, ... see the couchdb-lucene documentation for details.
@@ -80,7 +86,10 @@ cl.qd "title:(couchdb OR lucene) AND body:(awesome AND \#{cl.escape(':-)')})"
80
86
 
81
87
  cl.info # get index infos
82
88
  cl.help # this info
89
+ cl.e "~^" # helper: proper escaping of lucene query operators
90
+ => \~\^
83
91
  ------------------------------------------------------------------------------
84
92
  HELP_MSG
85
93
  end
94
+ def help; CLConsole.help; end
86
95
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cl-console
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 23
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
- - 1
8
+ - 2
8
9
  - 0
9
- version: 0.1.0
10
+ version: 0.2.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Sebastian Cohnen
@@ -14,16 +15,18 @@ autorequire: lib/cl_console.rb
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-04-21 00:00:00 +02:00
18
+ date: 2010-08-10 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: activesupport
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 0
29
32
  version: "0"
@@ -33,9 +36,11 @@ dependencies:
33
36
  name: json
34
37
  prerelease: false
35
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
36
40
  requirements:
37
41
  - - ">="
38
42
  - !ruby/object:Gem::Version
43
+ hash: 31
39
44
  segments:
40
45
  - 1
41
46
  - 2
@@ -68,23 +73,27 @@ require_paths:
68
73
  - lib
69
74
  - lib
70
75
  required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
71
77
  requirements:
72
78
  - - ">="
73
79
  - !ruby/object:Gem::Version
80
+ hash: 3
74
81
  segments:
75
82
  - 0
76
83
  version: "0"
77
84
  required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
78
86
  requirements:
79
87
  - - ">="
80
88
  - !ruby/object:Gem::Version
89
+ hash: 3
81
90
  segments:
82
91
  - 0
83
92
  version: "0"
84
93
  requirements: []
85
94
 
86
95
  rubyforge_project:
87
- rubygems_version: 1.3.6
96
+ rubygems_version: 1.3.7
88
97
  signing_key:
89
98
  specification_version: 3
90
99
  summary: Little gem meant to be used in IRB sessions for querying CouchDB-Lucene indices.