Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.

Commit ffece80

Browse files
DATASOLR-232 - Upgrade to Solr 5 / Bump version to 2.0
The upgrade requires a switch to SolrClient and its derivates. This is a breaking change that demands a major version upgrade of spring-data-solr. XML namspace and JavaConfig bean definition changes accordingly to reflect the changes. <solr:solr-client ../> replaces <solr:solr-server ../> @bean SolrClient solrClient() replaces @bean SolrServer solrServer()
1 parent d099181 commit ffece80

File tree

123 files changed

+11459
-11380
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+11459
-11380
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ spring-data-solr.iml
1010
.DS_Store
1111
_site
1212

13+
/bin/

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ public class SolrContext {
133133
private @Resource Environment env;
134134

135135
@Bean
136-
public SolrServer solrServer() throws MalformedURLException, IllegalStateException {
137-
return new HttpSolrServer(env.getRequiredProperty("solr.host"));
136+
public SolrClient solrClient() throws MalformedURLException, IllegalStateException {
137+
return new HttpSolrClient(env.getRequiredProperty("solr.host"));
138138
}
139139

140140
}
@@ -177,7 +177,7 @@ You can set up repository scanning via xml configuration, which will happily cre
177177
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
178178

179179
<solr:repositories base-package="com.acme.repository" multicoreSupport="true" />
180-
<solr:solr-server id="solrServer" url="http://localhost:8983/solr" />
180+
<solr:solr-client id="solrClient" url="http://localhost:8983/solr" />
181181

182182
</beans>
183183
```
@@ -194,8 +194,8 @@ Use `@Indexed` to provide additional details like specific solr types to use.
194194
class Config {
195195

196196
@Bean
197-
public SolrServer solrServer() {
198-
return new HttpSolrServer("http://localhost:8983/solr");
197+
public SolrClient solrClient() {
198+
return new HttpSolrClient("http://localhost:8983/solr");
199199
}
200200
}
201201

pom.xml

+9-39
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.springframework.data</groupId>
77
<artifactId>spring-data-solr</artifactId>
8-
<version>1.6.0.BUILD-SNAPSHOT</version>
8+
<version>2.0.0.BUILD-SNAPSHOT</version>
99

1010
<name>Spring Data Solr</name>
1111
<description>Spring Data module providing support for Apache Solr repositories.</description>
@@ -22,8 +22,8 @@
2222
<dist.key>DATASOLR</dist.key>
2323
<commons.collections>3.2.1</commons.collections>
2424
<commons.lang>3.1</commons.lang>
25-
<httpcomponents>4.2.2</httpcomponents>
26-
<solr>4.10.4</solr>
25+
<httpcomponents>4.3.1</httpcomponents>
26+
<solr>5.3.0</solr>
2727
<springdata.commons>1.12.0.BUILD-SNAPSHOT</springdata.commons>
2828
</properties>
2929

@@ -90,33 +90,7 @@
9090
<artifactId>commons-collections</artifactId>
9191
<version>3.2.1</version>
9292
</dependency>
93-
<dependency>
94-
<groupId>org.apache.httpcomponents</groupId>
95-
<artifactId>httpclient</artifactId>
96-
<version>${httpcomponents}</version>
97-
<exclusions>
98-
<exclusion>
99-
<groupId>commons-logging</groupId>
100-
<artifactId>commons-logging</artifactId>
101-
</exclusion>
102-
</exclusions>
103-
</dependency>
104-
<dependency>
105-
<groupId>org.apache.httpcomponents</groupId>
106-
<artifactId>httpmime</artifactId>
107-
<version>${httpcomponents}</version>
108-
</dependency>
109-
<dependency>
110-
<groupId>org.apache.httpcomponents</groupId>
111-
<artifactId>httpclient-cache</artifactId>
112-
<version>${httpcomponents}</version>
113-
<exclusions>
114-
<exclusion>
115-
<groupId>commons-logging</groupId>
116-
<artifactId>commons-logging</artifactId>
117-
</exclusion>
118-
</exclusions>
119-
</dependency>
93+
12094

12195
<!-- JODA Time -->
12296
<dependency>
@@ -143,15 +117,7 @@
143117
<exclusion>
144118
<groupId>org.slf4j</groupId>
145119
<artifactId>jcl-over-slf4j</artifactId>
146-
</exclusion>
147-
<exclusion>
148-
<groupId>org.apache.httpcomponents</groupId>
149-
<artifactId>httpclient</artifactId>
150-
</exclusion>
151-
<exclusion>
152-
<groupId>org.apache.httpcomponents</groupId>
153-
<artifactId>httpmime</artifactId>
154-
</exclusion>
120+
</exclusion>
155121
</exclusions>
156122
</dependency>
157123
<dependency>
@@ -168,6 +134,10 @@
168134
<artifactId>jdk.tools</artifactId>
169135
<groupId>jdk.tools</groupId>
170136
</exclusion>
137+
<exclusion>
138+
<groupId>com.fasterxml.jackson.core</groupId>
139+
<artifactId>jackson-core</artifactId>
140+
</exclusion>
171141
</exclusions>
172142
</dependency>
173143

src/main/asciidoc/preface.adoc

+2-6
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ The Spring Data Solr project applies core Spring concepts to the development of
1616
[preface]
1717
== Requirements
1818

19-
Requires http://lucene.apache.org/solr/[Apache Solr] 3.6. Preferably the latest 4.x version.
20-
The client library of SolrJ 5.x is currently, due to breaking changes in the API, not supported.
19+
Requires http://lucene.apache.org/solr/[Apache Solr] 5. Preferably the latest 5.x version.
2120

2221
[source,xml]
2322
----
@@ -26,7 +25,4 @@ The client library of SolrJ 5.x is currently, due to breaking changes in the API
2625
<artifactId>solr-core</artifactId>
2726
<version>${solr.version}</version>
2827
</dependency>
29-
----
30-
31-
NOTE: If you tend to use the Embedded Version of Solr Server 4.x you will also have to add a version of servlet-api and check your <lockType> as well as <unlockOnStartup> settings.
32-
28+
----

src/main/asciidoc/reference/data-solr.adoc

+13-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This chapter includes details of the Solr repository implementation.
99
[[solr.namespace]]
1010
=== Spring Namespace
1111

12-
The Spring Data Solr module contains a custom namespace allowing definition of repository beans as well as elements for instantiating a `SolrServer` .
12+
The Spring Data Solr module contains a custom namespace allowing definition of repository beans as well as elements for instantiating a `SolrClient` .
1313

1414
Using the `repositories` element looks up Spring Data repositories as described in <<repositories.create-instances>> .
1515

@@ -31,9 +31,9 @@ Using the `repositories` element looks up Spring Data repositories as described
3131
----
3232
====
3333

34-
Using the `solr-server` or `embedded-solr-server` element registers an instance of `SolrServer` in the context.
34+
Using the `solr-server` or `embedded-solr-server` element registers an instance of `SolrClient` in the context.
3535

36-
.HttpSolrServer using Namespace
36+
.HttpSolrClient using Namespace
3737
====
3838
[source,xml]
3939
----
@@ -46,12 +46,12 @@ Using the `solr-server` or `embedded-solr-server` element registers an instance
4646
http://www.springframework.org/schema/data/solr
4747
http://www.springframework.org/schema/data/solr/spring-solr.xsd">
4848
49-
<solr:solr-server id="solrServer" url="http://locahost:8983/solr" />
49+
<solr:solr-client id="solrClient" url="http://locahost:8983/solr" />
5050
</beans>
5151
----
5252
====
5353

54-
.LBSolrServer using Namespace
54+
.LBSolrClient using Namespace
5555
====
5656
[source,xml]
5757
----
@@ -64,7 +64,7 @@ Using the `solr-server` or `embedded-solr-server` element registers an instance
6464
http://www.springframework.org/schema/data/solr
6565
http://www.springframework.org/schema/data/solr/spring-solr.xsd">
6666
67-
<solr:solr-server id="solrServer" url="http://locahost:8983/solr,http://localhost:8984/solr" />
67+
<solr:solr-client id="solrClient" url="http://locahost:8983/solr,http://localhost:8984/solr" />
6868
</beans>
6969
----
7070
====
@@ -82,7 +82,7 @@ Using the `solr-server` or `embedded-solr-server` element registers an instance
8282
http://www.springframework.org/schema/data/solr
8383
http://www.springframework.org/schema/data/solr/spring-solr.xsd">
8484
85-
<solr:embedded-solr-server id="solrServer" solrHome="classpath:com/acme/solr" />
85+
<solr:embedded-solr-server id="solrClient" solrHome="classpath:com/acme/solr" />
8686
</beans>
8787
----
8888
====
@@ -101,14 +101,14 @@ The Spring Data Solr repositories support cannot only be activated through an XM
101101
class ApplicationConfig {
102102
103103
@Bean
104-
public SolrServer solrServer() {
104+
public SolrClient solrClient() {
105105
EmbeddedSolrServerFactory factory = new EmbeddedSolrServerFactory("classpath:com/acme/solr");
106106
return factory.getSolrServer();
107107
}
108108
109109
@Bean
110110
public SolrOperations solrTemplate() {
111-
return new SolrTemplate(solrServer());
111+
return new SolrTemplate(solrClient());
112112
}
113113
}
114114
----
@@ -119,7 +119,7 @@ The configuration above sets up an `EmbeddedSolrServer` which is used by the `So
119119
[[solr.multicore]]
120120
=== Multicore Support
121121

122-
Solr handles different collections within one core. Use `MulticoreSolrServerFactory` to create separate `SolrServer` for each core.
122+
Solr handles different collections within one core. Use `MulticoreSolrClientFactory` to create separate `SolrClient` for each core.
123123

124124
.Multicore Configuration
125125
====
@@ -135,8 +135,8 @@ class ApplicationConfig {
135135
private Environment environment;
136136
137137
@Bean
138-
public SolrServer solrServer() {
139-
return new HttpSolrServer(environment.getRequiredProperty(PROPERTY_NAME_SOLR_SERVER_URL));
138+
public SolrClient solrClient() {
139+
return new HttpSolrClient(environment.getRequiredProperty(PROPERTY_NAME_SOLR_SERVER_URL));
140140
}
141141
142142
}
@@ -488,7 +488,7 @@ To register a custom converter one must add `CustomConversions` to `SolrTemplate
488488
</bean>
489489
490490
<bean id="solrTemplate" class="org.springframework.data.solr.core.SolrTemplate">
491-
<constructor-arg ref="solrServer" />
491+
<constructor-arg ref="solrClient" />
492492
<property name="solrConverter" ref="solrConverter" />
493493
</bean>
494494
----

src/main/asciidoc/reference/misc.adoc

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ This chapter covers additional support for Solr operations (such as faceting) th
66
[[solr.misc.partialUpdates]]
77
== Partial Updates
88

9-
PartialUpdates can be done using `PartialUpdate` which implements `Update` . NOTE: Partial updates require Solr 4.x. With Solr 4.0.0 it is not possible to update mulitvalue fields.
10-
11-
NOTE: With Solr 4.1.0 you have to take care on parameter order when setting null values. Order parameters with nulls last.
9+
PartialUpdates can be done using `PartialUpdate` which implements `Update`.
1210

1311
====
1412
[source,java]

src/main/java/org/springframework/data/solr/SolrRealtimeGetRequest.java

+5-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014 - 2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,13 +20,10 @@
2020
import java.util.ArrayList;
2121
import java.util.Arrays;
2222
import java.util.Collection;
23-
import java.util.concurrent.TimeUnit;
2423

24+
import org.apache.solr.client.solrj.SolrClient;
2525
import org.apache.solr.client.solrj.SolrRequest;
26-
import org.apache.solr.client.solrj.SolrServer;
27-
import org.apache.solr.client.solrj.SolrServerException;
2826
import org.apache.solr.client.solrj.response.QueryResponse;
29-
import org.apache.solr.common.SolrException;
3027
import org.apache.solr.common.params.ModifiableSolrParams;
3128
import org.apache.solr.common.params.SolrParams;
3229
import org.apache.solr.common.util.ContentStream;
@@ -36,7 +33,7 @@
3633
* @author Christoph Strobl
3734
* @since 1.4
3835
*/
39-
public class SolrRealtimeGetRequest extends SolrRequest {
36+
public class SolrRealtimeGetRequest extends SolrRequest<QueryResponse> {
4037

4138
private static final long serialVersionUID = 1500782684874146272L;
4239
private Collection<String> ids;
@@ -73,20 +70,7 @@ public Collection<ContentStream> getContentStreams() throws IOException {
7370
}
7471

7572
@Override
76-
public QueryResponse process(SolrServer server) throws SolrServerException, IOException {
77-
78-
try {
79-
long startTime = TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS);
80-
QueryResponse res = new QueryResponse(server.request(this), server);
81-
long endTime = TimeUnit.MILLISECONDS.convert(System.nanoTime(), TimeUnit.NANOSECONDS);
82-
res.setElapsedTime(endTime - startTime);
83-
return res;
84-
} catch (SolrServerException e) {
85-
throw e;
86-
} catch (SolrException s) {
87-
throw s;
88-
} catch (Exception e) {
89-
throw new SolrServerException("Error executing query", e);
90-
}
73+
protected QueryResponse createResponse(SolrClient client) {
74+
return new QueryResponse();
9175
}
9276
}

src/main/java/org/springframework/data/solr/UncategorizedSolrException.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
import org.springframework.dao.UncategorizedDataAccessException;
1919

2020
/**
21-
* SolrServer threw an exception that could not be mapped. UncategorizedSolrException wraps the original Exception
21+
* SolrClient threw an exception that could not be mapped. UncategorizedSolrException wraps the original Exception
2222
*
2323
* @author Christoph Strobl
24-
*
2524
*/
2625
public class UncategorizedSolrException extends UncategorizedDataAccessException {
2726

src/main/java/org/springframework/data/solr/config/SolrNamespaceHandler.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012 the original author or authors.
2+
* Copyright 2012 - 2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@
2121
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
2222
import org.springframework.data.solr.repository.config.SolrRepositoryConfigExtension;
2323
import org.springframework.data.solr.server.config.EmbeddedSolrServerBeanDefinitionParser;
24-
import org.springframework.data.solr.server.config.HttpSolrServerBeanDefinitionParser;
24+
import org.springframework.data.solr.server.config.HttpSolrClientBeanDefinitionParser;
2525

2626
/**
2727
* {@link NamespaceHandler} implementation to register parser for {@code <solr:repositories />},
@@ -44,6 +44,6 @@ public void init() {
4444

4545
registerBeanDefinitionParser("repositories", parser);
4646
registerBeanDefinitionParser("embedded-solr-server", new EmbeddedSolrServerBeanDefinitionParser());
47-
registerBeanDefinitionParser("solr-server", new HttpSolrServerBeanDefinitionParser());
47+
registerBeanDefinitionParser("solr-client", new HttpSolrClientBeanDefinitionParser());
4848
}
4949
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/**
2-
* Spring XML namespace configuration for Solr specific repositories and SolrServer
2+
* Spring XML namespace configuration for Solr specific repositories and SolrClient
33
*/
44
package org.springframework.data.solr.config;

src/main/java/org/springframework/data/solr/core/DefaultQueryParser.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
public class DefaultQueryParser extends QueryParserBase<SolrDataQuery> {
7272

7373
/**
74-
* Convert given Query into a SolrQuery executable via {@link org.apache.solr.client.solrj.SolrServer}
74+
* Convert given Query into a SolrQuery executable via {@link org.apache.solr.client.solrj.SolrClient}
7575
*
7676
* @param query
7777
* @return
@@ -421,19 +421,13 @@ protected void appendFilterQuery(SolrQuery solrQuery, List<FilterQuery> filterQu
421421
* @param solrQuery
422422
* @param sort
423423
*/
424-
@SuppressWarnings("deprecation")
425424
protected void appendSort(SolrQuery solrQuery, Sort sort) {
426425
if (sort == null) {
427426
return;
428427
}
429428

430429
for (Order order : sort) {
431-
// addSort which is to be used instead of addSortField is not available in versions below 4.2.0
432-
if (VersionUtil.isSolr420Available()) {
433-
solrQuery.addSort(order.getProperty(), order.isAscending() ? ORDER.asc : ORDER.desc);
434-
} else {
435-
solrQuery.addSortField(order.getProperty(), order.isAscending() ? ORDER.asc : ORDER.desc);
436-
}
430+
solrQuery.addSort(order.getProperty(), order.isAscending() ? ORDER.asc : ORDER.desc);
437431
}
438432
}
439433

0 commit comments

Comments
 (0)