Examples of TopScoreDocCollector


Examples of org.apache.lucene.search.TopScoreDocCollector

        throw new RegainException("Creating index searcher failed", exc);
      }
    }

    try {
      TopScoreDocCollector collector = TopScoreDocCollector.create(20, false);
      mIndexSearcher.search(query, collector);
      return collector.topDocs().scoreDocs;

    } catch (IOException exc) {
      throw new RegainException("Searching query failed", exc);
    }
  }
View Full Code Here

Examples of org.apache.lucene.search.TopScoreDocCollector

      Term urlTerm = new Term("url", url);
      Query query = new TermQuery(urlTerm);

      try {
        setIndexMode(SEARCHING_MODE);
        TopScoreDocCollector collector = TopScoreDocCollector.create(2, false);
        mIndexSearcher.search(query, collector);

        if (collector.getTotalHits() == 1) {
          // we found one hit for our URL
          result = true;

        }
      } catch (IOException exc) {
View Full Code Here

Examples of org.apache.lucene.search.TopScoreDocCollector

      Term urlTerm = new Term("url", rawDocument.getUrl());
      Query query = new TermQuery(urlTerm);
      Document doc;
      try {
        setIndexMode(SEARCHING_MODE);
        TopScoreDocCollector collector = TopScoreDocCollector.create(20, false);
        mIndexSearcher.search(query, collector);
        ScoreDoc[] hits = collector.topDocs().scoreDocs;

        if (hits.length > 0) {
          if (hits.length > 1) {
            for (int i = 1; i < hits.length; i++) {
              markForDeletion(mIndexSearcher.doc(hits[i].doc));
View Full Code Here

Examples of org.apache.lucene.search.TopScoreDocCollector

    m_indexWriter.addDocument(doc3);
    m_indexWriter.commit();

    DirectoryReader reader = DirectoryReader.open(m_indexWriter, true);
    IndexSearcher searcher = new IndexSearcher(reader);
    TopScoreDocCollector docCollector = TopScoreDocCollector.create(100, true);
    QueryParser queryParser = new QueryParser(Version.LUCENE_43, "text", new StandardAnalyzer(
        Version.LUCENE_43));
    Query query = queryParser.parse("Foo*");
    searcher.search(query, docCollector);
    TopDocs docs = docCollector.topDocs();
    ScoreDoc[] scoreDocs = docs.scoreDocs;

    assertEquals("should be doc 0", 0, scoreDocs[0].doc);
    assertEquals("should be doc 1", 1, scoreDocs[1].doc);
    assertEquals("should be doc 2", 2, scoreDocs[2].doc);
View Full Code Here

Examples of org.apache.lucene.search.TopScoreDocCollector

    private int doSearch(String searchPhrase, int maxNumberOfHits, Version luceneVersion) throws NullPointerException, ParseException, IOException {
        LOG.trace("*** Search Phrase: {} ***", searchPhrase);

        QueryParser parser = new QueryParser(luceneVersion, "contents", analyzer);
        Query query = parser.parse(searchPhrase);
        TopScoreDocCollector collector = TopScoreDocCollector.create(maxNumberOfHits, true);
        indexSearcher.search(query, collector);
        hits = collector.topDocs().scoreDocs;
       
        LOG.trace("*** Search generated {} hits ***", hits.length);
        return hits.length;
    }
View Full Code Here

Examples of org.apache.lucene.search.TopScoreDocCollector

            int hitsPerPage, boolean raw, boolean interactive) throws IOException {
        ArrayList outData = new ArrayList();
        String accumulator = "";

        // Collect enough docs to show 5 pages
        TopScoreDocCollector collector = TopScoreDocCollector.create(
                5 * hitsPerPage, false);
        searcher.search(query, collector);
        ScoreDoc[] hits = collector.topDocs().scoreDocs;

        int numTotalHits = collector.getTotalHits();
        outMultiData.add(numTotalHits + " total matching documents");

        int start = 0;
        //int end = Math.min(numTotalHits, hitsPerPage);
        int end = 0;
View Full Code Here

Examples of org.apache.lucene.search.TopScoreDocCollector

    void search() throws BlurException {
      long s = System.currentTimeMillis();
      progressRef.searchesPerformed.incrementAndGet();
      try {
        TopScoreDocCollector collector = TopScoreDocCollector.create(numHitsToCollect, lastScoreDoc, true);
        Collector col = new StopExecutionCollector(collector, running);
        if (_runSlow) {
          col = new SlowCollector(col);
        }
        searcher.search(query, col);
        totalHitsRef.totalHits.set(collector.getTotalHits());
        TopDocs topDocs = collector.topDocs();
        scoreDocs = topDocs.scoreDocs;
      } catch (StopExecutionCollectorException e) {
        throw new BlurException(STOP_EXECUTION_COLLECTOR_EXCEPTION, null, ErrorType.UNKNOWN);
      } catch (ExitingReaderException e) {
        throw new BlurException(STOP_EXECUTION_COLLECTOR_EXCEPTION, null, ErrorType.UNKNOWN);
View Full Code Here

Examples of org.apache.lucene.search.TopScoreDocCollector

        final IndexSearcher indexSearcher = context.acquireIndexSearcher();
        try
        {
            for ( String uinfo : uinfos )
            {
                TopScoreDocCollector collector = TopScoreDocCollector.create( 1, false );

                indexSearcher.search( new TermQuery( new Term( ArtifactInfo.UINFO, uinfo ) ), collector );

                if ( collector.getTotalHits() > 0 )
                {
                    String[] ra = ArtifactInfo.FS_PATTERN.split( uinfo );

                    ArtifactInfo ai = new ArtifactInfo();

                    ai.repository = context.getRepositoryId();

                    ai.groupId = ra[0];

                    ai.artifactId = ra[1];

                    ai.version = ra[2];

                    if ( ra.length > 3 )
                    {
                        ai.classifier = ArtifactInfo.renvl( ra[3] );
                    }

                    if ( ra.length > 4 )
                    {
                        ai.packaging = ArtifactInfo.renvl( ra[4] );
                    }

                    // minimal ArtifactContext for removal
                    ArtifactContext ac = new ArtifactContext( null, null, null, ai, ai.calculateGav() );

                    for ( int i = 0; i < collector.getTotalHits(); i++ )
                    {
                        if ( contextPath == null
                            || context.getGavCalculator().gavToPath( ac.getGav() ).startsWith( contextPath ) )
                        {
                            indexerEngine.remove( context, ac );
View Full Code Here

Examples of org.apache.lucene.search.TopScoreDocCollector

        QueryParser parser = new QueryParser(Version.LUCENE_30, "content", analyzer);
        Query query = parser.parse(queryLine);
        combQuery.add(query, BooleanClause.Occur.MUST);

        TopScoreDocCollector collector = TopScoreDocCollector.create(10, false);
        searcher.search(combQuery, collector);

        assertEquals("Only 1 result expected from the testdata", 1, collector.getTotalHits());
    }
View Full Code Here

Examples of org.apache.lucene.search.TopScoreDocCollector

        }

        // check for descriptor if this is not a "virgin" index
        if ( getSize() > 0 )
        {
            final TopScoreDocCollector collector = TopScoreDocCollector.create( 1, false );
            final IndexSearcher indexSearcher = acquireIndexSearcher();
            try
            {
                indexSearcher.search( new TermQuery( DESCRIPTOR_TERM ), collector );

                if ( collector.getTotalHits() == 0 )
                {
                    throw new ExistingLuceneIndexMismatchException(
                        "The existing index has no NexusIndexer descriptor" );
                }

                if ( collector.getTotalHits() > 1 )
                {
                    // eh? this is buggy index it seems, just iron it out then
                    storeDescriptor();
                    return;
                }
                else
                {
                    // good, we have one descriptor as should
                    Document descriptor = indexSearcher.doc( collector.topDocs().scoreDocs[0].doc );
                    String[] h = StringUtils.split( descriptor.get( FLD_IDXINFO ), ArtifactInfo.FS );
                    // String version = h[0];
                    String repoId = h[1];

                    // // compare version
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.