org.apache.lucene.search.Query#getClass ( )源码实例Demo

下面列出了org.apache.lucene.search.Query#getClass ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: lucene-solr   文件: SpanNearClauseFactory.java
public void addSpanQuery(Query q) {
  if (q.getClass() == MatchNoDocsQuery.class)
    return;
  if (! (q instanceof SpanQuery))
    throw new AssertionError("Expected SpanQuery: " + q.toString(getFieldName()));
  float boost = 1f;
  if (q instanceof SpanBoostQuery) {
    SpanBoostQuery bq = (SpanBoostQuery) q;
    boost = bq.getBoost();
    q = bq.getQuery();
  }
  addSpanQueryWeighted((SpanQuery)q, boost);
}
 
源代码2 项目: lucene-solr   文件: ExtendedDismaxQParser.java
/**
 * Recursively examines the given query list for identical structure in all queries.
 * Boosts on BoostQuery-s are ignored, and the contained queries are instead used as the basis for comparison.
 **/
private boolean allSameQueryStructure(List<Query> lst) {
  boolean allSame = true;
  Query firstQuery = lst.get(0);
  if (firstQuery instanceof BoostQuery) {
    firstQuery = ((BoostQuery)firstQuery).getQuery(); // ignore boost; compare contained query
  }
  for (int n = 1 ; n < lst.size(); ++n) {
    Query nthQuery = lst.get(n);
    if (nthQuery instanceof BoostQuery) {
      nthQuery = ((BoostQuery)nthQuery).getQuery();
    }
    if (nthQuery.getClass() != firstQuery.getClass()) {
      allSame = false;
      break;
    }
    if (firstQuery instanceof BooleanQuery) {
      List<BooleanClause> firstBooleanClauses = ((BooleanQuery)firstQuery).clauses();
      List<BooleanClause> nthBooleanClauses = ((BooleanQuery)nthQuery).clauses();
      if (firstBooleanClauses.size() != nthBooleanClauses.size()) {
        allSame = false;
        break;
      }
      for (int c = 0 ; c < firstBooleanClauses.size() ; ++c) {
        if (nthBooleanClauses.get(c).getQuery().getClass() != firstBooleanClauses.get(c).getQuery().getClass()
            || nthBooleanClauses.get(c).getOccur() != firstBooleanClauses.get(c).getOccur()) {
          allSame = false;
          break;
        }
        if (firstBooleanClauses.get(c).getQuery() instanceof BooleanQuery && ! allSameQueryStructure
            (Arrays.asList(firstBooleanClauses.get(c).getQuery(), nthBooleanClauses.get(c).getQuery()))) {
          allSame = false;
          break;
        }
      }
    }
  }
  return allSame;
}
 
源代码3 项目: solr-redis   文件: QueryExtractor.java
/**
 * Method used for extracting inner queries using given collection of extractors.
 *
 * @param query Query to extract
 * @param extractors Extractors
 * @param extractedQueries Output parameter. List of extracted queries.
 *
 * @throws UnsupportedOperationException This method can trhow UnsupportedOperationException
 */
public static void extractQuery(final Query query, final Iterable<QueryExtractor<? extends Query>> extractors,
    final List<Query> extractedQueries) throws UnsupportedOperationException {
  for (final QueryExtractor extractor : extractors) {
    if (extractor.cls.isAssignableFrom(query.getClass())) {
      extractor.extract(query, extractors, extractedQueries);
      return;
    }
  }
  throw new UnsupportedOperationException("No extractor found for class: " + query.getClass());
}
 
源代码4 项目: solr-redis   文件: QueryExtractor.java
/**
 ** This static method is used for extracting inner queries field names using given extractros.
 *
 * @param query Query to extract field names from
 * @param extractors Extractors
 * @param extractedFields Output field names
 *
 * @throws UnsupportedOperationException This method can trhow UnsupportedOperationException
 */
public static void extractFields(final Query query, final Iterable<QueryExtractor<? extends Query>> extractors,
    final Set<String> extractedFields) throws UnsupportedOperationException {
  for (final QueryExtractor extractor : extractors) {
    if (extractor.getCls().isAssignableFrom(query.getClass())) {
      extractor.extractSubQueriesFields(query, extractors, extractedFields);
      return;
    }
  }
  throw new UnsupportedOperationException("No extractor found for class: " + query.getClass());
}
 
