Search in sources :

Example 1 with CommonsHttpSolrServer

use of org.apache.solr.client.solrj.impl.CommonsHttpSolrServer in project Solbase by Photobucket.

the class SolbaseIndexWriter method main.

public static void main(String[] args) {
    try {
        @SuppressWarnings("deprecation") CommonsHttpSolrServer // using seperate connector to leverage different http thread pool for updates
        solbaseServer = new CommonsHttpSolrServer("http://den2sch21:8080/solbase/pbimages~4");
        /*
			doc.addField("docId", docNumber);
			doc.addField("global_uniq_id", globalId);
			doc.addField("title", "tom");
			doc.addField("description", "Uploaded with Snapbucket");
			doc.addField("tags", "Snapbucket");
			doc.addField("path", "/albums/tt262/koh_tester/309AB021-orig.jpg");
			doc.addField("subdomain", "i618");
			doc.addField("lastModified", new Integer(SolbaseUtil.getEpochSinceSolbase(System.currentTimeMillis() / 60000)).toString());
			doc.addField("media_type", new Integer(1).toString());
			doc.addField("total_view_count", new Long(10).toString());
			doc.addField("sevendays_view_count", new Integer(5).toString());
			doc.addField("total_likes_count", new Long(5).toString());
			doc.addField("sevendays_likes_count", new Integer(1).toString());
			doc.addField("total_comments_count", new Long(5).toString());
			doc.addField("sevendays_comments_count", new Integer(1).toString());
			doc.addField("contents", "audi tom solbase Uploaded with Snapbucket ");
			// whether we want to store to hbase or not
			doc.addField("updateStore", true);
			
			solbaseServer.add(doc);

	*/
        // for delete only
        List<String> ids = new ArrayList<String>();
        // term vector didn't get deleted doc id
        ids.add(127995479 + "");
        // term vector did get deleted doc id
        ids.add(134876977 + "");
        solbaseServer.deleteById(ids, true);
    } catch (MalformedURLException e) {
    } catch (SolrServerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : CommonsHttpSolrServer(org.apache.solr.client.solrj.impl.CommonsHttpSolrServer) MalformedURLException(java.net.MalformedURLException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 2 with CommonsHttpSolrServer

use of org.apache.solr.client.solrj.impl.CommonsHttpSolrServer in project platformlayer by platformlayer.

the class ITSolrService method testSolrCustomField.

private void testSolrCustomField(String url, String field) throws SolrServerException, IOException {
    CommonsHttpSolrServer client = new CommonsHttpSolrServer(url);
    int docCount = 10;
    List<String> fieldValues = Lists.newArrayList();
    // Add some documents
    {
        for (int i = 0; i < docCount; i++) {
            SolrInputDocument doc = new SolrInputDocument();
            doc.addField("id", i);
            doc.addField("value_i", i);
            String fieldValue = random.randomText(40, 2000);
            doc.addField(field, fieldValue);
            fieldValues.add(fieldValue);
            client.add(doc);
        }
        client.commit();
    }
    // Query the documents
    {
        SolrQuery query = new SolrQuery();
        query.setQuery("value_i:[* TO 9]");
        query.addSortField("value_i", SolrQuery.ORDER.asc);
        query.setRows(Integer.MAX_VALUE);
        QueryResponse response = client.query(query);
        SolrDocumentList results = response.getResults();
        Assert.assertEquals(results.getNumFound(), 10);
        for (int i = 0; i < results.size(); i++) {
            SolrDocument doc = results.get(i);
            int docId = i;
            Assert.assertEquals(doc.get("id"), String.valueOf(docId));
            Assert.assertEquals(doc.get("value_i"), docId);
            Assert.assertEquals(doc.get(field), fieldValues.get(i));
        }
    }
}
Also used : CommonsHttpSolrServer(org.apache.solr.client.solrj.impl.CommonsHttpSolrServer) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 3 with CommonsHttpSolrServer

use of org.apache.solr.client.solrj.impl.CommonsHttpSolrServer in project platformlayer by platformlayer.

the class ITSolrService method testSolr.

private void testSolr(String url) throws SolrServerException, IOException {
    CommonsHttpSolrServer client = new CommonsHttpSolrServer(url);
    int docCount = 1000;
    // Add some documents
    {
        for (int i = 0; i < docCount; i++) {
            SolrInputDocument doc = new SolrInputDocument();
            doc.addField("id", i);
            doc.addField("name_t", "document" + i);
            doc.addField("value_i", i);
            doc.addField("units_i", i % 10);
            doc.addField("content_t", random.randomText(40, 2000));
            client.add(doc);
        }
        client.commit();
    }
    // Query the documents
    {
        SolrQuery query = new SolrQuery();
        query.setQuery("units_i:2");
        query.addSortField("value_i", SolrQuery.ORDER.asc);
        query.setRows(Integer.MAX_VALUE);
        QueryResponse response = client.query(query);
        SolrDocumentList results = response.getResults();
        Assert.assertEquals(results.getNumFound(), docCount / 10);
        for (int i = 0; i < results.size(); i++) {
            SolrDocument doc = results.get(i);
            int docId = (i * 10) + 2;
            Assert.assertEquals(doc.get("id"), String.valueOf(docId));
            Assert.assertEquals(doc.get("units_i"), 2);
            Assert.assertEquals(doc.get("name_t"), "document" + docId);
        }
    }
}
Also used : CommonsHttpSolrServer(org.apache.solr.client.solrj.impl.CommonsHttpSolrServer) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 4 with CommonsHttpSolrServer

use of org.apache.solr.client.solrj.impl.CommonsHttpSolrServer in project opencast by opencast.

the class SolrServerFactory method newRemoteInstance.

/**
 * Constructor. Prepares solr connection.
 *
 * @param url
 *          the connection url to the solr server
 */
public static SolrServer newRemoteInstance(URL url) {
    try {
        CommonsHttpSolrServer server = new CommonsHttpSolrServer(url);
        server.setSoTimeout(5000);
        server.setConnectionTimeout(5000);
        server.setDefaultMaxConnectionsPerHost(100);
        server.setMaxTotalConnections(100);
        // defaults to false
        server.setFollowRedirects(false);
        server.setAllowCompression(true);
        // defaults to 0. > 1 not recommended.
        server.setMaxRetries(1);
        // binary parser is used by default
        server.setParser(new XMLResponseParser());
        return server;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : CommonsHttpSolrServer(org.apache.solr.client.solrj.impl.CommonsHttpSolrServer) XMLResponseParser(org.apache.solr.client.solrj.impl.XMLResponseParser) SolrServerException(org.apache.solr.client.solrj.SolrServerException)

Example 5 with CommonsHttpSolrServer

use of org.apache.solr.client.solrj.impl.CommonsHttpSolrServer in project play-cookbook by spinscale.

the class SolrSearchTest method setup.

@Before
public void setup() throws Exception {
    Fixtures.deleteAllModels();
    server = new CommonsHttpSolrServer("http://localhost:8983/solr");
    server.setRequestWriter(new BinaryRequestWriter());
    clearSolrServerIndex();
    Fixtures.loadModels("test-data.yml");
}
Also used : CommonsHttpSolrServer(org.apache.solr.client.solrj.impl.CommonsHttpSolrServer) BinaryRequestWriter(org.apache.solr.client.solrj.impl.BinaryRequestWriter) Before(org.junit.Before)

Aggregations

CommonsHttpSolrServer (org.apache.solr.client.solrj.impl.CommonsHttpSolrServer)8 SolrInputDocument (org.apache.solr.common.SolrInputDocument)4 MalformedURLException (java.net.MalformedURLException)3 SolrQuery (org.apache.solr.client.solrj.SolrQuery)3 SolrServerException (org.apache.solr.client.solrj.SolrServerException)3 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)3 SolrDocument (org.apache.solr.common.SolrDocument)3 SolrDocumentList (org.apache.solr.common.SolrDocumentList)3 IOException (java.io.IOException)2 BinaryRequestWriter (org.apache.solr.client.solrj.impl.BinaryRequestWriter)2 ArrayList (java.util.ArrayList)1 StringTokenizer (java.util.StringTokenizer)1 Get (org.apache.hadoop.hbase.client.Get)1 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)1 Result (org.apache.hadoop.hbase.client.Result)1 XMLResponseParser (org.apache.solr.client.solrj.impl.XMLResponseParser)1 Cluster (org.apache.whirr.Cluster)1 Before (org.junit.Before)1 Test (org.junit.Test)1