Examples of PrefixQuery


Examples of org.apache.lucene.search.PrefixQuery

  }

  public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
    return new QParser(qstr, localParams, params, req) {
      public Query parse() throws ParseException {
        return new PrefixQuery(new Term(localParams.get(QueryParsing.F), localParams.get(QueryParsing.V)));
      }
    };
  }
View Full Code Here

Examples of org.apache.lucene.search.PrefixQuery

        assertThat(topDocs.totalHits, equalTo(1));

        FastVectorHighlighter highlighter = new FastVectorHighlighter();

        PrefixQuery prefixQuery = new PrefixQuery(new Term("content", "ba"));
        assertThat(prefixQuery.getRewriteMethod().getClass().getName(), equalTo(PrefixQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT.getClass().getName()));
        String fragment = highlighter.getBestFragment(highlighter.getFieldQuery(prefixQuery),
                reader, topDocs.scoreDocs[0].doc, "content", 30);
        assertThat(fragment, nullValue());

        prefixQuery.setRewriteMethod(PrefixQuery.SCORING_BOOLEAN_QUERY_REWRITE);
        Query rewriteQuery = prefixQuery.rewrite(reader);
        fragment = highlighter.getBestFragment(highlighter.getFieldQuery(rewriteQuery),
                reader, topDocs.scoreDocs[0].doc, "content", 30);
        assertThat(fragment, notNullValue());

        System.out.println(fragment);

        // now check with the custom field query
        prefixQuery = new PrefixQuery(new Term("content", "ba"));
        assertThat(prefixQuery.getRewriteMethod().getClass().getName(), equalTo(PrefixQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT.getClass().getName()));
        CustomFieldQuery.reader.set(reader);
        fragment = highlighter.getBestFragment(new CustomFieldQuery(prefixQuery, highlighter),
                reader, topDocs.scoreDocs[0].doc, "content", 30);
        assertThat(fragment, notNullValue());
View Full Code Here

Examples of org.apache.lucene.search.PrefixQuery

                fieldName = smartNameFieldMappers.mapper().names().indexName();
                value = smartNameFieldMappers.mapper().indexedValue(value);
            }
        }

        PrefixQuery query = new PrefixQuery(new Term(fieldName, value));
        query.setRewriteMethod(QueryParsers.parseRewriteMethod(rewriteMethod));
        query.setBoost(boost);
        return wrapSmartNameQuery(query, smartNameFieldMappers, parseContext);
    }
View Full Code Here

Examples of org.apache.lucene.search.PrefixQuery

        }
        phraseQuery.setSlop(pq.getSlop());
        return phraseQuery;
      }
    } else if (query instanceof PrefixQuery) {
      PrefixQuery pq = (PrefixQuery) query;
      Term term = pq.getPrefix();
      if (term.field().equals(BlurConstants.SUPER)) {
        return new PrefixQuery(new Term(name, term.bytes()));
      }
    } else if (query instanceof TermRangeQuery) {
      TermRangeQuery trq = (TermRangeQuery) query;
      BytesRef lowerTerm = trq.getLowerTerm();
      BytesRef upperTerm = trq.getUpperTerm();
View Full Code Here

Examples of org.apache.lucene.search.PrefixQuery

        if (path.equals("/")) {
            path = "";
        }
        switch (filter.getPathRestriction()) {
        case ALL_CHILDREN:
            qs.add(new PrefixQuery(new Term(":path", path + "/")));
            break;
        case DIRECT_CHILDREN:
            qs.add(new PrefixQuery(new Term(":path", path + "/"))); // FIXME
            break;
        case EXACT:
            qs.add(new TermQuery(new Term(":path", path)));
            break;
        case PARENT:
View Full Code Here

Examples of org.apache.lucene.search.PrefixQuery

        try {
            searcher = new IndexSearcher(IndexReader.open(writer, true));
            BooleanQuery query = new BooleanQuery();
            query.add(new TermQuery(new Term(MAILBOX_ID_FIELD, mailbox.getMailboxId().toString())), BooleanClause.Occur.MUST);
            // Not return flags documents
            query.add(new PrefixQuery(new Term(FLAGS_FIELD, "")), BooleanClause.Occur.MUST_NOT);
            List<Criterion> crits = searchQuery.getCriterias();
            for (int i = 0; i < crits.size(); i++) {
                query.add(createQuery(crits.get(i), mailbox, searchQuery.getRecentMessageUids()), BooleanClause.Occur.MUST);
            }
            
View Full Code Here

Examples of org.apache.lucene.search.PrefixQuery

     */
    private Query createTermQuery(String fieldName, String value) {
        if (suffixMatch) {
            return new WildcardQuery(new Term(fieldName, "*" + value + "*"));
        } else {
            return new PrefixQuery(new Term(fieldName, value));
        }
    }
View Full Code Here

Examples of org.apache.lucene.search.PrefixQuery

        String fieldName = PREFIX_HEADER_FIELD + name;
        if (op instanceof SearchQuery.ContainsOperator) {
            ContainsOperator cop = (ContainsOperator) op;
            return createTermQuery(fieldName, cop.getValue().toUpperCase(Locale.ENGLISH));
        } else if (op instanceof SearchQuery.ExistsOperator){
            return new PrefixQuery(new Term(fieldName, ""));
        } else if (op instanceof SearchQuery.DateOperator) {
                DateOperator dop = (DateOperator) op;
                String field = toSentDateField(dop.getDateResultion());
                return createQuery(field, dop);
        } else if (op instanceof SearchQuery.AddressOperator) {
View Full Code Here

Examples of org.apache.lucene.search.PrefixQuery

        if (isSet) {  
            query.add(new TermQuery(new Term(FLAGS_FIELD, flag)), BooleanClause.Occur.MUST);
        } else {
            // lucene does not support simple NOT queries so we do some nasty hack here
            BooleanQuery bQuery = new BooleanQuery();
            bQuery.add(new PrefixQuery(new Term(FLAGS_FIELD, "")), BooleanClause.Occur.MUST);
            bQuery.add(new TermQuery(new Term(FLAGS_FIELD, flag)),BooleanClause.Occur.MUST_NOT);
           
            query.add(bQuery, BooleanClause.Occur.MUST);
        }
        query.add(new TermQuery(new Term(MAILBOX_ID_FIELD, mailbox.getMailboxId().toString())), BooleanClause.Occur.MUST);
View Full Code Here

Examples of org.apache.lucene.search.PrefixQuery

     */
    private Query createAllQuery(SearchQuery.AllCriterion crit) throws UnsupportedSearchException{
        BooleanQuery query = new BooleanQuery();
       
        query.add(createQuery(MessageRange.all()), BooleanClause.Occur.MUST);
        query.add(new PrefixQuery(new Term(FLAGS_FIELD, "")), BooleanClause.Occur.MUST_NOT);
       
        return query;
    }
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.