public static QueryWritableMapper lookup(Query query) {
  QueryWritableMapper type = queryToType.get(query.getClass());
  if (type == null) {
    throw new RuntimeException("Type [" + query.getClass() + "] for query [" + query + "] not found");
  }
  return type;
}
 
源代码6 项目: fess   文件: QueryHelper.java
protected QueryBuilder convertQuery(final QueryContext context, final Query query, final float boost) {
    if (query instanceof TermQuery) {
        return convertTermQuery(context, (TermQuery) query, boost);
    } else if (query instanceof TermRangeQuery) {
        return convertTermRangeQuery(context, (TermRangeQuery) query, boost);
    } else if (query instanceof PhraseQuery) {
        return convertPhraseQuery(context, (PhraseQuery) query, boost);
    } else if (query instanceof FuzzyQuery) {
        return convertFuzzyQuery(context, (FuzzyQuery) query, boost);
    } else if (query instanceof PrefixQuery) {
        return convertPrefixQuery(context, (PrefixQuery) query, boost);
    } else if (query instanceof WildcardQuery) {
        return convertWildcardQuery(context, (WildcardQuery) query, boost);
    } else if (query instanceof BooleanQuery) {
        final BooleanQuery booleanQuery = (BooleanQuery) query;
        return convertBooleanQuery(context, booleanQuery, boost);
    } else if (query instanceof MatchAllDocsQuery) {
        return QueryBuilders.matchAllQuery();
    } else if (query instanceof BoostQuery) {
        final BoostQuery boostQuery = (BoostQuery) query;
        return convertQuery(context, boostQuery.getQuery(), boostQuery.getBoost());
    }
    throw new InvalidQueryException(messages -> messages.addErrorsInvalidQueryUnknown(UserMessages.GLOBAL_PROPERTY_KEY), "Unknown q: "
            + query.getClass() + " => " + query);
}
 
源代码7 项目: lucene-solr   文件: DirectUpdateHandler2.java
@Override
public void deleteByQuery(DeleteUpdateCommand cmd) throws IOException {
  TestInjection.injectDirectUpdateLatch();
  deleteByQueryCommands.increment();
  deleteByQueryCommandsCumulative.mark();
  boolean madeIt=false;
  try {
    if ((cmd.getFlags() & UpdateCommand.IGNORE_INDEXWRITER) != 0) {
      if (ulog != null) ulog.deleteByQuery(cmd);
      madeIt = true;
      return;
    }
    Query q = getQuery(cmd);
    
    boolean delAll = MatchAllDocsQuery.class == q.getClass();

    // currently for testing purposes.  Do a delete of complete index w/o worrying about versions, don't log, clean up most state in update log, etc
    if (delAll && cmd.getVersion() == -Long.MAX_VALUE) {
      synchronized (solrCoreState.getUpdateLock()) {
        deleteAll();
        ulog.deleteAll();
        return;
      }
    }

    //
    // synchronized to prevent deleteByQuery from running during the "open new searcher"
    // part of a commit.  DBQ needs to signal that a fresh reader will be needed for
    // a realtime view of the index.  When a new searcher is opened after a DBQ, that
    // flag can be cleared.  If those thing happen concurrently, it's not thread safe.
    // Also, ulog.deleteByQuery clears caches and is thus not safe to be called between
    // preSoftCommit/postSoftCommit and thus we use the updateLock to prevent this (just
    // as we use around ulog.preCommit... also see comments in ulog.postSoftCommit)
    //
    synchronized (solrCoreState.getUpdateLock()) {

      // We are reopening a searcher before applying the deletes to overcome LUCENE-7344.
      // Once LUCENE-7344 is resolved, we can consider removing this.
      if (ulog != null) ulog.openRealtimeSearcher();

      if (delAll) {
        deleteAll();
      } else {
        RefCounted<IndexWriter> iw = solrCoreState.getIndexWriter(core);
        try {
          iw.get().deleteDocuments(new DeleteByQueryWrapper(q, core.getLatestSchema()));
        } finally {
          iw.decref();
        }
      }

      if (ulog != null) ulog.deleteByQuery(cmd);  // this needs to be protected by the update lock
    }

    madeIt = true;

    updateDeleteTrackers(cmd);

  } finally {
    if (!madeIt) {
      numErrors.increment();
      numErrorsCumulative.mark();
    }
  }
}