Java 类org.apache.lucene.util.QueryBuilder 实例源码

项目:platypus-kb-lucene    文件:LuceneIndex.java   
public QueryBuilder getQueryBuilder() {
    return queryBuilder;
}
项目:search    文件:TextField.java   
static Query parseFieldQuery(QParser parser, Analyzer analyzer, String field, String queryText) {
  // note, this method always worked this way (but nothing calls it?) because it has no idea of quotes...
  return new QueryBuilder(analyzer).createPhraseQuery(field, queryText);
}
项目:community-edition-old    文件:AlfrescoFieldType.java   
static Query parseFieldQuery(QParser parser, Analyzer analyzer, String field, String queryText)
{
    // note, this method always worked this way (but nothing calls it?) because it has no idea of quotes...
    return new QueryBuilder(analyzer).createPhraseQuery(field, queryText);
}
项目:solr-bmax-queryparser    文件:BmaxLuceneQueryBuilder.java   
protected Optional<Query> getPhraseFieldQueries()  {

      // sloppy phrase queries for proximity
      final List<FieldParams> allPhraseFields = bmaxquery.getAllPhraseFields();

      if (!allPhraseFields.isEmpty()) {

         final List<BmaxTerm> bmaxTerms = bmaxquery.getTerms();

         if (bmaxTerms.size() > 1) { // it's a phrase

            final List<CharSequence> terms = bmaxTerms.stream().map(BmaxTerm::getTerm).collect(Collectors.toList());
            final List<Query> disjuncts = new LinkedList<>();

            final QueryBuilder queryBuilder = new QueryBuilder(schema.getQueryAnalyzer());

            // memoization of phrase shingles
            final Map<Integer, List<String>> shingles = new HashMap<>(2);

            // build phrase queries for the phrase query fields
            for (final FieldParams fieldParams : allPhraseFields) {

               final int phraseLength = fieldParams.getWordGrams();
               final int slop = fieldParams.getSlop();
               final String fieldname = fieldParams.getField();

               // get/create field-independent bi-gram or tri-gram strings
               final List<String> shinglesN = shingles.computeIfAbsent(phraseLength, n -> buildNGrams(terms, n));

               // map bi-gram/tri-gram strings to phrase queries
               final List<Query> nGramQueries = shinglesN.stream()
                       .map(nGram ->  queryBuilder.createPhraseQuery(fieldname, nGram, slop))
                       .filter(Objects::nonNull)
                       .collect(Collectors.toList());

               switch (nGramQueries.size()) {
                  case 0: break;
                  case 1: {
                     disjuncts.add(withBoostFactor(nGramQueries.get(0), fieldParams.getBoost()));
                     break;
                  }
                  default:
                     // If we have > 1 n-gram phrase for this field, aggregate their scores using
                     // a BooleanQuery with all clauses being optional
                     final BooleanQuery.Builder builder = new BooleanQuery.Builder()
                             .setMinimumNumberShouldMatch(1);

                     for (final Query nGramQuery : nGramQueries) {
                        builder.add(nGramQuery, BooleanClause.Occur.SHOULD);
                     }

                     disjuncts.add(withBoostFactor(builder.build(), fieldParams.getBoost()));
               }
            }

            switch (disjuncts.size()) {
               case 0: break;
               case 1: return Optional.of(disjuncts.get(0));
               default :
                  return Optional.of(new DisjunctionMaxQuery(disjuncts, bmaxquery.getPhraseBoostTieBreaker()));
            }
         }
      }

      return empty();
   }
项目:read-open-source-code    文件:TextField.java   
static Query parseFieldQuery(QParser parser, Analyzer analyzer, String field, String queryText) {
  // note, this method always worked this way (but nothing calls it?) because it has no idea of quotes...
  return new QueryBuilder(analyzer).createPhraseQuery(field, queryText);
}
项目:read-open-source-code    文件:TextField.java   
static Query parseFieldQuery(QParser parser, Analyzer analyzer, String field, String queryText) {
  // note, this method always worked this way (but nothing calls it?) because it has no idea of quotes...
  return new QueryBuilder(analyzer).createPhraseQuery(field, queryText);
}