solrsan 0.0.30 → 0.0.32

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- solrsan (0.0.25)
4
+ solrsan (0.0.31)
5
5
  activemodel (~> 3.0.5)
6
6
  activesupport (~> 3.0.5)
7
7
  rsolr (~> 1.0.0)
@@ -9,11 +9,11 @@ PATH
9
9
  GEM
10
10
  remote: http://rubygems.org/
11
11
  specs:
12
- activemodel (3.0.5)
13
- activesupport (= 3.0.5)
12
+ activemodel (3.0.7)
13
+ activesupport (= 3.0.7)
14
14
  builder (~> 2.1.2)
15
- i18n (~> 0.4)
16
- activesupport (3.0.5)
15
+ i18n (~> 0.5.0)
16
+ activesupport (3.0.7)
17
17
  builder (2.1.2)
18
18
  i18n (0.5.0)
19
19
  rsolr (1.0.0)
data/README.rdoc ADDED
@@ -0,0 +1,112 @@
1
+ = solrsan
2
+
3
+ http://github.com/tc/solrsan
4
+
5
+ This gem is a lightweight wrapper for the Apache Solr API.
6
+
7
+ Before you start, read the documentation for solr at http://wiki.apache.org/solr
8
+
9
+ It'll be invaluable for knowing parameters and error messages.
10
+ I made a few test cases for further examples at http://github.com/tc/solrsan/tree/master/test/unit
11
+
12
+ === HOWTO
13
+ Install Jetty
14
+
15
+ wget http://download.eclipse.org/jetty/stable-7/dist/jetty-distribution-7.3.0.v20110203.tar.gz
16
+ tar -zxvf jetty-distribution-*.tar.gz
17
+ rm jetty-distribution-*.tar.gz
18
+ mv jetty-distribution-* /usr/local
19
+ ln -s jetty-distribution-* jetty
20
+
21
+ Install solr
22
+
23
+
24
+ wget http://www.ecoficial.com/apachemirror/lucene/solr/3.1.0/apache-solr-3.1.0.tgz
25
+ tar -zxvf apache-solr-*.tgz
26
+ cd apache-solr-*
27
+ cp dist/apache-solr-*.war /usr/local/jetty/webapps/solr.war
28
+
29
+ Add solrsan to your Ruby application's Gemfile:
30
+ gem "solrsan"
31
+
32
+ Create solr configuration files using:
33
+ rails generate solrsan:config
34
+
35
+ The generator will copy the following files into your application.
36
+
37
+ config/solr.yml
38
+ config/solr
39
+ config/initializers/solrsan.rb
40
+ lib/tasks/solr.rake
41
+
42
+ Edit the config/solr.yml for your directory paths.
43
+
44
+ The rake file will add these rake tasks:
45
+
46
+ rake solr:start
47
+ rake solr:stop
48
+ rake solr:clear_index
49
+ rake solr:index
50
+
51
+ you will need to alter clear_index/index to match your models
52
+
53
+ Deploy tasks via capistrano:
54
+ add to your deploy.rb
55
+
56
+ require 'solrsan/capistrano'
57
+
58
+ This will add the following methods which will just call the
59
+ corresponding rake tasks:
60
+
61
+ cap solr:start
62
+ cap solr:stop
63
+ cap solr:reindex
64
+
65
+ === Indexing documents:
66
+ Edit config/solr/conf/schema.xml to state the types of fields you want
67
+ to index. You can use dynamic fields as well.
68
+
69
+ These fields are required for each solr document and are automatically
70
+ generated:
71
+
72
+ id, db_id, type
73
+
74
+ In your model, define as_solr_document and return a hash with specific fields.
75
+
76
+
77
+ class Document < ActiveRecord::Base
78
+ include Solrsan::Search
79
+ after_save :index
80
+ before_destroy :destroy_index_document
81
+
82
+ def as_solr_document
83
+ {:content => "hi"}
84
+ end
85
+ end
86
+
87
+
88
+ In each model, you can include a Solrsan::Search module which will include a few interface helper methods:
89
+ index
90
+ destroy_index_document
91
+ search(params)
92
+
93
+ === Search:
94
+ A simple search query:
95
+ Document.search(:q => "hello world")
96
+
97
+ More searching examples can be seen in test/unit/search_test.rb
98
+
99
+ == Changelog
100
+ 0.0.32
101
+ Using Hashwithindifferentaccess for request parsing.
102
+
103
+ 0.0.31
104
+ Usable version!
105
+
106
+ 0.0.1
107
+ First release.
108
+
109
+ == Copyright
110
+
111
+ Copyright (c) 2011 Tommy Chheng. See LICENSE for details.
112
+
@@ -3,28 +3,21 @@ require 'rails/generators/solrsan_generator'
3
3
  module Solrsan
