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

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


      _files = files;
    }
   
    public void run()
    {
      _server = new HttpSolrServer(
          "http://localhost:8983/solr/");
      _server.setMaxRetries(5);
     
      int i = 0;
           
View Full Code Here


    public SolrEndpoint(String endpointUri, SolrComponent component, String address, Map<String, Object> parameters) throws Exception {
        super(endpointUri, component);
        // check the url address
        URL url = new URL("http://" + address);
        solrServer = new HttpSolrServer(url.toString());
        streamingQueueSize = getIntFromString((String) parameters.get(SolrConstants.PARAM_STREAMING_QUEUE_SIZE), SolrConstants.DEFUALT_STREAMING_QUEUE_SIZE);
        streamingThreadCount = getIntFromString((String) parameters.get(SolrConstants.PARAM_STREAMING_THREAD_COUNT), SolrConstants.DEFAULT_STREAMING_THREAD_COUNT);
        streamingSolrServer = new ConcurrentUpdateSolrServer(url.toString(), streamingQueueSize, streamingThreadCount);
    }
View Full Code Here

            UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
            if (urlValidator.isValid(solrService)||ConfigurationManager.getBooleanProperty("discovery","solr.url.validation.enabled",true))
            {
                try {
                    log.debug("Solr URL: " + solrService);
                    solr = new HttpSolrServer(solrService);

                    solr.setBaseURL(solrService);
                    solr.setUseMultiPartPost(true);
                    SolrQuery solrQuery = new SolrQuery()
                            .setQuery("search.resourcetype:2 AND search.resourceid:1");
View Full Code Here

            yearQueryParams.put(CommonParams.FQ, filterQuery.toString());
            yearQueryParams.put(CommonParams.WT, "csv");

            //Start by creating a new core
            String coreName = "statistics-" + dcStart.getYear();
            HttpSolrServer statisticsYearServer = createCore(solr, coreName);

            System.out.println("Moving: " + totalRecords + " into core " + coreName);
            log.info("Moving: " + totalRecords + " records into core " + coreName);

            List<File> filesToUpload = new ArrayList<File>();
            for(int i = 0; i < totalRecords; i+=10000){
                String solrRequestUrl = solr.getBaseURL() + "/select";
                solrRequestUrl = generateURL(solrRequestUrl, yearQueryParams);

                HttpGet get = new HttpGet(solrRequestUrl);
                HttpResponse response = new DefaultHttpClient().execute(get);
                InputStream csvInputstream = response.getEntity().getContent();
                //Write the csv ouput to a file !
                File csvFile = new File(tempDirectory.getPath() + File.separatorChar + "temp." + dcStart.getYear() + "." + i + ".csv");
                FileUtils.copyInputStreamToFile(csvInputstream, csvFile);
                filesToUpload.add(csvFile);

                //Add 10000 & start over again
                yearQueryParams.put(CommonParams.START, String.valueOf((i + 10000)));
            }

            for (File tempCsv : filesToUpload) {
                //Upload the data in the csv files to our new solr core
                ContentStreamUpdateRequest contentStreamUpdateRequest = new ContentStreamUpdateRequest("/update/csv");
                contentStreamUpdateRequest.setParam("stream.contentType", "text/plain;charset=utf-8");
                contentStreamUpdateRequest.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                contentStreamUpdateRequest.addFile(tempCsv, "text/plain;charset=utf-8");

                statisticsYearServer.request(contentStreamUpdateRequest);
            }
            statisticsYearServer.commit(true, true);


            //Delete contents of this year from our year query !
            solr.deleteByQuery(filterQuery.toString());
            solr.commit(true, true);
View Full Code Here

        String baseSolrUrl = solr.getBaseURL().replace("statistics", "");
        CoreAdminRequest.Create create = new CoreAdminRequest.Create();
        create.setCoreName(coreName);
        create.setInstanceDir("statistics");
        create.setDataDir(solrDir + coreName + File.separator + "data");
        HttpSolrServer solrServer = new HttpSolrServer(baseSolrUrl);
        create.process(solrServer);
        log.info("Created core with name: " + coreName);
        return new HttpSolrServer(baseSolrUrl + "/" + coreName);
    }
View Full Code Here

    epersonEndId *= 4;

    // We got all our parameters now get the rest
    Context context = new Context();
    // Find our solr server
    HttpSolrServer solr = new HttpSolrServer(
        ConfigurationManager.getProperty("solr-statistics", "server"));
    solr.deleteByQuery("*:*");
    solr.commit();

    String prevIp = null;
    String dbfile = ConfigurationManager.getProperty("usage-statistics", "dbfile");
    LookupService cl = new LookupService(dbfile,
        LookupService.GEOIP_STANDARD);
    int countryErrors = 0;
    for (int i = 0; i < nrLogs; i++) {
      String ip = "";
      Date time;
      String continent;
      String countryCode;
      float longitude;
      float latitude;
      String city;

      // 1. Generate an ip for our user
            StringBuilder ipBuilder = new StringBuilder();
      for (int j = 0; j < 4; j++) {
        ipBuilder.append(getRandomNumberInRange(0, 254));
        if (j != 3)
                {
                    ipBuilder.append(".");
                }
      }
            ip = ipBuilder.toString();
           
      // 2 Depending on our ip get all the location info
      Location location;
      try {
        location = cl.getLocation(ip);
      } catch (Exception e) {
        location = null;
      }
      if (location == null) {
        // If we haven't got a prev ip this is pretty useless so move on
        // to the next one
        if (prevIp == null)
                {
                    continue;
                }
        ip = prevIp;
        location = cl.getLocation(ip);
      }

      city = location.city;
      countryCode = location.countryCode;
      longitude = location.longitude;
      latitude = location.latitude;
      try {
        continent = LocationUtils.getContinentCode(countryCode);
      } catch (Exception e) {
        // We could get an error if our country == Europa this doesn't
        // matter for generating statistics so ignore it
        System.out.println("COUNTRY ERROR: " + countryCode);
        countryErrors++;
        continue;
      }

      // 3. Generate a date that the object was visited
      time = new Date(getRandomNumberInRange(startDate, endDate));

      // 4. Get our dspaceobject we are supposed to be working on
      // We got mostly item views so lets say we got 1/2 chance that we
      // got an item view
      // What type have we got (PS: I know we haven't got 5 as a dso type
      // we can log but it is used so our item gets move traffic)
      int type = (int) getRandomNumberInRange(0, 8);
      if (type == Constants.BUNDLE || type >= 5)
            {
                type = Constants.ITEM;
            }

      int dsoId = -1;
      // Now we need to find a valid id
      switch (type) {
      case Constants.COMMUNITY:
        dsoId = (int) getRandomNumberInRange(commStartId, commEndId);
        break;
      case Constants.COLLECTION:
        dsoId = (int) getRandomNumberInRange(collStartId, collEndId);
        break;
      case Constants.ITEM:
        dsoId = (int) getRandomNumberInRange(itemStartId, itemEndId);
        break;
      case Constants.BITSTREAM:
        dsoId = (int) getRandomNumberInRange(bitStartId, bitEndId);
        break;
      }
      // Now find our dso
      DSpaceObject dso = DSpaceObject.find(context, type, dsoId);
      if (dso instanceof Bitstream) {
        Bitstream bit = (Bitstream) dso;
        if (bit.getFormat().isInternal()) {
          dso = null;
        }
      }
      // Make sure we got a dso
      boolean substract = false;
      while (dso == null) {
        // If our dsoId gets higher then our maxIdtotal we need to lower
        // to find a valid id
        if (dsoId == maxIdTotal)
                {
                    substract = true;
                }

        if (substract)
                {
                    dsoId--;
                }
        else
                {
                    dsoId++;
                }

        dso = DSpaceObject.find(context, type, dsoId);
        if (dso instanceof Bitstream) {
          Bitstream bit = (Bitstream) dso;
          if (bit.getFormat().isInternal()) {
            dso = null;
          }
        }
        // System.out.println("REFIND");
      }
      // Find the person who is visting us
      int epersonId = (int) getRandomNumberInRange(epersonStartId, epersonEndId);
      EPerson eperson = EPerson.find(context, epersonId);
      if (eperson == null)
            {
                epersonId = -1;
            }

      // System.out.println(ip);
      // System.out.println(country + " " +
      // LocationUtils.getCountryName(countryCode));

      // Resolve the dns
      String dns = null;
      try {
        dns = DnsLookup.reverseDns(ip);
      } catch (Exception e) {

      }

      System.out.println(ip);
      System.out.println(dns);

      // Save it in our server
      SolrInputDocument doc1 = new SolrInputDocument();
      doc1.addField("ip", ip);
      doc1.addField("type", dso.getType());
      doc1.addField("id", dso.getID());
      doc1.addField("time", DateFormatUtils.format(time,
          SolrLogger.DATE_FORMAT_8601));
      doc1.addField("continent", continent);
      // doc1.addField("country", country);
      doc1.addField("countryCode", countryCode);
      doc1.addField("city", city);
      doc1.addField("latitude", latitude);
      doc1.addField("longitude", longitude);
      if (epersonId > 0)
            {
                doc1.addField("epersonid", epersonId);
            }
      if (dns != null)
            {
                doc1.addField("dns", dns.toLowerCase());
            }

      SolrLogger.storeParents(doc1, dso);

      solr.add(doc1);

      // Make sure we have a previous ip
      prevIp = ip;
    }
    System.out.println("Nr of countryErrors: " + countryErrors);
    // Commit at the end cause it takes a while
    solr.commit();
  }
View Full Code Here

        String sserver = ConfigurationManager.getProperty("solr-statistics", "server");
        if (verbose)
        {
            System.out.println("Writing to solr server at: " + sserver);
        }
    solr = new HttpSolrServer(sserver);

        String dbfile = ConfigurationManager.getProperty("usage-statistics", "dbfile");
        try
        {
            geoipLookup = new LookupService(dbfile, LookupService.GEOIP_STANDARD);
View Full Code Here

            String solrService = ConfigurationManager.getProperty("solr.authority.server");

            log.debug("Solr authority URL: " + solrService);

            solr = new HttpSolrServer(solrService);
            solr.setBaseURL(solrService);

            SolrQuery solrQuery = new SolrQuery().setQuery("*:*");

            solr.query(solrQuery);
View Full Code Here

    public boolean connect() {
        try {
          server = null;
          coreContainer = null;
          if (baseurl!=null) {
            server = new HttpSolrServer(url);
              if (!solrUseJavaBin)
                ((HttpSolrServer)server).setParser(new XMLResponseParser());
          }

             if (home!=null) {
View Full Code Here

    {
        if (server == null)
        {
            try
            {
                server = new HttpSolrServer(configurationService.getProperty("oai", "solr.url"));
                log.debug("Solr Server Initialized");
            }
            catch (Exception e)
            {
                log.error(e.getMessage(), e);
View Full Code Here

TOP

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

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.