Package org.apache.lucene.search

Examples of org.apache.lucene.search.Hits


        IndexSearcher searcher = null;
        try {
            searcher = new IndexSearcher(indexFilePath);
            Term productIdTerm = new Term("product_id", productId);
            org.apache.lucene.search.Query query = new TermQuery(productIdTerm);
            Hits hits = searcher.search(query);

            // should be exactly 1 hit
            if (hits.length() == 0) {
              throw new CatalogException("Product: [" + productId + "] NOT found in the catalog!");
            } else if (hits.length() > 1) {
                throw new CatalogException("Product: [" + productId+ "] is not unique in the catalog!");
            }

            Document productDoc = hits.doc(0);
            CompleteProduct prod = toCompleteProduct(productDoc, getRefs,
                    getMet);
            return prod;
        } catch (IOException e) {
            LOG.log(Level.WARNING,
View Full Code Here


            searcher = new IndexSearcher(indexFilePath);
            Term productIdTerm = new Term("product_name", productName);
            org.apache.lucene.search.Query query = new TermQuery(productIdTerm);
            Sort sort = new Sort(new SortField("CAS.ProductReceivedTime",
                    SortField.STRING, true));
            Hits hits = searcher.search(query, sort);

            // should be > 0 hits
            if (hits.length() > 0) {
                // just get the first hit back
                Document productDoc = hits.doc(0);
                CompleteProduct prod = toCompleteProduct(productDoc, getRefs,
                        false);
                return prod.getProduct();
            } else {
                LOG.log(Level.FINEST, "Request for product by name: ["
View Full Code Here

            searcher = new IndexSearcher(indexFilePath);
            Term productIdTerm = new Term("myfield", "myvalue");
            org.apache.lucene.search.Query query = new TermQuery(productIdTerm);
            Sort sort = new Sort(new SortField("CAS.ProductReceivedTime",
                    SortField.STRING, true));
            Hits hits = searcher.search(query, sort);

            // should be > 0 hits
            if (hits.length() > 0) {
                products = new Vector<Product>(hits.length());
                for (int i = 0; i < hits.length(); i++) {
                    Document productDoc = hits.doc(i);
                    CompleteProduct prod = toCompleteProduct(productDoc,
                            getRefs, false);
                    products.add(prod.getProduct());
                }
            } else {
View Full Code Here

            Term productIdTerm = new Term("product_type_id", type
                    .getProductTypeId());
            org.apache.lucene.search.Query query = new TermQuery(productIdTerm);
            Sort sort = new Sort(new SortField("CAS.ProductReceivedTime",
                    SortField.STRING, true));
            Hits hits = searcher.search(query, sort);

            // should be > 0 hits
            if (hits.length() > 0) {
                products = new Vector<Product>(hits.length());
                for (int i = 0; i < hits.length(); i++) {
                    Document productDoc = hits.doc(i);
                    CompleteProduct prod = toCompleteProduct(productDoc,
                            getRefs, false);
                    products.add(prod.getProduct());
                }
            } else {
View Full Code Here

        IndexSearcher searcher = null;
        try {
            searcher = new IndexSearcher(indexFilePath);
            Term productIdTerm = new Term("product_id", product.getProductId());
            org.apache.lucene.search.Query query = new TermQuery(productIdTerm);
            Hits hits = searcher.search(query);

            // should be exactly 1 hit
            if (hits.length() != 1) {
                throw new CatalogException("Product: ["
                        + product.getProductId()
                        + "] is not unique in the catalog! Num Hits: ["
                        + hits.length() + "]");
            }

            Document productDoc = hits.doc(0);
            CompleteProduct prod = toCompleteProduct(productDoc, false, true);
            return prod.getMetadata();
        } catch (IOException e) {
            LOG.log(Level.WARNING,
                    "IOException when opening index directory: ["
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) {
                products = new Vector<Product>(n);
                int i = 0;
                while (products.size() < Math.min(n, hits.length())) {
                    Document productDoc = hits.doc(i);
                    CompleteProduct prod = toCompleteProduct(productDoc, false,
                            false);
                    products.add(prod.getProduct());
                    i++;
                }
View Full Code Here

            for (QueryCriteria queryCriteria : query.getCriteria())
                booleanQuery.add(this.getQuery(queryCriteria), BooleanClause.Occur.MUST);

            LOG.log(Level.FINE, "Querying LuceneCatalog: q: [" + booleanQuery
                    + "]");
            Hits hits = searcher.search(booleanQuery);
            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);
           
            // Calculate page size and set it while we have the results
            if (page != null) {
              page.setTotalPages(PaginationUtils.getTotalPage(hits.length(), pageSize));
            }
           
            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

            }
        }

        // System.out.println("Q: " + query);
        IndexSearcher usedSearcher = searcher;
        Hits hits = null;
        boolean retry = true;
        while (retry) {
            try {
                hits = usedSearcher.search(query);
            } catch (IOException e) {
                if (retry && usedSearcher != searcher) {
                    usedSearcher = searcher;
                } else {
                    throw e;
                }
            } finally {
                retry = false;
            }
        }
        // System.out.println("HITS: " + hits.length());
        SuggestWordQueue sugQueue = new SuggestWordQueue(numSug);

        // go thru more than 'maxr' matches in case the distance filter triggers
        int stop = Math.min(hits.length(), 10 * numSug);
        SuggestWord sugWord = new SuggestWord();
        for (int i = 0; i < stop; i++) {

            sugWord.string = hits.doc(i).get(F_WORD + (language != null ? "-" + language : "")); // get
            // orig
            // word

            // don't suggest a word for itself, that would be silly
            if (sugWord.string == null || word.equals(sugWord.string)) {
View Full Code Here

      ArrayList results = new ArrayList();
      IndexReader reader = IndexReader.open(storeIndex);
      Searcher searcher = new IndexSearcher(reader);
      Analyzer analyzer = new StandardAnalyzer();
      Query query = QueryParser.parse(item,"TextPath",analyzer);
      Hits hits = searcher.search(query);
      for(int i = 0; i < hits.length() && i < QueryManager.resultSize; i++){
        Document doc = hits.doc(i);
        String path = doc.get("Path");
        if(!results.contains(path))
          results.add(path);
      }
      if(content){
        query = QueryParser.parse(item, "Contents", analyzer);
        hits = searcher.search(query);
        for (int i = 0; i < hits.length() && i < QueryManager.resultSize; i++) {
          Document doc = hits.doc(i);
          String path = doc.get("Path");
          if (!results.contains(path))
            results.add(path);
        }
        query = QueryParser.parse(item, "ExtendedInfosContent", analyzer);
        hits = searcher.search(query);
        for (int i = 0; i < hits.length() && i < QueryManager.resultSize; i++) {
          Document doc = hits.doc(i);
          String path = doc.get("Path");
          if (!results.contains(path))
            results.add(path);
        }
      }
      query = QueryParser.parse(item,"PartialFileName",analyzer);
      hits = searcher.search(query);
      for(int i = 0; i < hits.length() && i < QueryManager.resultSize; i++){
        Document doc = hits.doc(i);
        StringHash hash = new StringHash(doc.get("PartialFileHash"));
        if(!results.contains(hash))
          results.add(hash);
      }
      reader.close();
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.