/**
 * ﻿Copyright (C) 2012
 * by 52 North Initiative for Geospatial Open Source Software GmbH
 *
 * Contact: Andreas Wytzisk
 * 52 North Initiative for Geospatial Open Source Software GmbH
 * Martin-Luther-King-Weg 24
 * 48155 Muenster, Germany
 * info@52north.org
 *
 * This program is free software; you can redistribute and/or modify it under
 * the terms of the GNU General Public License version 2 as published by the
 * Free Software Foundation.
 *
 * This program is distributed WITHOUT ANY WARRANTY; even without the implied
 * WARRANTY OF MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program (see gnu-gpl v2.txt). If not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA or
 * visit the Free Software Foundation web page, http://www.fsf.org.
 */

package org.n52.sir.ds.solr;

/** 
 * @author Yakoub 
 */
import java.io.IOException;

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.response.QueryResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.SolrParams;

public class SolrConnection {

    private SolrServer server;

    public SolrConnection() {
        this.server = new HttpSolrServer(SolrConstants.SOLR_URL);
    }

    public void addInputDocument(SolrInputDocument doc) throws SolrServerException, IOException {
        this.server.add(doc);
    }

    public void commitChanges() throws SolrServerException, IOException {
        this.server.commit();
    }

    public QueryResponse SolrQuery(SolrParams params) throws SolrServerException {
        return this.server.query(params);

    }
    public void deleteSensorWithID(String sensorID) throws SolrServerException, IOException {
    	this.server.deleteByQuery(SolrConstants.ID+":"+sensorID);
    	commitChanges();
    }
    public void deleteByQuery(String query) throws SolrServerException, IOException{
    	this.server.deleteByQuery("*:*");
    	commitChanges();
    }

}

/**
 * ﻿Copyright (C) 2012
 * by 52 North Initiative for Geospatial Open Source Software GmbH
 *
 * Contact: Andreas Wytzisk
 * 52 North Initiative for Geospatial Open Source Software GmbH
 * Martin-Luther-King-Weg 24
 * 48155 Muenster, Germany
 * info@52north.org
 *
 * This program is free software; you can redistribute and/or modify it under
 * the terms of the GNU General Public License version 2 as published by the
 * Free Software Foundation.
 *
 * This program is distributed WITHOUT ANY WARRANTY; even without the implied
 * WARRANTY OF MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program (see gnu-gpl v2.txt). If not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA or
 * visit the Free Software Foundation web page, http://www.fsf.org.
 */

package org.n52.sir.ds.solr;

/** 
 * @author Yakoub 
 */
import java.io.IOException;

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.response.QueryResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.params.SolrParams;

public class SolrConnection {

    private SolrServer server;

    public SolrConnection() {
        this.server = new HttpSolrServer(SolrConstants.SOLR_URL);
    }

    public void addInputDocument(SolrInputDocument doc) throws SolrServerException, IOException {
        this.server.add(doc);
    }

    public void commitChanges() throws SolrServerException, IOException {
        this.server.commit();
    }

    public QueryResponse SolrQuery(SolrParams params) throws SolrServerException {
        return this.server.query(params);

    }
    public void deleteSensorWithID(String sensorID) throws SolrServerException, IOException {
    	this.server.deleteByQuery(SolrConstants.ID+":"+sensorID);
    	commitChanges();
    }
    public void deleteByQuery(String query) throws SolrServerException, IOException{
    	this.server.deleteByQuery(query);
    	commitChanges();
    }

}

delete by query fix