Package org.apache.solr.client.solrj.impl

Examples of org.apache.solr.client.solrj.impl.CommonsHttpSolrServer


            authPrefs.add(AuthPolicy.BASIC);
            // This will exclude the NTLM authentication scheme
            client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs);
            client.getParams().setAuthenticationPreemptive(true);
            try {
                this.server = new CommonsHttpSolrServer("http://" + this.host + ":" + this.port + this.solrpath, client);
            } catch (final MalformedURLException e) {
                throw new IOException("bad auth connector url: " + this.solrurl);
            }
        } else {
            try {
                this.server = new CommonsHttpSolrServer(this.solrurl);
            } catch (final MalformedURLException e) {
                throw new IOException("bad connector url: " + this.solrurl);
            }
        }
View Full Code Here


                        localShards.add(subIndex);
                    }
                    else
                    {
                        // delete from other shards via http
                        CommonsHttpSolrServer solrj = new CommonsHttpSolrServer("http://" + addr.getHostAddress()
                                + ":8983/solandra/" + subIndex, new HttpClient(httpConnections));

                        try
                        {
                            solrj.deleteByQuery(cmd.query);
                        }
                        catch (SolrServerException e)
                        {
                            throw new IOException(e);
                        }
View Full Code Here

    testSolrCustomField(url, customFieldKey);
  }

  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);
View Full Code Here

      }
    }
  }

  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);

View Full Code Here

    super.setUp();
    File home = new File(getSolrHome());
    runner = createJetty(home, "target/solrjtest-data");
    port = runner.getLocalPort();
   
    solr = new CommonsHttpSolrServer(new URL("http://localhost:" + port + "/solr"));
    //clean out all the docs
    solr.deleteByQuery("*:*");
    solr.commit();

    System.out.println("NOTE: The Solr Server must be running on port 8983!!!!!!!!");
