solrj_wrapper 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7989bdc10a4e4a7a95890a667b9f9b86518a917
4
- data.tar.gz: 3954aed416588570e50fdc057d6a5c612138902a
3
+ metadata.gz: 5e6fbae7ea34d1a93ec3458e41597bb89d53bab9
4
+ data.tar.gz: 8e87b28c23005e38e44875aaa139d6d1d4397eaa
5
5
  SHA512:
6
- metadata.gz: 670af841e8fbf23f4299cb976ca769b4d21f7bc39d8990b78ce00272857c66d6c38cf4497777ca988ed3f783f54f6e33c32d041edf8006da5dfc98e62a22f0bd
7
- data.tar.gz: 2d6f5d5021adbb3106eae923927f6afba7d3f53486601d3f9c21e62cb8365cb0ec99946280bf143f049a537103a132f8c28258efe3453b8fbdcb6dca1830a603
6
+ metadata.gz: 608f548687498d7c52d871d61cc60136bb57c2f70173ecd4f5e183bbc9d32693e6059fdab2537eddeea9ce47095ca05baa6529c92e430ec6135d4d17d1e2b8a7
7
+ data.tar.gz: 0c4f6b2f9c2098610d083b385585d4a10e9c5a59791adc6b070f58a4b73f4d68448be32328a1dcf11fa100975b86afe1f9f6e2e320d7a826929c5ed0a1b7c49a
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 20XX-2012. The Board of Trustees of the Leland Stanford Junior University. All rights reserved.
1
+ Copyright (c) 2012-2014. The Board of Trustees of the Leland Stanford Junior University. All rights reserved.
2
2
 
3
3
  Redistribution and use of this distribution in source and binary forms, with or without modification, are permitted provided that: The above copyright notice and this permission notice appear in all copies and supporting documentation; The name, identifiers, and trademarks of The Board of Trustees of the Leland Stanford Junior University are not used in advertising or publicity without the express prior written permission of The Board of Trustees of the Leland Stanford Junior University; Recipients acknowledge that this distribution is made available as a research courtesy, "as is", potentially with defects, without any obligation on the part of The Board of Trustees of the Leland Stanford Junior University to provide support, services, or repair;
4
4
 
@@ -21,7 +21,9 @@ Or install it yourself as:
21
21
 
22
22
  == Usage
23
23
 
24
- This gem must be run under JRuby, and also requires a directory containing Solrj jar files and solr url (see config/settings.yml)
24
+ This gem must be run under JRuby, and also requires a directory containing Solrj jar files and solr url (see config/settings.yml).
25
+
26
+ It is known to work with Solr(J) release 4.4. Other versions of SolrJ may not work.
25
27
 
26
28
  Here are some examples of use cribbed from the specs:
27
29
 
@@ -2,22 +2,16 @@
2
2
  prod:
3
3
  solr_url: your_production_solr_url
4
4
  solrj_jar_dir: your_solrj_jar_dir
5
- solrj_queue_size: 20
6
- solrj_num_threads: 1
7
- log_level: error
5
+ log_level: warn
8
6
 
9
7
  # settings for local development
10
8
  dev:
11
9
  solr_url: your_dev_solr_url
12
10
  solrj_jar_dir: your_solrj_jar_dir
13
- solrj_queue_size: 20
14
- solrj_num_threads: 1
15
11
  log_level: info
16
12
 
17
13
  # settings for continuous integration
18
14
  ci:
19
15
  solr_url: http://localhost:8984/solr
20
16
  solrj_jar_dir: solrmarc-sw/dist/lib
21
- solrj_queue_size: 20
22
- solrj_num_threads: 1
23
17
  log_level: info
@@ -6,41 +6,31 @@ require 'logger'
6
6
  # Methods required to interact with SolrJ objects, such as org.apache.solr.client.solrj.impl.StreamingUpdateSolrServer
7
7
  class SolrjWrapper
8
8
 
9
- attr_reader :streaming_update_server, :query_server
9
+ attr_reader :http_solr_server
10
10
  attr_accessor :query
11
11
 
12
12
  # @param solrj_jar_dir the location of Solrj jars needed to use SolrJ here
13
13
  # @param solr_url base url of the solr instance
14
- # @param queue_size the number of Solr documents to buffer before writing to Solr
15
- # @param num_threads the number of threads to use when writing to Solr (should not be more than the number of cpu cores avail)
16
14
  # @param log_level level of Logger messages to output; defaults to Logger::INFO
17
15
  # @param log_file file to receive Logger output; defaults to STDERR
18
- def initialize(solrj_jar_dir, solr_url, queue_size, num_threads, log_level=Logger::INFO, log_file=STDERR)
16
+ def initialize(solrj_jar_dir, solr_url, log_level=Logger::INFO, log_file=STDERR)
19
17
  if not defined? JRUBY_VERSION
20
18
  raise "SolrjWrapper only runs under jruby"
21
19
  end
22
20
  @logger = Logger.new(log_file)
23
21
  @logger.level = log_level
24
22
  load_solrj(solrj_jar_dir)
25
- @query_server = org.apache.solr.client.solrj.impl.HttpSolrServer.new(solr_url)
26
- @streaming_update_server = @query_server
23
+ @http_solr_server = org.apache.solr.client.solrj.impl.HttpSolrServer.new(solr_url)
27
24
  end
28
25
 
29
26
  # send the query to Solr and get the SolrDocumentList from the response
30
27
  # @param org.apache.solr.client.solrj.SolrQuery object populated with query information to send to Solr
31
28
  # @return Java::OrgApacheSolrCommon::SolrDocumentList per the query. The list size will be the number of rows in the Solr response
32
29
  def get_query_result_docs(query_obj)
