public QueryBuilder getQueryBuilder() { return queryBuilder; }
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); }
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(); }