Package org.apache.lucene.search

Examples of org.apache.lucene.search.TopDocs


      writer.addDocument(doc, analyzer);
      writer.commit();

      // try the search over the first doc
      IndexSearcher indexSearcher = new IndexSearcher(writer.getReader());
      TopDocs result = indexSearcher.search(
              new MatchAllDocsQuery("contents"), 10);
      assertTrue(result.totalHits > 0);
      Document d = indexSearcher.doc(result.scoreDocs[0].doc);
      assertNotNull(d);
      assertNotNull(d.getFieldable("title"));
View Full Code Here


    }

    @Override
    public List<String> getUpcomingByCategory(String category, int maxDocument) throws EventSearchServiceException {
        try {
            TopDocs docs = LuceneService.get().search("", category, "beginDate", true, maxDocument);
            return convertToIds(docs, 0);
        } catch (ParseException e) {
            assert false;
            throw new EventSearchServiceException(e);
        }
View Full Code Here

        }
    }

    @Override
    public List<String> getRecent(int maxDocument) throws EventSearchServiceException {
        TopDocs docs = LuceneService.get().getRecentDocuments(maxDocument);
        return convertToIds(docs, 0);
    }
View Full Code Here

        return convertToIds(docs, 0);
    }

    @Override
    public List<String> getRecentByCategory(String category, int maxDocument) throws EventSearchServiceException {
        TopDocs docs = LuceneService.get().getRecentCategoryDocuments(category, maxDocument);
        return convertToIds(docs, 0);
    }
View Full Code Here

    }

    @Override
    public List<String> search(String term, String category, String sortOrder, boolean beforeDeadlineOnly, int offset, int limit) throws EventSearchServiceException {
        try {
            TopDocs docs = LuceneService.get().search(term, category, sortOrder, beforeDeadlineOnly, offset + limit);
            return convertToIds(docs, offset);
        } catch (ParseException e) {
            throw new EventSearchServiceException(e);
        }
    }
View Full Code Here


    @Override
    public List<String> search(String term, String category, String sortOrder, boolean beforeDeadlineOnly, int maxDocument) throws EventSearchServiceException {
        try {
            TopDocs docs = LuceneService.get().search(term, category, sortOrder, beforeDeadlineOnly, maxDocument);
            return convertToIds(docs, 0);
        } catch (ParseException e) {
            assert false;
            throw new EventSearchServiceException(e);
        }
View Full Code Here

    }

    public boolean hasDocument(String id) throws EventSearchServiceException {
        try {
            Query query = new TermQuery(new Term("ID", id));
            TopDocs docs = indexSearcher.search(query, 1);
            return docs.totalHits > 0;
        } catch (IOException e) {
            throw new EventSearchServiceException(e);
        }
    }
View Full Code Here

      IndexSearcher searcher = buildSearcher( searchFactoryImplementor );
      if ( searcher == null ) {
        resultSize = 0;
      }
      else {
        TopDocs hits;
        try {
          hits = getQueryHits( searcher ).topDocs;
          resultSize = hits.totalHits;
        }
        catch ( IOException e ) {
View Full Code Here

          topDocs.add(queryCommandResult.getTopDocs());
          mergedMatches += queryCommandResult.getMatches();
        }

        int topN = rb.getGroupingSpec().getOffset() + rb.getGroupingSpec().getLimit();
        TopDocs mergedTopDocs = TopDocs.merge(sortWithinGroup, topN, topDocs.toArray(new TopDocs[topDocs.size()]));
        rb.mergedQueryCommandResults.put(query, new QueryCommandResult(mergedTopDocs, mergedMatches));
      }

      Map<Object, ShardDoc> resultIds = new HashMap<Object, ShardDoc>();
      int i = 0;
View Full Code Here

      searcher = new IndexSearcher(directory, true);
    }
    Results result = new Results();
    QueryParser qp = new QueryParser(Version.LUCENE_36, "paragraph", new StandardAnalyzer(Version.LUCENE_36));
    Query query = qp.parse(queryStr);
    TopDocs topDocs = searcher.search(query, 20);
    System.out.println("Found " + topDocs.totalHits + " total hits.");
    for (int i = 0; i < topDocs.scoreDocs.length; i++) {
      Document theDoc = searcher.doc(topDocs.scoreDocs[i].doc);
      result.matches.add(theDoc);
    }
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.TopDocs

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.