package uk.ac.ebi.quickgo.solr.server;

import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.FacetField.Count;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.TermsResponse.Term;

/**
 * Interface for SolR server processor
 * @author cbonill
 *
 */
public interface SolrServerProcessor {
	
	/**
	 * Run a query in SolR server
	 * @param solRQuery Query to run
	 * @param type Type of the results (ontology, annotation, gene product, ...)
	 * @param numRows Number of rows to retrieve (-1 to set the default value)
	 * @return Results of specified type
	 * @throws SolrServerException SolR exception
	 */
	<T> List<T> findByQuery(SolrQuery solRQuery, Class<T> type, int numRows) throws SolrServerException;
	
	/**
	 * Index a collection of beans in Solr
	 * @param beans Collection of beans to index
	 */
	<T> void indexBeans (Collection<T> beans) throws SolrServerException, IOException;
	
	/**
	 * Index a collection of beans in Solr using auto commit option. To use this
	 * method in the Solr "solrconfig.xml" file you have to enable the
	 * <autoCommit> or <autoSoftCommit> option
	 * 
	 * @param beans
	 *            Collection of beans to index
	 */
	<T> void indexBeansAutoCommit (Collection<T> beans) throws SolrServerException, IOException;
	
	/**
	 * Deletes everything
	 */
	void deleteAll() throws SolrServerException, IOException;
	
	/**
	 * Delete by query
	 * @throws SolrServerException
	 * @throws IOException
	 */
	void deleteByQuery(String query) throws SolrServerException, IOException;
	
	/**
	 * Return total number of documents in the schema for a query
	 * @param query Query
	 * @return Number of documents in the schema
	 */
	long getTotalNumberDocuments(SolrQuery query) throws SolrServerException;
	
	/**
	 * Return total number of distinct values of a field 
	 * @param query Query to run
	 * @param field Field
	 * @return Total number of distinct values of the field
	 * @throws SolrServerException
	 */
	long getTotalNumberDistinctValues(String query, String field) throws SolrServerException;
	
	/**
	 * Return the specified list of fields using the field id as main key
	 * The returned structure is like this: MAP <ID, MAP <FIELD1, VALUE_FIELD1> <FIELD2, VALUE_FIELD2> ...>
	 * @param fields Fields to return
	 */
	Map<String, Map<String, String>> getFields(String query, String fieldID, String fields) throws SolrServerException;
	
	/**
	 * Return the top terms of the whole index
	 * @param solrQuery Query
	 * @return Top terms
	 * @throws SolrServerException 
	 */
	List<Term> getTopTerms(SolrQuery solrQuery) throws SolrServerException;
	
	/**
	 * Return list of facet counts
	 * @param solrQuery Query
	 * @return Map of counts
	 */
	List<Count> getFacetTerms(SolrQuery solrQuery) throws SolrServerException;
	
	/**
	 * Return map with id and total number of values for a specific query using pivot fields
	 * @param solrQuery Query
	 * @return Map of counts
	 */
	Map<String, Integer> getFacetTermsWithPivot(SolrQuery solrQuery) throws SolrServerException;
	
	/**
	 * Run Solr query
	 * @param query Solr query to run
	 * @return Query response
	 * @throws SolrServerException 
	 */
	QueryResponse query(SolrQuery query) throws SolrServerException;
} 
@@ -134,16 +134,45 @@
 til.Map;
+%0Aimport java.util.Properties;
 %0A%0Aimport
@@ -566,18 +566,17 @@
 essor %7B%0A
-%09
 %0A
+
 %09/**%0A%09 *
@@ -975,34 +975,33 @@
 erverException;%0A
-%09
 %0A
+
 %09/**%0A%09 * Index a
@@ -1156,34 +1156,33 @@
 n, IOException;%0A
-%09
 %0A
+
 %09/**%0A%09 * Index a
@@ -1363,17 +1363,16 @@
 tion%0A%09 *
- 
 %0A%09 * @pa
@@ -1516,34 +1516,33 @@
 n, IOException;%0A
-%09
 %0A
+
 %09/**%0A%09 * Deletes
@@ -1609,34 +1609,33 @@
 n, IOException;%0A
-%09
 %0A
+
 %09/**%0A%09 * Delete 
@@ -1771,34 +1771,33 @@
 n, IOException;%0A
-%09
 %0A
+
 %09/**%0A%09 * Return 
@@ -1989,34 +1989,33 @@
 erverException;%0A
-%09
 %0A
+
 %09/**%0A%09 * Return 
@@ -2056,17 +2056,16 @@
  a field
- 
 %0A%09 * @pa
@@ -2287,34 +2287,33 @@
 erverException;%0A
-%09
 %0A
+
 %09/**%0A%09 * Return 
@@ -2626,34 +2626,33 @@
 erverException;%0A
-%09
 %0A
+
 %09/**%0A%09 * Return 
@@ -2760,25 +2760,24 @@
 verException
- 
 %0A%09 */%0A%09List%3C
@@ -2835,34 +2835,33 @@
 erverException;%0A
-%09
 %0A
+
 %09/**%0A%09 * Return 
@@ -3007,34 +3007,33 @@
 erverException;%0A
-%09
 %0A
+
 %09/**%0A%09 * Return 
@@ -3267,10 +3267,9 @@
 on;%0A
-%09
 %0A
+
 %09/**
@@ -3381,17 +3381,16 @@
 xception
- 
 %0A%09 */%0A%09Q
@@ -3457,6 +3457,51 @@
 on;%0A
-%7D 
+%0A%09void setProperties(Properties properties);%0A%7D%0A

Use properties file defined on command line for configuration.