private static Query createJoinQuery(boolean multipleValuesPerDocument, String toField, Query fromQuery, IndexSearcher fromSearcher, ScoreMode scoreMode, final GenericTermsCollector collector) throws IOException { fromSearcher.search(fromQuery, collector); switch (scoreMode) { case None: return new TermsQuery(toField, fromQuery, collector.getCollectedTerms()); case Total: case Max: case Min: case Avg: return new TermsIncludingScoreQuery( toField, multipleValuesPerDocument, collector.getCollectedTerms(), collector.getScoresPerTerm(), fromQuery ); default: throw new IllegalArgumentException(String.format(Locale.ROOT, "Score mode %s isn't supported.", scoreMode)); } }