当前位置: 首页>>代码示例>>Java>>正文


Java QueryBuilder类代码示例

本文整理汇总了Java中org.apache.lucene.util.QueryBuilder的典型用法代码示例。如果您正苦于以下问题:Java QueryBuilder类的具体用法?Java QueryBuilder怎么用?Java QueryBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


QueryBuilder类属于org.apache.lucene.util包,在下文中一共展示了QueryBuilder类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getQueryBuilder

import org.apache.lucene.util.QueryBuilder; //导入依赖的package包/类
public QueryBuilder getQueryBuilder() {
    return queryBuilder;
}
 
开发者ID:askplatypus,项目名称:platypus-kb-lucene,代码行数:4,代码来源:LuceneIndex.java

示例2: parseFieldQuery

import org.apache.lucene.util.QueryBuilder; //导入依赖的package包/类
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);
}
 
开发者ID:europeana,项目名称:search,代码行数:5,代码来源:TextField.java

示例3: parseFieldQuery

import org.apache.lucene.util.QueryBuilder; //导入依赖的package包/类
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);
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:6,代码来源:AlfrescoFieldType.java

示例4: getPhraseFieldQueries

import org.apache.lucene.util.QueryBuilder; //导入依赖的package包/类
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();
   }
 
开发者ID:shopping24,项目名称:solr-bmax-queryparser,代码行数:67,代码来源:BmaxLuceneQueryBuilder.java


注:本文中的org.apache.lucene.util.QueryBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。