View Full Code Here

            "acccused Mr. Tortoise of doping, in what has become an " +
            "all too familiar scene in sporting events today.  " +
            "Fans everywhere were appalled by the revelations, with " +
            "allegiances falling roughly along species lines.";
    //<start id="solrj"/>
    SolrServer solr = new CommonsHttpSolrServer(new URL("http://localhost:" + port + "/solr"));//<co id="co.solrj.server"/>
    SolrInputDocument doc = new SolrInputDocument();
    doc.addField("id", "http://tortoisehare5k.tamingtext.com");//<co id="co.solrj.unique"/>
    doc.addField("mimeType", "text/plain");
    doc.addField("title", "Tortoise beats Hare!  Hare wants rematch.", 5);//<co id="co.solrj.title"/>
    Date now = new Date();
    doc.addField("date", DateUtil.getThreadLocalDateFormat().format(now));//<co id="co.solrj.date"/>
    doc.addField("description", description);
    doc.addField("categories_t", "Fairy Tale, Sports");//<co id="co.solrj.dynamic.field"/>
    solr.add(doc);//<co id="co.solrj.add"/>
    solr.commit();//<co id="co.solrj.commit"/>
    /*
    <calloutlist>
    <callout arearefs="co.solrj.server"><para>Create a HTTP-based Solr Server connection.</para></callout>
      <callout arearefs="co.solrj.unique"><para>The schema used for this instance of Solr requires a unique field named "id"</para></callout>
      <callout arearefs="co.solrj.title"><para>Add a Title field to our document and boost it to be 5 times as important as the other fields</para></callout>
      <callout arearefs="co.solrj.date"><para>Dates must be formatted in a specific way for Solr.</para></callout>
      <callout arearefs="co.solrj.dynamic.field"><para>A dynamic field allows for the addition of unknown fields to Solr.  The "_t" tells Solr this should be treated as a text field.</para></callout>
      <callout arearefs="co.solrj.add"><para>Send the newly created document to Solr.  Solr takes care of creating a correctly formatted XML message and sending it to Solr using Apache Jakarta Commons HTTPClient.</para></callout>
      <callout arearefs="co.solrj.commit"><para>After you have added all your documents and wish to make them available for searching, send a commit message to Solr</para></callout>
    </calloutlist>
    */
    //<end id="solrj"/>
    //Add some more docs
    doc = new SolrInputDocument();//<co id="co.solrj.doc"/>
    doc.addField("id", "http://redfox.tamingtext.com");//<co id="co.solrj.unique"/>
    doc.addField("mimeType", "text/plain");//<co id="co.solrj.mime"/>
    doc.addField("title", "Red Fox mocks Lazy Brown Dogs!", 5);//<co id="co.solrj.title"/>
    now = new Date();
    doc.addField("date", DateUtil.getThreadLocalDateFormat().format(now));
    doc.addField("description", "Once again, the Red Fox outshined the" +
            " lazy Brown Dogs to win the vaunted Tally Ho Cup, in what" +
            " has become an annual ritual.  The lazy brown " +
            "dogs just don't seem to have the drive that Red Fox does." +
            "  The lazy Brown Dogs vow to avenge their latest defeat, " +
            "but the group's supporters claim to have heard it all before.");
    doc.addField("categories_t", "Fairy Tale, Sports");
    solr.add(doc);//<co id="co.solrj.add"/>
    doc = new SolrInputDocument();//<co id="co.solrj.doc"/>
    doc.addField("id", "http://maryLambs.tamingtext.com");//<co id="co.solrj.unique"/>
    doc.addField("mimeType", "text/plain");//<co id="co.solrj.mime"/>

    now = new Date(10000);
    doc.addField("date", DateUtil.getThreadLocalDateFormat().format(now));
    doc.addField("title", "Mary's Little Lamb Stolen!.", 5);//<co id="co.solrj.title"/>
    doc.addField("description", "In an affront to all that is good and" +
            " decent in this world, criminals made off with Mary's " +
            "little Lamb in a late night raid on Mary's farm." +
            "  Early suspects include a Ms. Bo Peep who weeks earlier " +
            "reported losing several sheep.  Police suspect Ms. Peep " +
            "was going to use the lamb to bring her flock's numbers back up." +
            "  The spokesman for Ms. Peep declined comment at this " +
            "time.  Mary, however, was outraged and promises revenge " +
            "on the insensitive clod who stole her precious animals.");
    doc.addField("categories_t", "Fairy Tale, crime, sheep");
    solr.add(doc);
    //add in some random other docs
    Collection<SolrInputDocument> docs = new HashSet<SolrInputDocument>();
    for (int i = 0; i < 100; i++) {
      doc = new SolrInputDocument();
      doc.addField("id", "http://www.tamingtext.com/" + i + ".html");
      doc.addField("mimeType", "text/html");
      doc.addField("title", "This is title " + i);
      now = new Date(150 * i + i + 20);//create some dates
      doc.addField("date", DateUtil.getThreadLocalDateFormat().format(now));
      doc.addField("description", "This is description number: " + i
              + " of something that is very important.");
      docs.add(doc);
    }

    solr.add(docs);
    solr.commit();
    solr.optimize();
    //<start id="solrj-search-1"/>
    SolrQuery queryParams = new SolrQuery();//<co id="solrj-search.co.query"/>
    queryParams.setFields("description", "title");//<co id="solrj-search.co.fields"/>
    queryParams.setQuery("description:win OR description:all");//<co id="solrj-search.co.terms"/>
    queryParams.setRows(10);
    QueryResponse response = solr.query(queryParams);//<co id="solrj-search.co.process"/>
    assertTrue("response is null and it shouldn't be", response != null);
    SolrDocumentList documentList = response.getResults();
    System.out.println("Docs: " + documentList);
    assertTrue("response.getResults() Size: " + documentList.size() +
            " is not: " + 3, documentList.size() == 3);
    /*
<calloutlist>
    <callout arearefs="solrj-search.co.query"><para>A <classname>SolrQuery</classname> is a easy-to-use container for creating the most common types of queries.</para></callout>
    <callout arearefs="solrj-search.co.fields"><para>Set the names of the Fields to be returned in the documents.</para></callout>
    <callout arearefs="solrj-search.co.terms"><para>Set the terms to search.  The "OR" is a boolean operator which allows one or the other or both to be present in the query.</para></callout>
    <callout arearefs="solrj-search.co.process"><para>Submit the query to Solr and get back a <classname>QueryResponse</classname> which contains the results of the search.</para></callout>

</calloutlist>
*/
    //<end id="solrj-search-1"/>

    //<start id="solrj-search-dismax"/>
    queryParams.setQuery("lazy");
    queryParams.setParam("defType", "dismax");//<co id="solrj-search.co.dismax"/>
    queryParams.set("qf", "title^3 description^10");//<co id="sorlj-search.co.qf"/>
    System.out.println("Query: " + queryParams);
    response = solr.query(queryParams);
    assertTrue("response is null and it shouldn't be", response != null);
    documentList = response.getResults();
    assertTrue("documentList Size: " + documentList.size() +
            " is not: " + 2, documentList.size() == 2);
