0
votes

I am beginner in solr i am trying to query solr from the java application (on play framework). I have included the following jar files to my lib directory

apache-solr-solrj-*.jar
commons-codec-1.3.jar
commons-httpclient-3.1.jar
commons-io-1.4.jar
jcl-over-slf4j-1.5.5.jar
slf4j-api-1.5.5.jar

as instructed in http://www.solrtutorial.com/solrj-tutorial.html

and my code is

import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocumentList;

 public static Result getRecipesAndVariants(String searchString){
    JsonNode jnode = null;
 HttpSolrServer solr = new HttpSolrServer("http://localhost:8983/solr/dbcollection");

SolrQuery query = new SolrQuery();
query.setQuery("fiction");

query.setFields("id","title","author");
query.setStart(0);    
query.set("defType", "edismax");

QueryResponse response = solr.query(query);
SolrDocumentList results = response.getResults();
  for (int i = 0; i < results.size(); ++i) {
  System.out.println("from solr : "+results.get(i));
}

I am getting the error as error: cannot find symbol HttpSolrServer solr = new HttpSolrServer("http://localhost:8983/solr/dbcollection"); Kindly Help please

2
Are you using any IDE, like eclipse? - Sumit Singh
No i am not using any ide - Aswin Raghavan

2 Answers

0
votes

I think the problem is because of your jar file apache-solr-solrj-*.jar You have to add as full name rather using regex.

0
votes

HttpSolrServer is not even part of solrj 1.4 api. I have attached the screenshot from grepcode. Why don't you use the latest or higher version of solrj api. solrj 4.0 contains the HttpSolrServer class.