Skip to content

Commit

Permalink
SOLR-2949: Fix for QueryElevationComponent does not fully support dis…
Browse files Browse the repository at this point in the history
…tributed search
  • Loading branch information
markrmiller committed Mar 16, 2012
1 parent ae98b4d commit d73db1c
Showing 1 changed file with 5 additions and 28 deletions.
Expand Up @@ -399,7 +399,7 @@ public void prepare(ResponseBuilder rb) throws IOException {
SortSpec sortSpec = rb.getSortSpec();
if (sortSpec.getSort() == null) {
sortSpec.setSort(new Sort(new SortField[]{
new SortField(idField, comparator, false),
new SortField("_elevate_", comparator, true),
new SortField(null, SortField.Type.SCORE, false)
}));
} else {
Expand All @@ -409,12 +409,12 @@ public void prepare(ResponseBuilder rb) throws IOException {
ArrayList<SortField> sorts = new ArrayList<SortField>(current.length + 1);
// Perhaps force it to always sort by score
if (force && current[0].getType() != SortField.Type.SCORE) {
sorts.add(new SortField(idField, comparator, false));
sorts.add(new SortField("_elevate_", comparator, true));
modify = true;
}
for (SortField sf : current) {
if (sf.getType() == SortField.Type.SCORE) {
sorts.add(new SortField(idField, comparator, sf.getReverse()));
sorts.add(new SortField("_elevate_", comparator, sf.getReverse()));
modify = true;
}
sorts.add(sf);
Expand Down Expand Up @@ -450,29 +450,6 @@ public void prepare(ResponseBuilder rb) throws IOException {
public void process(ResponseBuilder rb) throws IOException {
// Do nothing -- the real work is modifying the input query
}

@Override
public int distributedProcess(ResponseBuilder rb) throws IOException {
// TODO: this is a hackey way to get distrib working - we need to reverse all the sorts
SortSpec sortSpec = rb.getSortSpec();
Sort sort = sortSpec.getSort();
if (sort != null) {
SortField[] sorts = sort.getSort();
List<SortField> sortsList = new ArrayList<SortField>(sorts.length);
for (SortField s : sorts) {
if (s.getComparatorSource() != null) {
FieldComparatorSource cs = s.getComparatorSource();
sortsList.add(new SortField(s.getField(), cs, true));
} else if (s.getParser() != null) {
sortsList.add(new SortField(s.getField(), s.getParser(), true));
} else {
sortsList.add(new SortField(s.getField(), s.getType(), true));
}
}
rb.getSortSpec().getSort().setSort(sortsList.toArray(new SortField[0]));
}
return super.distributedProcess(rb);
}

//---------------------------------------------------------------------------------
// SolrInfoMBean
Expand Down Expand Up @@ -531,7 +508,7 @@ public FieldComparator<Integer> newComparator(final String fieldname, final int

@Override
public int compare(int slot1, int slot2) {
return values[slot2] - values[slot1]; // values will be small enough that there is no overflow concern
return values[slot1] - values[slot2]; // values will be small enough that there is no overflow concern
}

@Override
Expand All @@ -553,7 +530,7 @@ private int docVal(int doc) throws IOException {

@Override
public int compareBottom(int doc) throws IOException {
return docVal(doc) - bottomVal;
return bottomVal - docVal(doc);
}

@Override
Expand Down

0 comments on commit d73db1c

Please sign in to comment.