You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by da...@apache.org on 2017/03/29 07:07:11 UTC
lucene-solr:branch_6x: SOLR-9993: Add support for ExpandComponent
with PointFields
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x bcc36b900 -> 40a9568d5
SOLR-9993: Add support for ExpandComponent with PointFields
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/40a9568d
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/40a9568d
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/40a9568d
Branch: refs/heads/branch_6x
Commit: 40a9568d59cd610265304fc94d0ba439e7a90ab4
Parents: bcc36b9
Author: Cao Manh Dat <da...@apache.org>
Authored: Wed Mar 29 14:07:01 2017 +0700
Committer: Cao Manh Dat <da...@apache.org>
Committed: Wed Mar 29 14:07:01 2017 +0700
----------------------------------------------------------------------
solr/CHANGES.txt | 2 +
.../solr/handler/component/ExpandComponent.java | 75 +++++++++++++-------
.../handler/component/TestExpandComponent.java | 2 -
3 files changed, 53 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/40a9568d/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 4114558..2794645 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -53,6 +53,8 @@ New Features
* SOLR-10349: Add totalTermFreq support to TermsComponent. (Shai Erera)
+* SOLR-9993: Add support for ExpandComponent with PointFields. (Cao Manh Dat)
+
Optimizations
----------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/40a9568d/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java b/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
index fb85d34..84f38f9 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java
@@ -73,7 +73,12 @@ import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.core.PluginInfo;
import org.apache.solr.core.SolrCore;
import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.schema.DoublePointField;
import org.apache.solr.schema.FieldType;
+import org.apache.solr.schema.FloatPointField;
+import org.apache.solr.schema.IntPointField;
+import org.apache.solr.schema.LongPointField;
+import org.apache.solr.schema.SchemaField;
import org.apache.solr.schema.StrField;
import org.apache.solr.schema.TrieDoubleField;
import org.apache.solr.schema.TrieFloatField;
@@ -209,7 +214,8 @@ public class ExpandComponent extends SearchComponent implements PluginInfoInitia
SolrIndexSearcher searcher = req.getSearcher();
LeafReader reader = searcher.getSlowAtomicReader();
- FieldType fieldType = searcher.getSchema().getField(field).getType();
+ SchemaField schemaField = searcher.getSchema().getField(field);
+ FieldType fieldType = schemaField.getType();
SortedDocValues values = null;
long nullValue = 0;
@@ -228,17 +234,18 @@ public class ExpandComponent extends SearchComponent implements PluginInfoInitia
//Get the nullValue for the numeric collapse field
String defaultValue = searcher.getSchema().getField(field).getDefaultValue();
if(defaultValue != null) {
- if(fieldType instanceof TrieIntField || fieldType instanceof TrieLongField) {
+ if(fieldType instanceof TrieIntField || fieldType instanceof TrieLongField ||
+ fieldType instanceof IntPointField || fieldType instanceof LongPointField) {
nullValue = Long.parseLong(defaultValue);
- } else if(fieldType instanceof TrieFloatField){
+ } else if(fieldType instanceof TrieFloatField || fieldType instanceof FloatPointField){
nullValue = Float.floatToIntBits(Float.parseFloat(defaultValue));
- } else if(fieldType instanceof TrieDoubleField){
+ } else if(fieldType instanceof TrieDoubleField || fieldType instanceof DoublePointField){
nullValue = Double.doubleToLongBits(Double.parseDouble(defaultValue));
}
} else {
- if(fieldType instanceof TrieFloatField){
+ if(fieldType instanceof TrieFloatField || fieldType instanceof FloatPointField){
nullValue = Float.floatToIntBits(0.0f);
- } else if(fieldType instanceof TrieDoubleField){
+ } else if(fieldType instanceof TrieDoubleField || fieldType instanceof DoublePointField){
nullValue = Double.doubleToLongBits(0.0f);
}
}
@@ -354,7 +361,11 @@ public class ExpandComponent extends SearchComponent implements PluginInfoInitia
}
if(count > 0 && count < 200) {
- groupQuery = getGroupQuery(field, fieldType, count, groupSet);
+ if (fieldType.isPointField()) {
+ groupQuery = getPointGroupQuery(schemaField, count, groupSet);
+ } else {
+ groupQuery = getGroupQuery(field, fieldType, count, groupSet);
+ }
}
}
@@ -417,13 +428,7 @@ public class ExpandComponent extends SearchComponent implements PluginInfoInitia
String group = charsRef.toString();
outMap.add(group, slice);
} else {
- if(fieldType instanceof TrieIntField || fieldType instanceof TrieLongField ) {
- outMap.add(Long.toString(groupValue), slice);
- } else if(fieldType instanceof TrieFloatField) {
- outMap.add(Float.toString(Float.intBitsToFloat((int) groupValue)), slice);
- } else if(fieldType instanceof TrieDoubleField) {
- outMap.add(Double.toString(Double.longBitsToDouble(groupValue)), slice);
- }
+ outMap.add(numericToString(fieldType, groupValue), slice);
}
}
}
@@ -659,18 +664,10 @@ public class ExpandComponent extends SearchComponent implements PluginInfoInitia
BytesRefBuilder term = new BytesRefBuilder();
Iterator<LongCursor> it = groupSet.iterator();
int index = -1;
- String stringVal = null;
+
while (it.hasNext()) {
LongCursor cursor = it.next();
- if(ft instanceof TrieIntField || ft instanceof TrieLongField) {
- stringVal = Long.toString(cursor.value);
- } else {
- if(ft instanceof TrieFloatField) {
- stringVal = Float.toString(Float.intBitsToFloat((int)cursor.value));
- } else {
- stringVal = Double.toString(Double.longBitsToDouble(cursor.value));
- }
- }
+ String stringVal = numericToString(ft, cursor.value);
ft.readableToIndexed(stringVal, term);
bytesRefs[++index] = term.toBytesRef();
}
@@ -678,6 +675,36 @@ public class ExpandComponent extends SearchComponent implements PluginInfoInitia
return new SolrConstantScoreQuery(new QueryWrapperFilter(new TermInSetQuery(fname, bytesRefs)));
}
+ private Query getPointGroupQuery(SchemaField sf,
+ int size,
+ LongHashSet groupSet) {
+
+ Iterator<LongCursor> it = groupSet.iterator();
+ List<String> values = new ArrayList<>(size);
+ FieldType ft = sf.getType();
+ while (it.hasNext()) {
+ LongCursor cursor = it.next();
+ values.add(numericToString(ft, cursor.value));
+ }
+
+ return new SolrConstantScoreQuery(new QueryWrapperFilter(sf.getType().getSetQuery(null, sf, values)));
+ }
+
+ private String numericToString(FieldType fieldType, long val) {
+ if (fieldType.getNumberType() != null) {
+ switch (fieldType.getNumberType()) {
+ case INTEGER:
+ case LONG:
+ return Long.toString(val);
+ case FLOAT:
+ return Float.toString(Float.intBitsToFloat((int)val));
+ case DOUBLE:
+ return Double.toString(Double.longBitsToDouble(val));
+ }
+ }
+ throw new IllegalArgumentException("FieldType must be INT,LONG,FLOAT,DOUBLE found " + fieldType);
+ }
+
private Query getGroupQuery(String fname,
int size,
IntObjectHashMap<BytesRef> ordBytes) throws Exception {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/40a9568d/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java b/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java
index 7baa5a9..d1906d5 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/TestExpandComponent.java
@@ -21,14 +21,12 @@ import java.util.Collections;
import java.util.List;
import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.SolrTestCaseJ4.SuppressPointFields;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.search.CollapsingQParserPlugin;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-@SuppressPointFields
public class TestExpandComponent extends SolrTestCaseJ4 {
@BeforeClass