package org.sports.websearch.contoller;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrQuery.ORDER;
import org.apache.solr.client.solrj.SolrQuery.SortClause;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.impl.XMLResponseParser;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.params.SolrParams;
import org.sports.websearch.model.Article;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/solr")
public class SolrController {

	private SolrServer getSolrServer() {
		String url = "http://localhost:8983/solr/nutch";
		HttpSolrServer server = new HttpSolrServer(url);
		server.setMaxRetries(1); // defaults to 0. > 1 not recommended.
		server.setConnectionTimeout(5000); // 5 seconds to establish TCP
		// Setting the XML response parser is only required for cross
		// version compatibility and only when one side is 1.4.1 or
		// earlier and the other side is 3.1 or later.
		server.setParser(new XMLResponseParser()); // binary parser is used by
													// default
		// The following settings are provided here for completeness.
		// They will not normally be required, and should only be used
		// after consulting javadocs to know whether they are truly required.
		server.setSoTimeout(1000); // socket read timeout
		server.setDefaultMaxConnectionsPerHost(100);
		server.setMaxTotalConnections(100);
		server.setFollowRedirects(false); // defaults to false
		// allowCompression defaults to false.
		// Server side must support gzip or deflate for this to have any effect.
		server.setAllowCompression(true);

		return server;
	}

	@RequestMapping(value = "/{query}", method = RequestMethod.GET)
	public @ResponseBody ResponseEntity<Article> search(
			@RequestParam(value = "query", required = true) String query) {

		SolrServer server = this.getSolrServer();
		SolrQuery solrQuery = new SolrQuery();
		solrQuery.setQuery( query );
//		solrQuery.addSort(new SortClause("tstamp", ORDER.desc));
		
		QueryResponse rsp = null;
		try {
			rsp = server.query( solrQuery );
		} catch (SolrServerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		SolrDocumentList docs = rsp.getResults();
		
		System.out.println(query);
		return null;
	}

}

@@ -49,2692 +49,640 @@
 org.
-apache.solr.client.solrj.SolrQuery;%0Aimport org.apache.solr.client.solrj.SolrQuery.ORDER;%0Aimport org.apache.solr.client.solrj.SolrQuery.SortClause;%0Aimport org.apache.solr.client.solrj.SolrServer;%0Aimport org.apache.solr.client.solrj.SolrServerException;%0Aimport org.apache.solr.client.solrj.impl.HttpSolrServer;%0Aimport org.apache.solr.client.solrj.impl.XMLResponseParser;%0Aimport org.apache.solr.client.solrj.response.QueryResponse;%0Aimport org.apache.solr.common.SolrDocumentList;%0Aimport org.apache.solr.common.params.SolrParams;%0Aimport org.sports.websearch.model.Article;%0Aimport org.springframework.http.ResponseEntity;%0Aimport org.springframework.stereotype.Controller;%0Aimport org.springframework.web.bind.annotation.RequestMapping;%0Aimport org.springframework.web.bind.annotation.RequestMethod;%0Aimport org.springframework.web.bind.annotation.RequestParam;%0Aimport org.springframework.web.bind.annotation.ResponseBody;%0A%0A@Controller%0A@RequestMapping(%22/solr%22)%0Apublic class SolrController %7B%0A%0A%09private SolrServer getSolrServer() %7B%0A%09%09String url = %22http://localhost:8983/solr/nutch%22;%0A%09%09HttpSolrServer server = new HttpSolrServer(url);%0A%09%09server.setMaxRetries(1); // defaults to 0. %3E 1 not recommended.%0A%09%09server.setConnectionTimeout(5000); // 5 seconds to establish TCP%0A%09%09// Setting the XML response parser is only required for cross%0A%09%09// version compatibility and only when one side is 1.4.1 or%0A%09%09// earlier and the other side is 3.1 or later.%0A%09%09server.setParser(new XMLResponseParser()); // binary parser is used by%0A%09%09%09%09%09%09%09%09%09%09%09%09%09// default%0A%09%09// The following settings are provided here for completeness.%0A%09%09// They will not normally be required, and should only be used%0A%09%09// after consulting javadocs to know whether they are truly required.%0A%09%09server.setSoTimeout(1000); // socket read timeout%0A%09%09server.setDefaultMaxConnectionsPerHost(100);%0A%09%09server.setMaxTotalConnections(100);%0A%09%09server.setFollowRedirects(false); // defaults to false%0A%09%09// allowCompression defaults to false.%0A%09%09// Server side must support gzip or deflate for this to have any effect.%0A%09%09server.setAllowCompression(true);%0A%0A%09%09return server;%0A%09%7D%0A%0A%09@RequestMapping(value = %22/%7Bquery%7D%22, method = RequestMethod.GET)%0A%09public @ResponseBody ResponseEntity%3CArticle%3E search(%0A%09%09%09@RequestParam(value = %22query%22, required = true) String query) %7B%0A%0A%09%09SolrServer server = this.getSolrServer();%0A%09%09SolrQuery solrQuery = new SolrQuery();%0A%09%09solrQuery.setQuery( query );%0A//%09%09solrQuery.addSort(new SortClause(%22tstamp%22, ORDER.desc));%0A%09%09%0A%09%09QueryResponse rsp = null;%0A%09%09try %7B%0A%09%09%09rsp = server.query( solrQuery );%0A%09%09%7D catch (SolrServerException e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09SolrDocumentList docs = rsp.getResults();%0A%09%09
+sports.websearch.model.Article;%0Aimport org.springframework.http.ResponseEntity;%0Aimport org.springframework.stereotype.Controller;%0Aimport org.springframework.web.bind.annotation.RequestMapping;%0Aimport org.springframework.web.bind.annotation.RequestMethod;%0Aimport org.springframework.web.bind.annotation.RequestParam;%0Aimport org.springframework.web.bind.annotation.ResponseBody;%0A%0A@Controller%0A@RequestMapping(%22/solr%22)%0Apublic class SolrController %7B%0A%0A%09@RequestMapping(value = %22/%7Bquery%7D%22, method = RequestMethod.GET)%0A%09public @ResponseBody ResponseEntity%3CArticle%3E search(%0A%09%09%09@RequestParam(value = %22query%22, required = true) String query) %7B%0A
 %0A%09%09S

Revert "Added integration and quering with solrj"