Package org.apache.nutch.searcher

Examples of org.apache.nutch.searcher.Hits


      NutchBean.LOG.info("query: " + query);
      NutchBean.LOG.info("lang: " + lang);
    }

    // search and return hits
    Hits hits;
    try {
      hits = bean.search(queryObj, start + rows, numDupes, dedup, sort, reverse);
    }
    catch (IOException e) {
      if (NutchBean.LOG.isWarnEnabled()) {
        NutchBean.LOG.warn("Search Error", e);
      }
      hits = new Hits(0, new Hit[0]);
    }

    // get the total number of hits, the hits to show, and the hit details
    long totalHits = hits.getTotal();
    int end = (int)Math.min(hits.getLength(), start + rows);
    int numHits = (end > start) ? (end - start) : 0;
    Hit[] show = hits.getHits(start, numHits);
    HitDetails[] details = bean.getDetails(show);

    // setup the SearchResults object, used in response writing
    SearchResults results = new SearchResults();
    results.setResponseType(respType);
View Full Code Here


      numTotal.incrementAndGet();

      try {
        Query runner = Query.parse(query, conf);
        long start = System.currentTimeMillis();
        Hits hits = bean.search(runner, 10);
        long end = System.currentTimeMillis();
        numResolved.incrementAndGet();
        long total = (end - start);
        if (showTimes) {
          System.out.println("Query for " + query + " numhits "
            + hits.getTotal() + " in " + total + "ms");
        }
        totalTime.addAndGet(total);
      }
      catch (Exception uhe) {
        LOG.info("Error executing search for " + query);
View Full Code Here

      hits = locator.getNutchBean().search(getQuery(),
          getStartOffset() + getHitsRequired(), getHitsPerDup(), getDupField(),
          getSortColumn(), isSortDesc());
    } catch (IOException e) {
      hits = new Hits(0, new Hit[0]);
    }

    int realEnd = (int) Math.min(hits.getLength(), getStartOffset()
        + getHitsRequired());
View Full Code Here

    }

  }

  public void readFields(DataInput in) throws IOException {
    hits = new Hits();
    hits.readFields(in);
    int showlength = in.readInt();
    show = new Hit[showlength];
    for (int i = 0; i < showlength; i++) {
      show[i] = new Hit();
View Full Code Here

    Query query = Query.parse(queryString, getServiceLocator()
        .getConfiguration());
    NutchBean.LOG.info("query: " + queryString);

    // execute the query
    Hits hits;
    try {
      hits = getServiceLocator().getNutchBean().search(query,
          start + hitsPerPage, hitsPerDup, dedupField, sort, reverse);
    } catch (IOException e) {
      NutchBean.LOG.warn("Search Error", e);
      hits = new Hits(0, new Hit[0]);
    }

    NutchBean.LOG.info("total hits: " + hits.getTotal());

    // generate xml results
    int end = (int) Math.min(hits.getLength(), start + hitsPerPage);
    int length = end - start;

    Hit[] show = hits.getHits(start, end - start);
    HitDetails[] details = getServiceLocator().getNutchBean().getDetails(show);
    Summary[] summaries = getServiceLocator().getNutchBean().getSummary(
        details, query);

    String requestUrl = request.getRequestURL().toString();
    String base = requestUrl.substring(0, requestUrl.lastIndexOf('/'));

    try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      factory.setNamespaceAware(true);
      Document doc = factory.newDocumentBuilder().newDocument();

      Element rss = addNode(doc, doc, "rss");
      addAttribute(doc, rss, "version", "2.0");
      addAttribute(doc, rss, "xmlns:opensearch", (String) NS_MAP
          .get("opensearch"));
      addAttribute(doc, rss, "xmlns:nutch", (String) NS_MAP.get("nutch"));

      Element channel = addNode(doc, rss, "channel");

      addNode(doc, channel, "title", "Nutch: " + queryString);
      addNode(doc, channel, "description", "Nutch search results for query: "
          + queryString);
      addNode(doc, channel, "link", base + "/search.jsp" + "?query=" + urlQuery
          + "&start=" + start + "&hitsPerDup=" + hitsPerDup + params);

      addNode(doc, channel, "opensearch", "totalResults", "" + hits.getTotal());
      addNode(doc, channel, "opensearch", "startIndex", "" + start);
      addNode(doc, channel, "opensearch", "itemsPerPage", "" + hitsPerPage);

      addNode(doc, channel, "nutch", "query", queryString);

      if ((hits.totalIsExact() && end < hits.getTotal()) // more hits to show
          || (!hits.totalIsExact() && (hits.getLength() > start + hitsPerPage))) {
        addNode(doc, channel, "nutch", "nextPage", requestUrl + "?query="
            + urlQuery + "&start=" + end + "&hitsPerDup=" + hitsPerDup + params);
      }

      if ((!hits.totalIsExact() && (hits.getLength() <= start + hitsPerPage))) {
        addNode(doc, channel, "nutch", "showAllHits", requestUrl + "?query="
            + urlQuery + "&hitsPerDup=" + 0 + params);
      }

      for (int i = 0; i < length; i++) {
View Full Code Here

   
    NutchBean bean = new NutchwaxBean(conf);
   
    Query query = Query.parse(args[0], conf);
   
    Hits hits = bean.search(query, 10);
    System.out.println("Total hits: " + hits.getTotal());
   
    int length = (int)Math.min(hits.getTotal(), 10);
   
    Hit[] show = hits.getHits(0, length);
   
    HitDetails[] details = bean.getDetails(show);
   
    Summary[] summaries = bean.getSummary(details, query);

    for (int i = 0; i < hits.getLength(); i++)
    {
      System.out.println(" "+i+" "+ details[i] + "\n" + summaries[i]);
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.nutch.searcher.Hits

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.