public static Query createJoinQuery(String fromField,boolean multipleValuesPerDocument,String toField,Query fromQuery,IndexSearcher fromSearcher,ScoreMode scoreMode) throws IOException {final GenericTermsCollector termsWithScoreCollector;if (multipleValuesPerDocument) {Function<SortedSetDocValues> mvFunction = DocValuesTermsCollector.sortedSetDocValues(fromField);termsWithScoreCollector = GenericTermsCollector.createCollectorMV(mvFunction, scoreMode);} else {Function<BinaryDocValues> svFunction = DocValuesTermsCollector.binaryDocValues(fromField);termsWithScoreCollector = GenericTermsCollector.createCollectorSV(svFunction, scoreMode);}return createJoinQuery(multipleValuesPerDocument, toField, fromQuery, fromField, fromSearcher, scoreMode, termsWithScoreCollector);}

public static Query CreateJoinQuery(string fromField, bool multipleValuesPerDocument, string toField, Query fromQuery, IndexSearcher fromSearcher, ScoreMode scoreMode){switch (scoreMode){case ScoreMode.None:TermsCollector termsCollector = TermsCollector.Create(fromField, multipleValuesPerDocument);fromSearcher.Search(fromQuery, termsCollector);return new TermsQuery(toField, fromQuery, termsCollector.CollectorTerms);case ScoreMode.Total:case ScoreMode.Max:case ScoreMode.Avg:TermsWithScoreCollector termsWithScoreCollector = TermsWithScoreCollector.Create(fromField, multipleValuesPerDocument, scoreMode);fromSearcher.Search(fromQuery, termsWithScoreCollector);return new TermsIncludingScoreQuery(toField, multipleValuesPerDocument, termsWithScoreCollector.CollectedTerms, termsWithScoreCollector.ScoresPerTerm, fromQuery);default:throw new System.ArgumentException(string.Format("Score mode {0} isn't supported.", scoreMode));}}
