You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2012/03/19 18:08:09 UTC
svn commit: r1302541 - in /lucene/dev/trunk/solr/core/src:
java/org/apache/solr/handler/component/ test-files/solr/conf/
test/org/apache/solr/handler/component/
Author: yonik
Date: Mon Mar 19 17:08:08 2012
New Revision: 1302541
URL: http://svn.apache.org/viewvc?rev=1302541&view=rev
Log:
SOLR-2949: distrib support for QEC
Added:
lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryElevationComponentTest.java (with props)
Modified:
lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java
lucene/dev/trunk/solr/core/src/test-files/solr/conf/elevate.xml
lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java?rev=1302541&r1=1302540&r2=1302541&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java Mon Mar 19 17:08:08 2012
@@ -21,7 +21,6 @@ import org.apache.lucene.analysis.Analyz
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.index.*;
-import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.search.*;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
@@ -234,9 +233,17 @@ public class QueryElevationComponent ext
"QueryElevationComponent must specify argument: " + CONFIG_FILE);
}
log.info("Loading QueryElevation from data dir: " + f);
-
- InputStream is = VersionedFile.getLatestFile(core.getDataDir(), f);
- Config cfg = new Config(core.getResourceLoader(), f, new InputSource(is), null);
+
+ Config cfg;
+
+ ZkController zkController = core.getCoreDescriptor().getCoreContainer().getZkController();
+ if (zkController != null) {
+ cfg = new Config(core.getResourceLoader(), f, null, null);
+ } else {
+ InputStream is = VersionedFile.getLatestFile(core.getDataDir(), f);
+ cfg = new Config(core.getResourceLoader(), f, new InputSource(is), null);
+ }
+
map = loadElevationMap(cfg);
elevationCache.put(reader, map);
}
@@ -392,7 +399,7 @@ public class QueryElevationComponent ext
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 {
@@ -402,12 +409,12 @@ public class QueryElevationComponent ext
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);
@@ -491,7 +498,7 @@ public class QueryElevationComponent ext
}
@Override
- public FieldComparator<Integer> newComparator(final String fieldname, final int numHits, int sortPos, boolean reversed) throws IOException {
+ public FieldComparator<Integer> newComparator(String fieldname, final int numHits, int sortPos, boolean reversed) throws IOException {
return new FieldComparator<Integer>() {
private final int[] values = new int[numHits];
private int bottomVal;
@@ -501,7 +508,7 @@ public class QueryElevationComponent ext
@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
@@ -523,7 +530,7 @@ public class QueryElevationComponent ext
@Override
public int compareBottom(int doc) throws IOException {
- return docVal(doc) - bottomVal;
+ return bottomVal - docVal(doc);
}
@Override
@@ -537,7 +544,7 @@ public class QueryElevationComponent ext
ordSet.clear();
Fields fields = context.reader().fields();
if (fields == null) return this;
- Terms terms = fields.terms(fieldname);
+ Terms terms = fields.terms(idField);
if (terms == null) return this;
termsEnum = terms.iterator(termsEnum);
BytesRef term = new BytesRef();
Modified: lucene/dev/trunk/solr/core/src/test-files/solr/conf/elevate.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test-files/solr/conf/elevate.xml?rev=1302541&r1=1302540&r2=1302541&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test-files/solr/conf/elevate.xml (original)
+++ lucene/dev/trunk/solr/core/src/test-files/solr/conf/elevate.xml Mon Mar 19 17:08:08 2012
@@ -42,5 +42,8 @@
<doc id="6" exclude="true" />
</query>
+ <query text="solr">
+ <doc id="7" />
+ </query>
</elevate>
Added: lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryElevationComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryElevationComponentTest.java?rev=1302541&view=auto
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryElevationComponentTest.java (added)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryElevationComponentTest.java Mon Mar 19 17:08:08 2012
@@ -0,0 +1,94 @@
+package org.apache.solr.handler.component;
+
+/**
+ * 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.
+ */
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.solr.BaseDistributedSearchTestCase;
+import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.params.CommonParams;
+import org.apache.solr.common.util.FileUtils;
+import org.junit.BeforeClass;
+
+/**
+ *
+ */
+public class DistributedQueryElevationComponentTest extends BaseDistributedSearchTestCase {
+
+ public DistributedQueryElevationComponentTest() {
+ fixShardCount = true;
+ shardCount = 3;
+ stress = 0;
+
+ // TODO: a better way to do this?
+ configString = "solrconfig-elevate.xml";
+ schemaString = "schema11.xml";
+ }
+
+ @BeforeClass
+ public static void beforeClass() throws IOException {
+ File parent = new File(TEST_HOME(), "conf");
+ File elevateFile = new File(parent, "elevate.xml");
+ File elevateDataFile = new File(parent, "elevate-data.xml");
+ FileUtils.copyFile(elevateFile, elevateDataFile);
+ }
+
+ @Override
+ public void doTest() throws Exception {
+
+
+ del("*:*");
+ indexr(id,"1", "int_i", "1", "text", "XXXX XXXX", "field_t", "anything");
+ indexr(id,"2", "int_i", "2", "text", "YYYY YYYY", "plow_t", "rake");
+ indexr(id,"3", "int_i", "3", "text", "ZZZZ ZZZZ");
+ indexr(id,"4", "int_i", "4", "text", "XXXX XXXX");
+ indexr(id,"5", "int_i", "5", "text", "ZZZZ ZZZZ ZZZZ");
+ indexr(id,"6", "int_i", "6", "text", "ZZZZ");
+
+ index_specific(2, id, "7", "int_i", "7", "text", "solr");
+ commit();
+
+ handle.put("explain", SKIPVAL);
+ handle.put("debug", SKIPVAL);
+ handle.put("QTime", SKIPVAL);
+ handle.put("maxScore", SKIPVAL);
+ handle.put("timestamp", SKIPVAL);
+ handle.put("score", SKIPVAL);
+ handle.put("wt", SKIP);
+ handle.put("distrib", SKIP);
+ handle.put("shards.qt", SKIP);
+ handle.put("shards", SKIP);
+ handle.put("q", SKIP);
+ handle.put("qt", SKIP);
+ query("q", "*:*", "qt", "/elevate", "shards.qt", "/elevate", "rows", "500", "sort", "id desc", CommonParams.FL, "id, score, [elevated]");
+
+ query("q", "ZZZZ", "qt", "/elevate", "shards.qt", "/elevate", "rows", "500", CommonParams.FL, "*, [elevated]", "forceElevation", "true", "sort", "int_i desc");
+
+ query("q", "solr", "qt", "/elevate", "shards.qt", "/elevate", "rows", "500", CommonParams.FL, "*, [elevated]", "forceElevation", "true", "sort", "int_i asc");
+
+ query("q", "ZZZZ", "qt", "/elevate", "shards.qt", "/elevate", "rows", "500", CommonParams.FL, "*, [elevated]", "forceElevation", "true", "sort", "id desc");
+ }
+
+ protected void indexr(Object... fields) throws Exception {
+ SolrInputDocument doc = new SolrInputDocument();
+ addFields(doc, fields);
+ indexDoc(doc);
+ }
+
+}
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java?rev=1302541&r1=1302540&r2=1302541&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/QueryElevationComponentTest.java Mon Mar 19 17:08:08 2012
@@ -157,7 +157,7 @@ public class QueryElevationComponentTest
req.close();
// Make sure the boosts loaded properly
- assertEquals(5, map.size());
+ assertEquals(6, map.size());
assertEquals(1, map.get("XXXX").priority.size());
assertEquals(2, map.get("YYYY").priority.size());
assertEquals(3, map.get("ZZZZ").priority.size());
@@ -174,7 +174,7 @@ public class QueryElevationComponentTest
comp.init(args);
comp.inform(core);
map = comp.getElevationMap(reader, core);
- assertEquals(5, map.size());
+ assertEquals(6, map.size());
assertEquals(null, map.get("XXXX"));
assertEquals(null, map.get("YYYY"));
assertEquals(null, map.get("ZZZZ"));