33
- response = @query_server.query(query_obj)
30
+ response = @http_solr_server.query(query_obj)
34
31
  response.getResults
35
32
  end
36
33
 
37
- # Send requests using the Javabin binary format instead of serializing to XML
38
- # Requires /update/javabin to be defined in solrconfig.xml as
39
- # <requestHandler name="/update/javabin" class="solr.BinaryUpdateRequestHandler" />
40
- def useJavabin!
41
- @streaming_update_server.setRequestWriter Java::org.apache.solr.client.solrj.impl.BinaryRequestWriter.new
42
- end
43
-
44
34
  # given a SolrInputDocument, add the field and/or the values. This will not add empty values, and it will not add duplicate values
45
35
  # @param solr_input_doc - the SolrInputDocument object receiving a new field value
46
36
  # @param fld_name - the name of the Solr field
@@ -79,13 +69,13 @@ class SolrjWrapper
79
69
  add_vals_to_fld(solr_input_doc, fld_name, val_array)
80
70
  end
81
71
 
82
- # add the doc to Solr by calling add on the Solrj StreamingUpdateServer object
72
+ # add the doc to Solr by calling add on the Solrj HttpSolrServer object
83
73
  # @param solr_input_doc - the SolrInputDocument to be added to the Solr index
84
74
  # @param id - the id of the Solr document, used for log messages
85
75
  def add_doc_to_ix(solr_input_doc, id)
86
76
  unless solr_input_doc.nil?
87
77
  begin
88
- @streaming_update_server.add(solr_input_doc)
78
+ @http_solr_server.add(solr_input_doc)
89
79
  @logger.info("updating Solr document #{id}")
90
80
  rescue org.apache.solr.common.SolrException => e
91
81
  @logger.error("SolrException while indexing document #{id}")
@@ -95,10 +85,10 @@ class SolrjWrapper
95
85
  end
96
86
  end
97
87
 
98
- # send a commit to the Solrj StreamingUpdateServer object
88
+ # send a commit to the Solrj HttpSolrServer object
99
89
  def commit
100
90
  begin
101
- update_response = @streaming_update_server.commit
91
+ update_response = @http_solr_server.commit
102
92
  rescue org.apache.solr.common.SolrException => e
103
93
  @logger.error("SolrException while committing updates")
104
94
  @logger.error("#{e.message}")
@@ -108,7 +98,7 @@ class SolrjWrapper
108
98
 
109
99
  # remove all docs from the Solr index. Assumes default request handler has type dismax
110
100
  def empty_ix
111
- delete_response = @streaming_update_server.deleteByQuery("*:*")
101
+ delete_response = @http_solr_server.deleteByQuery("*:*")
112
102
  commit
113
103
  end
114
104
 
@@ -3,14 +3,12 @@ require 'yaml'
3
3
  # Read the .yml file containing the configuration values
4
4
  class Settings
5
5
 
6
- attr_reader :solr_url, :solrj_jar_dir, :solrj_queue_size, :solrj_num_threads, :log_level, :log_file
6
+ attr_reader :solr_url, :solrj_jar_dir, :log_level, :log_file
7
7
 
8
8
  def initialize(settings_group)
9
9
  yml = YAML.load_file('lib/config/settings.yml')[settings_group]
10
10
  @solr_url = yml["solr_url"]
11
11
  @solrj_jar_dir = yml["solrj_jar_dir"]
12
- @solrj_queue_size = yml["solrj_queue_size"]
13
- @solrj_num_threads = yml["solrj_num_threads"]
14
12
  @log_level = yml["log_level"]
15
13
  @log_file = yml["log_file"]
16
14
  end
@@ -19,8 +17,6 @@ class Settings
19
17
  def as_hash
20
18
  {:solr_url => @solr_url,
21
19
  :solrj_jar_dir => @solrj_jar_dir,
22
- :solrj_queue_size => @solrj_queue_size,
23
- :solrj_num_threads => @solrj_num_threads,
24
20
  :log_level => get_log_level,
25
21
  :log_file => @log_file
26
22
  }
@@ -1,3 +1,3 @@
1
1
  class SolrjWrapper
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -4,11 +4,11 @@ require 'solrj_wrapper'
4
4
  describe SolrjWrapper do
5
5
 
6
6
  before(:all) do
7
- @solrj_wrapper = SolrjWrapper.new(@@settings.solrj_jar_dir, @@settings.solr_url, @@settings.solrj_queue_size, @@settings.solrj_num_threads, @@settings.log_level, @@settings.log_file)
7
+ @solrj_wrapper = SolrjWrapper.new(@@settings.solrj_jar_dir, @@settings.solr_url, @@settings.log_level, @@settings.log_file)
8
8
  end
9
9
 
10
- it "should initialize a query_server object" do
11
- expect(@solrj_wrapper.query_server).to be_an_instance_of(Java::OrgApacheSolrClientSolrjImpl::HttpSolrServer)
10
+ it "initializes an HttpSolrServer object" do
11
+ expect(@solrj_wrapper.http_solr_server).to be_an_instance_of(Java::OrgApacheSolrClientSolrjImpl::HttpSolrServer)
12
12
  end
13
13
 
14
14
  context "get_query_result_docs" do
@@ -40,10 +40,6 @@ describe SolrjWrapper do
40
40
  end
41
41
  end
42
42
 
43
- it "streaming_update_server should be an HttpSolrServer object" do
44
- expect(@solrj_wrapper.streaming_update_server).to be_an_instance_of(Java::OrgApacheSolrClientSolrjImpl::HttpSolrServer)
45
- end
46
-
47
43
  context "add_vals_to_fld" do
48
44
  it "should do nothing if the field name or value is nil or of size 0" do
49
45
  sid = Java::OrgApacheSolrCommon::SolrInputDocument.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solrj_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naomi Dushay