4
4
  module Generators
5
5
  class ConfigGenerator < Rails::Generators::Base
6
- desc "This setups the configuration files for solrsan"
7
- def self.source_root
8
- File.expand_path("../templates", __FILE__)
9
- end
6
+ source_root File.expand_path("../templates", __FILE__)
10
7
 
11
-   def create_config_files
12
- template "solrsan.rb", File.join("config", "initializers", "solrsan.rb")
13
- template "solr.yml", File.join("config", "solr.yml")
14
-   end
8
+ def create_config_files
9
+ template("solrsan.rb", File.join("config", "initializers", "solrsan.rb"))
10
+ template("solr.yml", File.join("config", "solr.yml"))
11
+ end
15
12
 
16
13
  def copy_solr_conf
17
- Dir["config/solr/conf/*"].each do |source|
18
- destination = "config/solr/conf/#{File.basename(source)}"
19
- FileUtils.rm(destination) if options[:force]
20
- if File.exist?(destination)
21
- puts "Skipping #{destination} because it already exists"
22
- else
23
- puts "Generating #{destination}"
24
- FileUtils.cp(source, destination)
25
- end
26
- end
14
+ directory "../../../../../../config/solr", "config/solr", :recursive => true
27
15
  end
16
+
17
+ def copy_rake_task
18
+ copy_file "../../../../../tasks/solr.rake", "lib/tasks/solr.rake"
19
+ end
20
+
28
21
  end
29
22
  end
30
23
  end
@@ -37,10 +37,10 @@ module Solrsan
37
37
  end
38
38
 
39
39
  def parse_params_for_solr(search_params={})
40
- solr_params = { :echoParams => 'explicit',
40
+ solr_params = HashWithIndifferentAccess.new({ :echoParams => 'explicit',
41
41
  :q => "*:*",
42
42
  :facet => "on",
43
- :'facet.mincount' => 1}.merge(search_params)
43
+ :'facet.mincount' => 1}.merge(search_params))
44
44
  solr_params[:hl] = true unless search_params[:'hl.fl'].blank?
45
45
  solr_params[:fq] = ["type:#{class_name}"] + parse_fq(search_params[:fq])
46
46
  solr_params
@@ -1,3 +1,3 @@
1
1
  module Solrsan
2
- VERSION = "0.0.30"
2
+ VERSION = "0.0.32"
3
3
  end
@@ -85,6 +85,14 @@ class SearchTest < Test::Unit::TestCase
85
85
  assert_equal expected, filters
86
86
  end
87
87
 
88
+ def test_parse_fq_with_hash_multiple_entries
89
+ params = {:fq => {:tags => ["ruby", "scala"], :author => "Bert"}}
90
+ filters = Document.parse_fq(params[:fq])
91
+
92
+ expected = ["tags:\"ruby\"", "tags:\"scala\"", "author:\"Bert\""]
93
+ assert_equal expected, filters
94
+ end
95
+
88
96
  def test_parse_fq_with_hash_array_args
89
97
  params = {:fq => [{:tags => ["ruby", "scala"]}]}
90
98
  filters = Document.parse_fq(params[:fq])
@@ -115,6 +123,22 @@ class SearchTest < Test::Unit::TestCase
115
123
  assert_equal expected, filters
116
124
  end
117
125
 
126
+
127
+ def test_filter_query_mulitple_filters
128
+ Document.index(Document.new(:id => 3, :author => "Bert", :title => "solr lucene",:review_count => 10, :tags => ['ruby']))
129
+ Document.index(Document.new(:id => 4, :author => "Ernie", :title => "lucene solr", :review_count => 5, :tags => ['ruby', 'scala']))
130
+
131
+ response = Document.search(:q => "solr", :fq => {:tags => ["scala"], :author => "Ernie"})
132
+ docs = response[:docs]
133
+ metadata = response[:metadata]
134
+
135
+ assert_equal 1, metadata[:total_count]
136
+
137
+ doc = docs.first
138
+ assert_not_nil doc['tags']
139
+ assert doc['tags'].include?("scala")
140
+ end
141
+
118
142
  def test_filter_query
