I am developing a web application. I use spring mvc framework , cassandra and solr. I use standalone solr, not solr cloud. I use solr as a fulltext retrieval tool. I am
As I see, you change baseUrl in your code. As you said in comments, you query multiple cores at the same page, and all of them use the same HttpSolrServer. So it seems to be a lack of synchronization in your solution, and that there could be two requests running at the same time, and one request quering the ‘core’ of another.
Of course, you could synchronize your method. But I think, that in your case it is better not to twitch HttpSolrServer each time, but to set additional parameter to your query, that will be used as additional path to your baseUrl. You will need to set baseUrl for HttpSolrServer once at creation time:
HttpSolrServer solrHttpServer = new HttpSolrServer(baseUrl);
and instead of changing it for each query you will set parameter (diff for your code):
String queryExpression = "*:*";
String sortField = "createTime";
-String baseUrl = SolrUtil.getSolrBaseURL(solrHttpServer.getBaseURL());
-solrHttpServer.setBaseURL(baseUrl + "/" + coreName);
SolrQuery query = new SolrQuery();
+query.set(CommonParams.QT, "/" + coreName + "/select");
query.setQuery(queryExpression);
query.setSortField(sortField, SolrQuery.ORDER.asc);
QueryResponse rsp = solrHttpServer.query(query);
But the best solution is to have separate HttpSolrServer for each core:
Map servers = new HashMap();
servers.put(coreName1, new HttpSolrServer(baseUrl + "/" + coreName1));
...
Resulting code changes:
String queryExpression = "*:*";
String sortField = "createTime";
-String baseUrl = SolrUtil.getSolrBaseURL(solrHttpServer.getBaseURL());
-solrHttpServer.setBaseURL(baseUrl + "/" + coreName);
SolrQuery query = new SolrQuery();
query.setQuery(queryExpression);
query.setSortField(sortField, SolrQuery.ORDER.asc);
-QueryResponse rsp = solrHttpServer.query(query);
+QueryResponse rsp = servers.get(coreName).query(query);