Package org.apache.lucene.search

Examples of org.apache.lucene.search.Sort


   *
   * @param sorting
   * @return
   */
  private Sort createSort(final String[] sorting) {
    Sort ret = null;
    ArrayList<SortField> sortFields = new ArrayList<SortField>();
    for (String s : sorting) {
      // split attribute on :. First element is attribute name the
      // second is the direction
      String[] sort = s.split(":");

      if (sort[0] != null) {
        boolean reverse;
        if ("desc".equals(sort[1].toLowerCase())) {
          reverse = true;
        } else {
          reverse = false;
        }
        if ("score".equalsIgnoreCase(sort[0])) {
          sortFields.add(SortField.FIELD_SCORE);
        } else {
          sortFields.add(new SortField(sort[0], Locale.getDefault(), reverse));
        }
      }

    }
    ret = new Sort(sortFields.toArray(new SortField[] {}));

    return ret;
  }
View Full Code Here


    IndexAccessor ia = autocompleteLocation.getAccessor();
    Searcher autoCompleteSearcher = ia.getPrioritizedSearcher();
    IndexReader autoCompleteReader = ia.getReader(false);
    try {
      Query query = new TermQuery(new Term(GRAMMED_WORDS_FIELD, term));
      Sort sort = new Sort(new SortField(COUNT_FIELD, SortField.LONG, true));
      TopDocs docs = autoCompleteSearcher.search(query, null, 5, sort);
      int id = 1;
      for (ScoreDoc doc : docs.scoreDocs) {
        CRResolvableBean bean = new CRResolvableBean(id++);
        Document d = autoCompleteReader.document(doc.doc);
View Full Code Here

                                             boolean[] orderSpecs,
                                             long resultFetchHint)
            throws IOException {
        checkOpen();

        Sort sort = new Sort(createSortFields(orderProps, orderSpecs));

        final IndexReader reader = getIndexReader(queryImpl.needsSystemTree());
        JackrabbitIndexSearcher searcher = new JackrabbitIndexSearcher(
                session, reader, getContext().getItemStateManager());
        searcher.setSimilarity(getSimilarity());
View Full Code Here

        }

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

                                             boolean[] orderSpecs,
                                             long resultFetchHint)
            throws IOException {
        checkOpen();

        Sort sort = new Sort(createSortFields(orderProps, orderSpecs));

        final IndexReader reader = getIndexReader(queryImpl.needsSystemTree());
        JackrabbitIndexSearcher searcher = new JackrabbitIndexSearcher(
                session, reader, getContext().getItemStateManager());
        searcher.setSimilarity(getSimilarity());
View Full Code Here

                                             boolean[] orderSpecs,
                                             long resultFetchHint)
            throws IOException {
        checkOpen();

        Sort sort = new Sort(createSortFields(orderProps, orderSpecs));

        final IndexReader reader = getIndexReader(queryImpl.needsSystemTree());
        JackrabbitIndexSearcher searcher = new JackrabbitIndexSearcher(
                session, reader, getContext().getItemStateManager());
        searcher.setSimilarity(getSimilarity());
View Full Code Here

    SimpleBindings bindings = new SimpleBindings();   
    bindings.add(new SortField("_score", SortField.Type.SCORE));
    bindings.add(new SortField("popularity", SortField.Type.INT));
   
    // create a sort field and sort by it (reverse order)
    Sort sort = new Sort(expr.getSortField(bindings, true));
    Query query = new TermQuery(new Term("body", "contents"));
    searcher.search(query, null, 3, sort);
  }
View Full Code Here

    Expression expr = JavascriptCompiler.compile("sqrt(_score)");
   
    SimpleBindings bindings = new SimpleBindings();   
    bindings.add(new SortField("_score", SortField.Type.SCORE));
   
    Sort sort = new Sort(expr.getSortField(bindings, true));
    Query query = new TermQuery(new Term("body", "contents"));
    TopFieldDocs td = searcher.search(query, null, 3, sort, true, true);
    for (int i = 0; i < 3; i++) {
      FieldDoc d = (FieldDoc) td.scoreDocs[i];
      float expected = (float) Math.sqrt(d.score);
View Full Code Here

    Expression expr = JavascriptCompiler.compile("_score + _score");
   
    SimpleBindings bindings = new SimpleBindings();   
    bindings.add(new SortField("_score", SortField.Type.SCORE));
   
    Sort sort = new Sort(expr.getSortField(bindings, true));
    Query query = new TermQuery(new Term("body", "contents"));
    TopFieldDocs td = searcher.search(query, null, 3, sort, true, true);
    for (int i = 0; i < 3; i++) {
      FieldDoc d = (FieldDoc) td.scoreDocs[i];
      float expected = 2*d.score;
 
View Full Code Here

   
    SimpleBindings bindings = new SimpleBindings();   
    bindings.add(new SortField("_score", SortField.Type.SCORE));
    bindings.add("expr1", expr1);
   
    Sort sort = new Sort(expr2.getSortField(bindings, true));
    Query query = new TermQuery(new Term("body", "contents"));
    TopFieldDocs td = searcher.search(query, null, 3, sort, true, true);
    for (int i = 0; i < 3; i++) {
      FieldDoc d = (FieldDoc) td.scoreDocs[i];
      float expected = 2*d.score;
 
View Full Code Here

TOP

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

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.