119
143
  Document.index(Document.new(:id => 3, :author => "Bert", :title => "solr lucene",:review_count => 10, :tags => ['ruby']))
120
144
  Document.index(Document.new(:id => 4, :author => "Ernie", :title => "lucene solr", :review_count => 5, :tags => ['ruby', 'scala']))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solrsan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.30
4
+ version: 0.0.32
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-04-11 00:00:00.000000000 -07:00
12
+ date: 2011-05-03 00:00:00.000000000 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr
17
- requirement: &2172979340 !ruby/object:Gem::Requirement
17
+ requirement: &2156388680 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 1.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2172979340
25
+ version_requirements: *2156388680
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activemodel
28
- requirement: &2172978840 !ruby/object:Gem::Requirement
28
+ requirement: &2156388180 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 3.0.5
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2172978840
36
+ version_requirements: *2156388180
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: activesupport
39
- requirement: &2172978380 !ruby/object:Gem::Requirement
39
+ requirement: &2156404100 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 3.0.5
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *2172978380
47
+ version_requirements: *2156404100
48
48
  description: solrsan is a lightweight wrapper for using Apache Solr within a Ruby
49
49
  application including Rails and Sinatra.
50
50
  email:
@@ -57,7 +57,7 @@ files:
57
57
  - Gemfile
58
58
  - Gemfile.lock
59
59
  - LICENSE
60
- - README.markdown
60
+ - README.rdoc
61
61
  - Rakefile
62
62
  - config/solr.yml
63
63
  - config/solr.yml.example
data/README.markdown DELETED
@@ -1,71 +0,0 @@
1
- # solrsan
2
- This gem is a lightweight wrapper for the Apache Solr API.
3
-
4
- Before you start, read the documentation for solr at http://wiki.apache.org/solr/
5
-
6
- It'll be invaluable for knowing parameters and error messages. I made a few test cases for further examples at http://github.com/tc/solrsan/tree/master/test/
7
-
8
- ## HOWTO
9
- Install jetty:
10
- Download jetty 7 from http://download.eclipse.org/jetty/stable-7/dist/
11
-
12
- Install solr:
13
- Download solr from http://www.apache.org/dyn/closer.cgi/lucene/solr/
14
- Unzip the jar file:
15
- tar -zxvf apache-solr-*.jar
16
-
17
- Copy dist/apache-solr-*.war into jetty's webapps directory as solr.war:
18
- cd apache-solr-*
19
- cp dist/apache-solr-*.war JETTY_PATH/webapps/solr.war
20
-
21
- Create solrsan and solr configuration files using:
22
- rails generate Solrsan:Config
23
-
24
- The generator will copy the following files into your application.
25
- config/solr.yml
26
- config/solr
27
- config/initializers/solrsan.rb
28
- lib/tasks/solr.rake
29
-
30
- The rake file will add
31
- rake solr:start
32
- rake solr:stop
33
- rake solr:clear_index
34
- rake solr:index
35
- #you will need to alter clear_index/index to match your models
36
-
37
- Deploy tasks via capistrano:
38
- add to your deploy.rb
39
- require 'solrsan/capistrano'
40
-
41
- This will add the following methods which will just call the
42
- corresponding rake tasks:
43
- cap solr:start
44
- cap solr:stop
45
- cap solr:reindex
46
-
47
- ##
48
- The fields are required for each solr document:
49
- id, db_id, type
50
-
51
- In each model, you can include a Solrsan::Search module which will include a few interface helper methods:
52
- index
53
- destroy_index_document
54
- search(params)
55
-
56
- You can also add hooks for thse methods:
57
- class Document < ActiveRecord::Base
58
- include Solrsan::Search
59
- after_save :index
60
- before_destroy :destroy_index_document
61
- end
62
-
63
- ---
64
- ## Changelog
65
- 0.0.1
66
- First release.
67
-
68
- ## Copyright
69
-
70
- Copyright (c) 2011 Tommy Chheng. See LICENSE for details.
71
-