コード例 #1
0
 private static void splitSources(
     int dim, List<ValueSource> sources, List<ValueSource> dest1, List<ValueSource> dest2) {
   // Get dim value sources for the first vector
   for (int i = 0; i < dim; i++) {
     dest1.add(sources.get(i));
   }
   // Get dim value sources for the second vector
   for (int i = dim; i < sources.size(); i++) {
     dest2.add(sources.get(i));
   }
 }
コード例 #2
0
  private static MVResult getMultiValueSources(List<ValueSource> sources) {
    MVResult mvr = new MVResult();
    if (sources.size() % 2 != 0) {
      throw new SolrException(
          SolrException.ErrorCode.BAD_REQUEST,
          "Illegal number of sources.  There must be an even number of sources");
    }
    if (sources.size() == 2) {

      // check to see if these are MultiValueSource
      boolean s1MV = sources.get(0) instanceof MultiValueSource;
      boolean s2MV = sources.get(1) instanceof MultiValueSource;
      if (s1MV && s2MV) {
        mvr.mv1 = (MultiValueSource) sources.get(0);
        mvr.mv2 = (MultiValueSource) sources.get(1);
      } else if (s1MV || s2MV) {
        // if one is a MultiValueSource, than the other one needs to be too.
        throw new SolrException(
            SolrException.ErrorCode.BAD_REQUEST,
            "Illegal number of sources.  There must be an even number of sources");
      } else {
        mvr.mv1 = new VectorValueSource(Collections.singletonList(sources.get(0)));
        mvr.mv2 = new VectorValueSource(Collections.singletonList(sources.get(1)));
      }
    } else {
      int dim = sources.size() / 2;
      List<ValueSource> sources1 = new ArrayList<>(dim);
      List<ValueSource> sources2 = new ArrayList<>(dim);
      // Get dim value sources for the first vector
      splitSources(dim, sources, sources1, sources2);
      mvr.mv1 = new VectorValueSource(sources1);
      mvr.mv2 = new VectorValueSource(sources2);
    }

    return mvr;
  }