SOLR-8871 - adjusted header positioning

This commit is contained in:
Tommaso Teofili 2016-11-24 23:46:20 +01:00
parent 5ad741eef8
commit 96489d2384
3 changed files with 24 additions and 23 deletions

View File

@ -195,9 +195,10 @@ public class KNearestNeighborClassifier implements Classifier<BytesRef> {
Map<BytesRef, Double> classBoosts = new HashMap<>(); // this is a boost based on class ranking positions in topDocs Map<BytesRef, Double> classBoosts = new HashMap<>(); // this is a boost based on class ranking positions in topDocs
float maxScore = topDocs.getMaxScore(); float maxScore = topDocs.getMaxScore();
for (ScoreDoc scoreDoc : topDocs.scoreDocs) { for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
IndexableField storableField = indexSearcher.doc(scoreDoc.doc).getField(classFieldName); IndexableField[] storableFields = indexSearcher.doc(scoreDoc.doc).getFields(classFieldName);
if (storableField != null) { for (IndexableField singleStorableField : storableFields) {
BytesRef cl = new BytesRef(storableField.stringValue()); if (singleStorableField != null) {
BytesRef cl = new BytesRef(singleStorableField.stringValue());
//update count //update count
Integer count = classCounts.get(cl); Integer count = classCounts.get(cl);
if (count != null) { if (count != null) {
@ -213,6 +214,7 @@ public class KNearestNeighborClassifier implements Classifier<BytesRef> {
} else { } else {
classBoosts.put(cl, singleBoost); classBoosts.put(cl, singleBoost);
} }
}
} }
} }
List<ClassificationResult<BytesRef>> returnList = new ArrayList<>(); List<ClassificationResult<BytesRef>> returnList = new ArrayList<>();

View File

@ -109,6 +109,7 @@ public class KNearestNeighborDocumentClassifier extends KNearestNeighborClassifi
TopDocs knnResults = knnSearch(document); TopDocs knnResults = knnSearch(document);
List<ClassificationResult<BytesRef>> assignedClasses = buildListFromTopDocs(knnResults); List<ClassificationResult<BytesRef>> assignedClasses = buildListFromTopDocs(knnResults);
Collections.sort(assignedClasses); Collections.sort(assignedClasses);
max = Math.min(max, assignedClasses.size());
return assignedClasses.subList(0, max); return assignedClasses.subList(0, max);
} }
@ -130,15 +131,14 @@ public class KNearestNeighborDocumentClassifier extends KNearestNeighborClassifi
boost = field2boost[1]; boost = field2boost[1];
} }
String[] fieldValues = document.getValues(fieldName); String[] fieldValues = document.getValues(fieldName);
mlt.setBoost(true); // we want always to use the boost coming from TF * IDF of the term
if (boost != null) { if (boost != null) {
mlt.setBoost(true); mlt.setBoostFactor(Float.parseFloat(boost)); // this is an additional multiplicative boost coming from the field boost
mlt.setBoostFactor(Float.parseFloat(boost));
} }
mlt.setAnalyzer(field2analyzer.get(fieldName)); mlt.setAnalyzer(field2analyzer.get(fieldName));
for (String fieldContent : fieldValues) { for (String fieldContent : fieldValues) {
mltQuery.add(new BooleanClause(mlt.like(fieldName, new StringReader(fieldContent)), BooleanClause.Occur.SHOULD)); mltQuery.add(new BooleanClause(mlt.like(fieldName, new StringReader(fieldContent)), BooleanClause.Occur.SHOULD));
} }
mlt.setBoost(false);
} }
Query classFieldQuery = new WildcardQuery(new Term(classFieldName, "*")); Query classFieldQuery = new WildcardQuery(new Term(classFieldName, "*"));
mltQuery.add(new BooleanClause(classFieldQuery, BooleanClause.Occur.MUST)); mltQuery.add(new BooleanClause(classFieldQuery, BooleanClause.Occur.MUST));

View File

@ -1,3 +1,19 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.update.processor; package org.apache.solr.update.processor;
import java.io.IOException; import java.io.IOException;
@ -24,23 +40,6 @@ import org.junit.Test;
import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.is;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** /**
* Tests for {@link ClassificationUpdateProcessor} * Tests for {@link ClassificationUpdateProcessor}
*/ */