/*
<calloutlist>
    <callout arearefs="solrj-search.co.dismax"><para>Tell Solr to use the <classname>DisMax</classname> Query Parser (named dismax in solrconfig.xml). </para></callout>
    <callout arearefs="sorlj-search.co.qf"><para>The DisMax parser will search across the fields given by the "qf" parameter and boosts the terms accordingly.</para></callout>

</calloutlist>
*/
    //<end id="solrj-search-dismax"/>

    //<start id="solrj-search-facets"/>
    queryParams = new SolrQuery();
    queryParams.setQuery("description:number");
    queryParams.setRows(10);
    queryParams.setFacet(true);//<co id="solrj-search-facets-facetOn"/>
    queryParams.set("facet.field", "date");//<co id="solrj-search-facets-date"/>
    response = solr.query(queryParams);
    assertTrue("response is null and it shouldn't be", response != null);
    System.out.println("Query: " + queryParams);
    documentList = response.getResults();
    assertTrue("documentList Size: " + documentList.size() +
            " is not: " + 10, documentList.size() == 10);
    System.out.println("Facet Response: " + response.getResponse());//<co id="solrj-search-facets-print"/>
    /*
<calloutlist>
  <callout arearefs="solrj-search-facets-facetOn"><para>Turn on faceting for this query</para></callout>
  <callout arearefs="solrj-search-facets-date"><para>Specify the Field to facet on</para></callout>
  <callout arearefs="solrj-search-facets-print"><para>Print out the facet information</para></callout>

</calloutlist>
*/
    //<end id="solrj-search-facets"/>
    //<start id="solrj-search-more-like-this"/>
    queryParams = new SolrQuery();
    queryParams.setQueryType("/mlt");//<co id="solrj-search.co.mlt"/>
    queryParams.setQuery("description:number");
    queryParams.set("mlt.match.offset", "0");//<co id="solrj-search.co.mlt.off"/>
    queryParams.setRows(1);
    queryParams.set("mlt.fl", "description, title");//<co id="solrj-search.co.mlt.fl"/>
    response = solr.query(queryParams);
    assertTrue("response is null and it shouldn't be", response != null);
    SolrDocumentList results = (SolrDocumentList) response.getResponse().get("match");
    assertTrue("results Size: " + results.size() + " is not: " + 1,
            results.size() == 1);
    /*
 
View Full Code Here

        String url = "http://" + shardparams[0];
        try {
          params.set("__higo_ms_depth__", (depth+1));
           HttpCommComponent.setupParams(params, shardparams);
         HttpClient cli =HttpCommComponent.makeHttpClient();
           SolrServer server = new CommonsHttpSolrServer(url, cli);
       
           QueryRequest req = new QueryRequest(params);
           req.setMethod(SolrRequest.METHOD.POST);
           ssr.nl = server.request(req);
           cli.getHttpConnectionManager().closeIdleConnections(0);
          
           Map<String,String> timetaken=(Map<String,String>) ssr.nl.get("mdrill_shard_time");
           if(timetaken==null)
           {
View Full Code Here

   
    SolrServerException error = new SolrServerException("checkSolrRecord");
    for (int i = 0; i < 3; i++) {
      try {
        int port = getLocalPort();
        CommonsHttpSolrServer server = new CommonsHttpSolrServer(
            "http://localhost:" + port + context);
        server.setConnectionManagerTimeout(60000000l);
        server.setSoTimeout(60000000);
          server.setConnectionTimeout(100000);
          server.setDefaultMaxConnectionsPerHost(100);
          server.setMaxTotalConnections(100);
          server.setFollowRedirects(false);
          server.setAllowCompression(true);
          server.setMaxRetries(1);
        server.setRequestWriter(new BinaryRequestWriter());
        SolrQuery query = new SolrQuery();
        query.setParam("start", "0");
        if (newestPartion != null && !newestPartion.isEmpty()) {
          query.setParam(CommonParams.PARTION, newestPartion);
        }

       
        if(day!=null&&!day.isEmpty()&&!day.equals(newestPartion))
        {
          query.addFilterQuery("thedate:"+day);
        }
        query.setParam(CommonParams.HIGOHB,true);
        query.setParam("mlogtime", fmt.format(new Date()));

        query.setParam("rows", "0");
        query.setQuery("*:*");
        QueryResponse qr3 = server.query(query);
        SolrDocumentList result3 = qr3.getResults();
        if(result3!=null)
        {
          return result3.getNumFound();
        }else{
View Full Code Here

  }
 
 
  public static CommonsHttpSolrServer makeServer(GetPartions.Shards shard) throws MalformedURLException
  {
    CommonsHttpSolrServer server = new CommonsHttpSolrServer(shard.urlMain);
    server.setConnectionManagerTimeout(60000000l);
    server.setSoTimeout(60000000);
      server.setConnectionTimeout(100000);
      server.setDefaultMaxConnectionsPerHost(100);
      server.setMaxTotalConnections(100);
      server.setFollowRedirects(false);
      server.setAllowCompression(true);
      server.setMaxRetries(1);
    server.setRequestWriter(new BinaryRequestWriter());
    return server;
  }
View Full Code Here

public class MovieMatcher {

 
 
  public MovieMatcher() throws MalformedURLException {
    solr = new CommonsHttpSolrServer(new URL("http://localhost:8983/solr"));
    query = new SolrQuery();
    query.setRows(10);
  }
View Full Code Here

TOP

Related Classes of org.apache.solr.client.solrj.impl.CommonsHttpSolrServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.