lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject [2/2] lucene-solr:master: SOLR-8871 - adjusted header positioning
Date Fri, 25 Nov 2016 00:11:28 GMT
SOLR-8871 - adjusted header positioning


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/96489d23
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/96489d23
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/96489d23

Branch: refs/heads/master
Commit: 96489d23846a6ed93ec663afb84a520858d66d15
Parents: 5ad741e
Author: Tommaso Teofili <tommaso@apache.org>
Authored: Thu Nov 24 23:46:20 2016 +0100
Committer: Tommaso Teofili <tommaso@apache.org>
Committed: Thu Nov 24 23:46:20 2016 +0100

----------------------------------------------------------------------
 .../KNearestNeighborClassifier.java             |  8 +++--
 .../KNearestNeighborDocumentClassifier.java     |  6 ++--
 .../ClassificationUpdateProcessorTest.java      | 33 ++++++++++----------
 3 files changed, 24 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/96489d23/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java
----------------------------------------------------------------------
diff --git a/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java
b/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java
index c4f2c2f..77f0416 100644
--- a/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java
+++ b/lucene/classification/src/java/org/apache/lucene/classification/KNearestNeighborClassifier.java
@@ -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
     float maxScore = topDocs.getMaxScore();
     for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
-      IndexableField storableField = indexSearcher.doc(scoreDoc.doc).getField(classFieldName);
-      if (storableField != null) {
-        BytesRef cl = new BytesRef(storableField.stringValue());
+      IndexableField[] storableFields = indexSearcher.doc(scoreDoc.doc).getFields(classFieldName);
+      for (IndexableField singleStorableField : storableFields) {
+        if (singleStorableField != null) {
+          BytesRef cl = new BytesRef(singleStorableField.stringValue());
         //update count
         Integer count = classCounts.get(cl);
         if (count != null) {
@@ -213,6 +214,7 @@ public class KNearestNeighborClassifier implements Classifier<BytesRef>
{
         } else {
           classBoosts.put(cl, singleBoost);
         }
+        }
       }
     }
     List<ClassificationResult<BytesRef>> returnList = new ArrayList<>();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/96489d23/lucene/classification/src/java/org/apache/lucene/classification/document/KNearestNeighborDocumentClassifier.java
----------------------------------------------------------------------
diff --git a/lucene/classification/src/java/org/apache/lucene/classification/document/KNearestNeighborDocumentClassifier.java
b/lucene/classification/src/java/org/apache/lucene/classification/document/KNearestNeighborDocumentClassifier.java
index 342ee08..e01090a 100644
--- a/lucene/classification/src/java/org/apache/lucene/classification/document/KNearestNeighborDocumentClassifier.java
+++ b/lucene/classification/src/java/org/apache/lucene/classification/document/KNearestNeighborDocumentClassifier.java
@@ -109,6 +109,7 @@ public class KNearestNeighborDocumentClassifier extends KNearestNeighborClassifi
     TopDocs knnResults = knnSearch(document);
     List<ClassificationResult<BytesRef>> assignedClasses = buildListFromTopDocs(knnResults);
     Collections.sort(assignedClasses);
+    max = Math.min(max, assignedClasses.size());
     return assignedClasses.subList(0, max);
   }
 
@@ -130,15 +131,14 @@ public class KNearestNeighborDocumentClassifier extends KNearestNeighborClassifi
         boost = field2boost[1];
       }
       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) {
-        mlt.setBoost(true);
-        mlt.setBoostFactor(Float.parseFloat(boost));
+        mlt.setBoostFactor(Float.parseFloat(boost)); // this is an additional multiplicative
boost coming from the field boost
       }
       mlt.setAnalyzer(field2analyzer.get(fieldName));
       for (String fieldContent : fieldValues) {
         mltQuery.add(new BooleanClause(mlt.like(fieldName, new StringReader(fieldContent)),
BooleanClause.Occur.SHOULD));
       }
-      mlt.setBoost(false);
     }
     Query classFieldQuery = new WildcardQuery(new Term(classFieldName, "*"));
     mltQuery.add(new BooleanClause(classFieldQuery, BooleanClause.Occur.MUST));

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/96489d23/solr/core/src/test/org/apache/solr/update/processor/ClassificationUpdateProcessorTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/update/processor/ClassificationUpdateProcessorTest.java
b/solr/core/src/test/org/apache/solr/update/processor/ClassificationUpdateProcessorTest.java
index 938dfc5..432bb02 100644
--- a/solr/core/src/test/org/apache/solr/update/processor/ClassificationUpdateProcessorTest.java
+++ b/solr/core/src/test/org/apache/solr/update/processor/ClassificationUpdateProcessorTest.java
@@ -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;
 
 import java.io.IOException;
@@ -24,23 +40,6 @@ import org.junit.Test;
 import static org.hamcrest.core.Is.is;
 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}
  */


Mime
View raw message