// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java
// public class Result {
// 
//     private final String title;
//     private final String excerpt;
//     private final List<String> categories;
//     private final List<String> speakers;
//     private final Date date;
// 
//     public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) {
//         this.title = title;
//         this.excerpt = excerpt;
//         this.categories = categories;
//         this.speakers = speakers;
//         this.date = date;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public String getExcerpt() {
//         return excerpt;
//     }
// 
//     public List<String> getCategories() {
//         return categories;
//     }
// 
//     public List<String> getSpeakers() {
//         return speakers;
//     }
// 
//     public Date getDate() {
//         return date;
//     }
// }
// 
// Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Facet.java
// public class Facet {
//     
//     private final String term;
//     private final long count;
// 
//     private final String fq;
// 
//     private Facet(String displayTerm, long count, String fq) {
//         this.term = displayTerm;
//         this.count = count;
//         this.fq = fq;
//     }
// 
//     public static Facet termFacet(String term, long count, String fieldname) {
//         return new Facet(term, count, fieldname.concat(":").concat(ClientUtils.escapeQueryChars(term)));
//     }
//     
//     public static Facet withFilterQuery(String term, long count, String fq) {
//         return new Facet(term, count, fq);
//     }
//     
//     public String getTerm() {
//         return term;
//     }
// 
//     public long getCount() {
//         return count;
//     }
// 
//     public String getFq() {
//         return fq;
//     }
// }
// 
// Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java
// public class Faceting {
// 
//     private final List<Facet> categoryFacet;
//     private final List<Facet> speakerFacet;
//     private final List<Facet> dateFacet;
//     private final List<Facet> organizerFacet;
// 
//     public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) {
//         this.categoryFacet = categoryFacet;
//         this.speakerFacet = speakerFacet;
//         this.dateFacet = dateFacet;
//         this.organizerFacet = organizerFacet;
//     }
// 
//     public List<Facet> getCategoryFacet() {
//         return categoryFacet;
//     }
// 
//     public List<Facet> getSpeakerFacet() {
//         return speakerFacet;
//     }
//     
//     public List<Facet> getDateFacet() {
//         return dateFacet;
//     }
// 
//     public List<Facet> getOrganizerFacet() {
//         return organizerFacet;
//     }
// }


import com.google.common.base.Optional;
import de.fhopf.lucenesolrtalk.Result;
import de.fhopf.lucenesolrtalk.web.Facet;
import de.fhopf.lucenesolrtalk.web.Faceting;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.ParseException;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.FacetField;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import java.util.*;
import static java.util.Collections.emptyList;
import org.apache.solr.client.solrj.response.RangeFacet;
import org.apache.solr.common.util.DateUtil;
package de.fhopf.lucenesolrtalk.web.solr;




public class SolrSearcher {

    private final SolrServer solrServer;

    public SolrSearcher(SolrServer solrServer) {
        this.solrServer = solrServer;
    }

    public List<String> getAllCategories() {
        return emptyList();
    }

    public SolrSearchResult search(Optional<String> query, Set<String> fq) throws SolrServerException {

        if (query.isPresent()) {
            SolrQuery solrQuery = new SolrQuery(query.get());
            solrQuery.setRequestHandler("/jugka");
            for (String filter : fq) {
                solrQuery.addFilterQuery(filter);
            }
            QueryResponse response = solrServer.query(solrQuery);

            // TODO move to a function?
// Path: lucene/src/main/java/de/fhopf/lucenesolrtalk/Result.java
// public class Result {
// 
//     private final String title;
//     private final String excerpt;
//     private final List<String> categories;
//     private final List<String> speakers;
//     private final Date date;
// 
//     public Result(String title, String excerpt, List<String> categories, List<String> speakers, Date date) {
//         this.title = title;
//         this.excerpt = excerpt;
//         this.categories = categories;
//         this.speakers = speakers;
//         this.date = date;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public String getExcerpt() {
//         return excerpt;
//     }
// 
//     public List<String> getCategories() {
//         return categories;
//     }
// 
//     public List<String> getSpeakers() {
//         return speakers;
//     }
// 
//     public Date getDate() {
//         return date;
//     }
// }
// 
// Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Facet.java
// public class Facet {
//     
//     private final String term;
//     private final long count;
// 
//     private final String fq;
// 
//     private Facet(String displayTerm, long count, String fq) {
//         this.term = displayTerm;
//         this.count = count;
//         this.fq = fq;
//     }
// 
//     public static Facet termFacet(String term, long count, String fieldname) {
//         return new Facet(term, count, fieldname.concat(":").concat(ClientUtils.escapeQueryChars(term)));
//     }
//     
//     public static Facet withFilterQuery(String term, long count, String fq) {
//         return new Facet(term, count, fq);
//     }
//     
//     public String getTerm() {
//         return term;
//     }
// 
//     public long getCount() {
//         return count;
//     }
// 
//     public String getFq() {
//         return fq;
//     }
// }
// 
// Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/Faceting.java
// public class Faceting {
// 
//     private final List<Facet> categoryFacet;
//     private final List<Facet> speakerFacet;
//     private final List<Facet> dateFacet;
//     private final List<Facet> organizerFacet;
// 
//     public Faceting(List<Facet> categoryFacet, List<Facet> speakerFacet, List<Facet> dateFacet, List<Facet> organizerFacet) {
//         this.categoryFacet = categoryFacet;
//         this.speakerFacet = speakerFacet;
//         this.dateFacet = dateFacet;
//         this.organizerFacet = organizerFacet;
//     }
// 
//     public List<Facet> getCategoryFacet() {
//         return categoryFacet;
//     }
// 
//     public List<Facet> getSpeakerFacet() {
//         return speakerFacet;
//     }
//     
//     public List<Facet> getDateFacet() {
//         return dateFacet;
//     }
// 
//     public List<Facet> getOrganizerFacet() {
//         return organizerFacet;
//     }
// }


// Path: web/src/main/java/de/fhopf/lucenesolrtalk/web/solr/SolrSearcher.java
import com.google.common.base.Optional;
import de.fhopf.lucenesolrtalk.Result;
import de.fhopf.lucenesolrtalk.web.Facet;
import de.fhopf.lucenesolrtalk.web.Faceting;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.ParseException;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.FacetField;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import java.util.*;
import static java.util.Collections.emptyList;
import org.apache.solr.client.solrj.response.RangeFacet;
import org.apache.solr.common.util.DateUtil;

package de.fhopf.lucenesolrtalk.web.solr;




public class SolrSearcher {

    private final SolrServer solrServer;

    public SolrSearcher(SolrServer solrServer) {
        this.solrServer = solrServer;
    }

    public List<String> getAllCategories() {
        return emptyList();
    }

    public SolrSearchResult search(Optional<String> query, Set<String> fq) throws SolrServerException {

        if (query.isPresent()) {
            SolrQuery solrQuery = new SolrQuery(query.get());
            solrQuery.setRequestHandler("/jugka");
            for (String filter : fq) {
                solrQuery.addFilterQuery(filter);
            }
            QueryResponse response = solrServer.query(solrQuery);

            // TODO move to a function?
            List<Result> results = new ArrayList<Result>();