Package org.apache.lucene.search

Examples of org.apache.lucene.search.Hits


     * @throws  ProcessingException  iff an error occurs
     */
    private LuceneCocoonPager buildHits() throws ProcessingException {

        if (queryString != null && queryString.length() != 0) {
            Hits hits = null;

            // TODO (VG): Move parts into compose/initialize/recycle
            try {
                lcs = (LuceneCocoonSearcher) this.manager.lookup(LuceneCocoonSearcher.ROLE);
                Analyzer analyzer = LuceneCocoonHelper.getAnalyzer("org.apache.lucene.analysis.standard.StandardAnalyzer");
                lcs.setAnalyzer(analyzer);
                // get the directory where the index resides
                Directory directory = LuceneCocoonHelper.getDirectory(index, false);
                lcs.setDirectory(directory);
                hits = lcs.search(queryString, LuceneXMLIndexer.BODY_FIELD);
            } catch (IOException ioe) {
                throw new ProcessingException("IOException in search", ioe);
            } catch (ComponentException ce) {
                throw new ProcessingException("ComponentException in search", ce);
            } finally {
                if (lcs != null) {
                    this.manager.release(lcs);
                    lcs = null;
                }
            }

            // wrap the hits by an pager help object for accessing only a range of hits
            LuceneCocoonPager pager = new LuceneCocoonPager(hits);

            int start_index = START_INDEX_DEFAULT;
            if (this.startIndex != null) {
                start_index = this.startIndex.intValue();
                if (start_index <= 0) {
                    start_index = 0;
                }
                pager.setStartIndex(start_index);
            }

            int page_length = PAGE_LENGTH_DEFAULT;
            if (this.pageLength != null) {
                page_length = this.pageLength.intValue();
                if (page_length <= 0) {
                    page_length = hits.length();
                }
                pager.setCountOfHitsPerPage(page_length);
            }

            return pager;
View Full Code Here


                                            (CachingMultiReader) parentReader};
            reader = new CombinedIndexReader(readers);
        }

        IndexSearcher searcher = new IndexSearcher(reader);
        Hits hits;
        if (sortFields.length > 0) {
            hits = searcher.search(query, new Sort(sortFields));
        } else {
            hits = searcher.search(query);
        }
View Full Code Here

            } else {
                aQuery = new TermQuery(new Term(aField, aQueryStr));
            }

            // Perform search
            Hits aHits = searcher.search(aQuery);
            int nHitCount = aHits.length();

            String aDocs[] = new String[nHitCount];
            for (int iHit = 0; iHit < nHitCount; iHit++) {
                Document aDoc = aHits.doc(iHit);
                String aPath = aDoc.get("path");
                aDocs[iHit] = (aPath != null) ? aPath : "";
            }

            reader.close();
View Full Code Here

       
        // execute search
        indexMgr.executeIndexOperationNow(search);
       
        if (search.getResultsCount() > -1) {
            Hits hits = search.getResults();
            this.hits = search.getResultsCount();
           
            // Convert the Hits into WeblogEntryData instances.
            convertHitsToEntries(hits);
        }
View Full Code Here

       
        if (search.getResultsCount() == -1) {
            // this means there has been a parsing (or IO) error
            this.errorMessage = I18nMessages.getMessages(searchRequest.getLocaleInstance()).getString("error.searchProblem");
        } else {
            Hits hits = search.getResults();
            this.hits = search.getResultsCount();
           
            // Convert the Hits into WeblogEntryData instances.
            convertHitsToEntries(hits);
        }
View Full Code Here

       
        // execute search
        indexMgr.executeIndexOperationNow(search);
       
        if (search.getResultsCount() > -1) {
            Hits hits = search.getResults();
            this.hits = search.getResultsCount();
           
            // Convert the Hits into WeblogEntryData instances.
            convertHitsToEntries(hits);
        }
View Full Code Here

       
        if (search.getResultsCount() == -1) {
            // this means there has been a parsing (or IO) error
            this.errorMessage = I18nMessages.getMessages(searchRequest.getLocaleInstance()).getString("error.searchProblem");
        } else {
            Hits hits = search.getResults();
            this.hits = search.getResultsCount();
           
            // Convert the Hits into WeblogEntryData instances.
            convertHitsToEntries(hits);
        }
View Full Code Here

        }
           
        int errorCode=Integer.parseInt(parts[0]);
        String url=parts[1];                     
        String encoded = Base32.encode(md.digest(url.getBytes()));
        Hits hits=searcher.search(new TermQuery(new Term("exacturl", encoded))); // index query         
        if (hits.length()>0) {
          idsThread[hits.id(0)%nThreads].add(hits.id(0));
        }
     
        System.out.println(errorCode+" "+hits.length()+" "+url+" "+(hits.length()>0 ? hits.id(0) : "")); // TODO remove
      }     
      br.close();
    }
    else { // set all ids
      int maxDoc=reader.maxDoc();
View Full Code Here

                booleanQuery.add(query2, BooleanClause.Occur.MUST);
            }

            Sort sort = new Sort(new SortField("CAS.ProductReceivedTime",
                    SortField.STRING, true));
            Hits hits = searcher.search(booleanQuery, sort);
            if (hits.length() > 0) {
                products = new Vector(hits.length());
                for (int i = 0; i < hits.length(); i++) {
                    Document productDoc = hits.doc(i);
                    products.add(productDoc.get("reference_data_store"));
                }
            } else {
                LOG.log(Level.WARNING, "Query: [" + query1
                        + "] for Product Type: [" + productTypeId
View Full Code Here

            searcher = new IndexSearcher(idxFilePath);
            Term instIdTerm = new Term("myfield", "myvalue");
            org.apache.lucene.search.Query query = new TermQuery(instIdTerm);
            Sort sort = new Sort(new SortField("workflow_inst_startdatetime",
                    SortField.STRING, true));
            Hits hits = searcher.search(query, sort);

            numInsts = hits.length();

        } catch (IOException e) {
            LOG.log(Level.WARNING,
                    "IOException when opening index directory: [" + idxFilePath
                            + "] for search: Message: " + e.getMessage());
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.