Package org.apache.lucene.search

Examples of org.apache.lucene.search.Hits


    break;

  Query query = QueryParser.parse(line, "contents", analyzer);
  System.out.println("Searching for: " + query.toString("contents"));

  Hits hits = searcher.search(query);
  System.out.println(hits.length() + " total matching documents");

  final int HITS_PER_PAGE = 10;
  for (int start = 0; start < hits.length(); start += HITS_PER_PAGE) {
    int end = Math.min(hits.length(), start + HITS_PER_PAGE);
    for (int i = start; i < end; i++) {
      Document doc = hits.doc(i);
      String path = doc.get("path");
      if (path != null) {
              System.out.println(i + ". " + path);
      } else {
              String url = doc.get("url");
        if (url != null) {
    System.out.println(i + ". " + url);
    System.out.println("   - " + doc.get("title"));
        } else {
    System.out.println(i + ". " + "No path nor URL for this document");
        }
      }
    }

    if (hits.length() > end) {
      System.out.print("more (y/n) ? ");
      line = in.readLine();
      if (line.length() == 0 || line.charAt(0) == 'n')
        break;
    }
View Full Code Here


    // valid exact phrase query
    PhraseQuery query = new PhraseQuery();
    query.add(new Term("field","stop"));
    query.add(new Term("field","words"));
    Hits hits = searcher.search(query);
    assertEquals(1, hits.length());

    // currently StopAnalyzer does not leave "holes", so this matches.
    query = new PhraseQuery();
    query.add(new Term("field", "words"));
    query.add(new Term("field", "here"));
    hits = searcher.search(query);
    assertEquals(1, hits.length());

    searcher.close();
  }
View Full Code Here

    while (it.hasNext()) {
      SimpleLuceneCriterion criterion = (SimpleLuceneCriterion)it.next();
      Query subquery = criterion.getQuery (searcher.getAnalyzer());
      query.add(subquery, required, criterion.isProhibited());
    }
    Hits hits = searcher.search(query);
    this.total = new Long (hits.length());
    this.date = new Date();
    return page(hits);
  }
View Full Code Here

    line = StringUtil.replace(line, " ou ", " OR ");
    line = StringUtil.replace(line, " nao ", " NOT ");
    line = StringUtil.replace(line, " n�o ", " NOT ");

    Query query = QueryParser.parse(line, "contents", analyzer);
    Hits hits = searcher.search(query);
    List list = new ArrayList(hits.length());
    for (int i = 0; i < hits.length(); i++) {
      Hit hit = new LuceneHit(hits, i);
      list.add(hit);
    }
    return list;
  }
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

            searcher = new IndexSearcher(idxFilePath);
            Term instIdTerm = new Term("workflow_inst_status", status);
            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

        try {
            searcher = new IndexSearcher(idxFilePath);
            Term instIdTerm = new Term("workflow_inst_id", workflowInstId);
            org.apache.lucene.search.Query query = new TermQuery(instIdTerm);
            Hits hits = searcher.search(query);

            if (hits.length() != 1) {
                LOG.log(Level.WARNING, "The workflow instance: ["
                        + workflowInstId + "] is not being "
                        + "managed by this " + "workflow engine, or "
                        + "is not unique in the catalog: num hits: ["+hits.length()+"]");
                return null;
            } else {
                Document instDoc = hits.doc(0);
                wInst = toWorkflowInstance(instDoc);
            }

        } catch (IOException e) {
            LOG.log(Level.WARNING,
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);

            if (hits.length() > 0) {
                wInsts = new Vector(hits.length());

                for (int i = 0; i < hits.length(); i++) {
                    Document doc = hits.doc(i);
                    WorkflowInstance wInst = toWorkflowInstance(doc);
                    wInsts.add(wInst);
                }
            }
View Full Code Here

            searcher = new IndexSearcher(idxFilePath);
            Term instIdTerm = new Term("workflow_inst_status", status);
            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);

            if (hits.length() > 0) {
                wInsts = new Vector(hits.length());

                for (int i = 0; i < hits.length(); i++) {
                    Document doc = hits.doc(i);
                    WorkflowInstance wInst = toWorkflowInstance(doc);
                    wInsts.add(wInst);
                }
            }
View Full Code Here

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

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

                instIds = new Vector(pageSize);

                for (int i = startNum; i < Math.min(hits.length(),
                        (startNum + pageSize)); i++) {
                    Document instDoc = hits.doc(i);
                    WorkflowInstance inst = toWorkflowInstance(instDoc);
                    instIds.add(inst.getId());

                }
            } else {
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.