Package org.apache.lucene.search

Examples of org.apache.lucene.search.Hits


            Sort sort = new Sort(new SortField("CAS.ProductReceivedTime",
                    SortField.STRING, true));
            LOG.log(Level.FINE, "Querying LuceneCatalog: q: [" + booleanQuery
                    + "]");
            Hits hits = searcher.search(booleanQuery, sort);
            if (hits.length() > 0) {
                products = new Vector<Product>(n);
                int i = 0;
                while (products.size() < n) {
                    Document productDoc = hits.doc(i);
                    CompleteProduct prod = toCompleteProduct(productDoc, false,
                            false);
                    products.add(prod.getProduct());
                    i++;
                }
View Full Code Here


            Sort sort = new Sort(new SortField("CAS.ProductReceivedTime",
                    SortField.STRING, true));
            LOG.log(Level.FINE, "Querying LuceneCatalog: q: [" + booleanQuery
                    + "]");
            Hits hits = searcher.search(booleanQuery, sort);
            numHits = hits.length();
        } catch (IOException e) {
            LOG.log(Level.WARNING,
                    "IOException when opening index directory: ["
                            + indexFilePath + "] for search: Message: "
                            + e.getMessage());
View Full Code Here

           
            Sort sort = new Sort(new SortField("CAS.ProductReceivedTime",
                    SortField.STRING, true));
            LOG.log(Level.FINE, "Querying LuceneCatalog: q: [" + booleanQuery
                    + "]");
            Hits hits = searcher.search(booleanQuery, sort);
            if (hits.length() > 0) {

                int startNum = (pageNum - 1) * pageSize;
                if (doSkip) {
                    if (startNum > hits.length()) {
                        startNum = 0;
                    }

                    products = new Vector<Product>(pageSize);

                    for (int i = startNum; i < Math.min(hits.length(),
                            (startNum + pageSize)); i++) {
                        Document productDoc = hits.doc(i);
                        CompleteProduct prod = toCompleteProduct(productDoc,
                                false, false);
                        products.add(prod.getProduct());
                    }
                } else {
                    products = new Vector<Product>(hits.length());
                    for (int i = 0; i < hits.length(); i++) {
                        Document productDoc = hits.doc(i);
                        CompleteProduct prod = toCompleteProduct(productDoc,
                                false, false);
                        products.add(prod.getProduct());
                    }
                }
View Full Code Here

      DistanceFieldComparatorSource dsort = new DistanceFieldComparatorSource(dq.distanceFilter);
      Sort sort = new Sort(new SortField("foo", dsort,false));
   
      // Perform the search, using the term query, the serial chain filter, and the
      // distance sort
      Hits hits = searcher.search(customScore,null,sort);

      int results = hits.length();
   
      // Get a list of distances
      Map<Integer,Double> distances = dq.distanceFilter.getDistances();
   
      // distances calculated from filter first pass must be less than total
      // docs, from the above test of 20 items, 12 will come from the boundary box
      // filter, but only 5 are actually in the radius of the results.
   
      // Note Boundary Box filtering, is not accurate enough for most systems.
   
   
      System.out.println("Distance Filter filtered: " + distances.size());
      System.out.println("Results: " + results);
      System.out.println("=============================");
      System.out.println("Distances should be 7 "+ distances.size());
      System.out.println("Results should be 7 "+ results);

      assertEquals(expected[x], distances.size()); // fixed a store of only needed distances
      assertEquals(expected[x], results);
      double lastDistance = 0;
      for(int i =0 ; i < results; i++){
        Document d = hits.doc(i);
     
        String name = d.get("name");
        double rsLat = NumericUtils.prefixCodedToDouble(d.get(latField));
        double rsLng = NumericUtils.prefixCodedToDouble(d.get(lngField));
        Double geo_distance = distances.get(hits.id(i));
     
        double distance = DistanceUtils.getInstance().getDistanceMi(lat, lng, rsLat, rsLng);
        double llm = DistanceUtils.getInstance().getLLMDistance(lat, lng, rsLat, rsLng);
        System.out.println("Name: "+ name +", Distance "+ distance); //(res, ortho, harvesine):"+ distance +" |"+ geo_distance +"|"+ llm +" | score "+ hits.score(i));
        assertTrue(Math.abs((distance - llm)) < 1);
View Full Code Here

      DistanceFieldComparatorSource dsort = new DistanceFieldComparatorSource(dq.distanceFilter);
      Sort sort = new Sort(new SortField("foo", dsort));
     
      // Perform the search, using the term query, the serial chain filter, and the
      // distance sort
      Hits hits = searcher.search(customScore, dq.getFilter()); //,sort);

      int results = hits.length();
     
      // Get a list of distances
      Map<Integer,Double> distances = dq.distanceFilter.getDistances();
     
      // distances calculated from filter first pass must be less than total
      // docs, from the above test of 20 items, 12 will come from the boundary box
      // filter, but only 5 are actually in the radius of the results.
     
      // Note Boundary Box filtering, is not accurate enough for most systems.
     
     
      System.out.println("Distance Filter filtered: " + distances.size());
      System.out.println("Results: " + results);
      System.out.println("=============================");
      System.out.println("Distances should be 14 "+ distances.size());
      System.out.println("Results should be 7 "+ results);

      assertEquals(expected[x], distances.size());
      assertEquals(expected[x], results);
     
      for(int i =0 ; i < results; i++){
        Document d = hits.doc(i);
       
        String name = d.get("name");
        double rsLat = NumericUtils.prefixCodedToDouble(d.get(latField));
        double rsLng = NumericUtils.prefixCodedToDouble(d.get(lngField));
        Double geo_distance = distances.get(hits.id(i));
       
        double distance = DistanceUtils.getInstance().getDistanceMi(lat, lng, rsLat, rsLng);
        double llm = DistanceUtils.getInstance().getLLMDistance(lat, lng, rsLat, rsLng);
        System.out.println("Name: "+ name +", Distance (res, ortho, harvesine):"+ distance +" |"+ geo_distance +"|"+ llm +" | score "+ hits.score(i));
        assertTrue(Math.abs((distance - llm)) < 1);
        assertTrue((distance < miles ));
       
      }
    }
View Full Code Here

      Searcher searcher = null;

      try {
        searcher = new IndexSearcher(blog.getSearchIndexDirectory());
        Query query = QueryParser.parse(queryString, "blogEntry", getAnalyzer());
        Hits hits = searcher.search(query);

        for (int i = 0; i < hits.length(); i++) {
          Document doc = hits.doc(i);
          SearchHit result = new SearchHit(
              blog,
              doc.get("id"),
              doc.get("permalink"),
              doc.get("title"),
              doc.get("truncatedBody"),
              DateField.stringToDate(doc.get("date")),
              hits.score(i));
          searchResults.add(result);
        }
      } catch (ParseException pe) {
        pe.printStackTrace();
        searchResults.setMessage("Sorry, but there was an error. Please try another search");
View Full Code Here

  // search for something that does exists
  Query query = new TermQuery(new Term("keyword", "test1"));

  // ensure that queries return expected results without DateFilter first
        Hits hits = searcher.search(query);
  assertEquals(1, hits.length());

        try
        {
            doAssert(hits.doc(0), true);
        }
        catch (Exception e)
        {
            e.printStackTrace(System.err);
            System.err.print("\n");
View Full Code Here

    writer.optimize();
    writer.close();

    IndexSearcher searcher = new IndexSearcher(store);
    PhraseQuery q;
    Hits hits;

    q = new PhraseQuery();
    q.add(new Term("field", "1"));
    q.add(new Term("field", "2"));
    hits = searcher.search(q);
    assertEquals(0, hits.length());

    q = new PhraseQuery();
    q.add(new Term("field", "2"));
    q.add(new Term("field", "3"));
    hits = searcher.search(q);
    assertEquals(1, hits.length());

    q = new PhraseQuery();
    q.add(new Term("field", "3"));
    q.add(new Term("field", "4"));
    hits = searcher.search(q);
    assertEquals(0, hits.length());

    q = new PhraseQuery();
    q.add(new Term("field", "2"));
    q.add(new Term("field", "4"));
    hits = searcher.search(q);
    assertEquals(1, hits.length());

    q = new PhraseQuery();
    q.add(new Term("field", "3"));
    q.add(new Term("field", "5"));
    hits = searcher.search(q);
    assertEquals(1, hits.length());

    q = new PhraseQuery();
    q.add(new Term("field", "4"));
    q.add(new Term("field", "5"));
    hits = searcher.search(q);
    assertEquals(1, hits.length());

    q = new PhraseQuery();
    q.add(new Term("field", "2"));
    q.add(new Term("field", "5"));
    hits = searcher.search(q);
    assertEquals(0, hits.length());
  }
View Full Code Here

  Query query1 = new TermQuery(new Term("body", "NoMatchForThis"));

  // search for something that does exists
  Query query2 = new TermQuery(new Term("body", "sunny"));

  Hits result;

  // ensure that queries return expected results without DateFilter first
  result = searcher.search(query1);
  assertEquals(0, result.length());

  result = searcher.search(query2);
  assertEquals(1, result.length());


  // run queries with DateFilter
  result = searcher.search(query1, df1);
  assertEquals(0, result.length());

  result = searcher.search(query1, df2);
  assertEquals(0, result.length());

   result = searcher.search(query2, df1);
   assertEquals(1, result.length());

  result = searcher.search(query2, df2);
  assertEquals(0, result.length());
    }
View Full Code Here

  Query query1 = new TermQuery(new Term("body", "NoMatchForThis"));

  // search for something that does exists
  Query query2 = new TermQuery(new Term("body", "sunny"));

  Hits result;

  // ensure that queries return expected results without DateFilter first
  result = searcher.search(query1);
  assertEquals(0, result.length());

  result = searcher.search(query2);
  assertEquals(1, result.length());


  // run queries with DateFilter
  result = searcher.search(query1, df1);
  assertEquals(0, result.length());

  result = searcher.search(query1, df2);
  assertEquals(0, result.length());

   result = searcher.search(query2, df1);
   assertEquals(1, result.length());

  result = searcher.search(query2, df2);
  assertEquals(0, result.length());
    }
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.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.