You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/02/09 23:30:23 UTC
svn commit: r1566454 [2/2] - in /lucene/dev/branches/lucene5376: ./ lucene/
lucene/core/ lucene/core/src/java/org/apache/lucene/index/
lucene/core/src/java/org/apache/lucene/search/
lucene/core/src/test/org/apache/lucene/index/ lucene/core/src/test/org...
Modified: lucene/dev/branches/lucene5376/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TSTLookup.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TSTLookup.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TSTLookup.java (original)
+++ lucene/dev/branches/lucene5376/lucene/suggest/src/java/org/apache/lucene/search/suggest/tst/TSTLookup.java Sun Feb 9 22:30:22 2014
@@ -17,20 +17,17 @@ package org.apache.lucene.search.suggest
* limitations under the License.
*/
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.lucene.search.suggest.InputIterator;
import org.apache.lucene.search.suggest.Lookup;
import org.apache.lucene.search.suggest.SortedInputIterator;
+import org.apache.lucene.store.DataInput;
+import org.apache.lucene.store.DataOutput;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.CharsRef;
-import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.RamUsageEstimator;
import org.apache.lucene.util.UnicodeUtil;
@@ -43,6 +40,9 @@ import org.apache.lucene.util.UnicodeUti
public class TSTLookup extends Lookup {
TernaryTreeNode root = new TernaryTreeNode();
TSTAutocomplete autocomplete = new TSTAutocomplete();
+
+ /** Number of entries the lookup was built with */
+ private long count = 0;
/**
* Creates a new TSTLookup with an empty Ternary Search Tree.
@@ -51,24 +51,25 @@ public class TSTLookup extends Lookup {
public TSTLookup() {}
@Override
- public void build(InputIterator tfit) throws IOException {
- if (tfit.hasPayloads()) {
+ public void build(InputIterator iterator) throws IOException {
+ if (iterator.hasPayloads()) {
throw new IllegalArgumentException("this suggester doesn't support payloads");
}
root = new TernaryTreeNode();
// make sure it's sorted and the comparator uses UTF16 sort order
- tfit = new SortedInputIterator(tfit, BytesRef.getUTF8SortedAsUTF16Comparator());
-
+ iterator = new SortedInputIterator(iterator, BytesRef.getUTF8SortedAsUTF16Comparator());
+ count = 0;
ArrayList<String> tokens = new ArrayList<String>();
ArrayList<Number> vals = new ArrayList<Number>();
BytesRef spare;
CharsRef charsSpare = new CharsRef();
- while ((spare = tfit.next()) != null) {
+ while ((spare = iterator.next()) != null) {
charsSpare.grow(spare.length);
UnicodeUtil.UTF8toUTF16(spare.bytes, spare.offset, spare.length, charsSpare);
tokens.add(charsSpare.toString());
- vals.add(Long.valueOf(tfit.weight()));
+ vals.add(Long.valueOf(iterator.weight()));
+ count++;
}
autocomplete.balancedTree(tokens.toArray(), vals.toArray(), 0, tokens.size() - 1, root);
}
@@ -148,11 +149,11 @@ public class TSTLookup extends Lookup {
private static final byte HAS_VALUE = 0x10;
// pre-order traversal
- private void readRecursively(DataInputStream in, TernaryTreeNode node) throws IOException {
- node.splitchar = in.readChar();
+ private void readRecursively(DataInput in, TernaryTreeNode node) throws IOException {
+ node.splitchar = in.readString().charAt(0);
byte mask = in.readByte();
if ((mask & HAS_TOKEN) != 0) {
- node.token = in.readUTF();
+ node.token = in.readString();
}
if ((mask & HAS_VALUE) != 0) {
node.val = Long.valueOf(in.readLong());
@@ -172,9 +173,9 @@ public class TSTLookup extends Lookup {
}
// pre-order traversal
- private void writeRecursively(DataOutputStream out, TernaryTreeNode node) throws IOException {
+ private void writeRecursively(DataOutput out, TernaryTreeNode node) throws IOException {
// write out the current node
- out.writeChar(node.splitchar);
+ out.writeString(new String(new char[] {node.splitchar}, 0, 1));
// prepare a mask of kids
byte mask = 0;
if (node.eqKid != null) mask |= EQ_KID;
@@ -183,7 +184,7 @@ public class TSTLookup extends Lookup {
if (node.token != null) mask |= HAS_TOKEN;
if (node.val != null) mask |= HAS_VALUE;
out.writeByte(mask);
- if (node.token != null) out.writeUTF(node.token);
+ if (node.token != null) out.writeString(node.token);
if (node.val != null) out.writeLong(((Number)node.val).longValue());
// recurse and write kids
if (node.loKid != null) {
@@ -198,26 +199,17 @@ public class TSTLookup extends Lookup {
}
@Override
- public synchronized boolean store(OutputStream output) throws IOException {
- DataOutputStream out = new DataOutputStream(output);
- try {
- writeRecursively(out, root);
- out.flush();
- } finally {
- IOUtils.close(output);
- }
+ public synchronized boolean store(DataOutput output) throws IOException {
+ output.writeVLong(count);
+ writeRecursively(output, root);
return true;
}
@Override
- public synchronized boolean load(InputStream input) throws IOException {
- DataInputStream in = new DataInputStream(input);
+ public synchronized boolean load(DataInput input) throws IOException {
+ count = input.readVLong();
root = new TernaryTreeNode();
- try {
- readRecursively(in, root);
- } finally {
- IOUtils.close(in);
- }
+ readRecursively(input, root);
return true;
}
@@ -227,4 +219,8 @@ public class TSTLookup extends Lookup {
return RamUsageEstimator.sizeOf(autocomplete);
}
+ @Override
+ public long getCount() {
+ return count;
+ }
}
Modified: lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/spell/TestLuceneDictionary.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/spell/TestLuceneDictionary.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/spell/TestLuceneDictionary.java (original)
+++ lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/spell/TestLuceneDictionary.java Sun Feb 9 22:30:22 2014
@@ -90,7 +90,7 @@ public class TestLuceneDictionary extend
indexReader = DirectoryReader.open(store);
ld = new LuceneDictionary(indexReader, "nonexistent_field");
- it = ld.getWordsIterator();
+ it = ld.getEntryIterator();
assertNull("More elements than expected", spare = it.next());
} finally {
@@ -103,7 +103,7 @@ public class TestLuceneDictionary extend
indexReader = DirectoryReader.open(store);
ld = new LuceneDictionary(indexReader, "aaa");
- it = ld.getWordsIterator();
+ it = ld.getEntryIterator();
assertNotNull("First element doesn't exist.", spare = it.next());
assertTrue("First element isn't correct", spare.utf8ToString().equals("foo"));
assertNull("More elements than expected", it.next());
@@ -117,7 +117,7 @@ public class TestLuceneDictionary extend
indexReader = DirectoryReader.open(store);
ld = new LuceneDictionary(indexReader, "contents");
- it = ld.getWordsIterator();
+ it = ld.getEntryIterator();
assertNotNull("First element doesn't exist.", spare = it.next());
assertTrue("First element isn't correct", spare.utf8ToString().equals("Jerry"));
@@ -126,7 +126,7 @@ public class TestLuceneDictionary extend
assertNull("More elements than expected", it.next());
ld = new LuceneDictionary(indexReader, "contents");
- it = ld.getWordsIterator();
+ it = ld.getEntryIterator();
int counter = 2;
while (it.next() != null) {
@@ -145,7 +145,7 @@ public class TestLuceneDictionary extend
indexReader = DirectoryReader.open(store);
ld = new LuceneDictionary(indexReader, "contents");
- it = ld.getWordsIterator();
+ it = ld.getEntryIterator();
// just iterate through words
assertEquals("First element isn't correct", "Jerry", it.next().utf8ToString());
@@ -162,7 +162,7 @@ public class TestLuceneDictionary extend
indexReader = DirectoryReader.open(store);
ld = new LuceneDictionary(indexReader, "zzz");
- it = ld.getWordsIterator();
+ it = ld.getEntryIterator();
assertNotNull("First element doesn't exist.", spare = it.next());
assertEquals("First element isn't correct", "bar", spare.utf8ToString());
Modified: lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentDictionaryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentDictionaryTest.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentDictionaryTest.java (original)
+++ lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentDictionaryTest.java Sun Feb 9 22:30:22 2014
@@ -109,7 +109,7 @@ public class DocumentDictionaryTest exte
writer.close();
IndexReader ir = DirectoryReader.open(dir);
Dictionary dictionary = new DocumentDictionary(ir, FIELD_NAME, WEIGHT_FIELD_NAME, PAYLOAD_FIELD_NAME);
- InputIterator inputIterator = (InputIterator) dictionary.getWordsIterator();
+ InputIterator inputIterator = dictionary.getEntryIterator();
assertNull(inputIterator.next());
assertEquals(inputIterator.weight(), 0);
@@ -135,7 +135,7 @@ public class DocumentDictionaryTest exte
writer.close();
IndexReader ir = DirectoryReader.open(dir);
Dictionary dictionary = new DocumentDictionary(ir, FIELD_NAME, WEIGHT_FIELD_NAME, PAYLOAD_FIELD_NAME);
- InputIterator inputIterator = (InputIterator) dictionary.getWordsIterator();
+ InputIterator inputIterator = dictionary.getEntryIterator();
BytesRef f;
while((f = inputIterator.next())!=null) {
Document doc = docs.remove(f.utf8ToString());
@@ -170,7 +170,7 @@ public class DocumentDictionaryTest exte
writer.close();
IndexReader ir = DirectoryReader.open(dir);
Dictionary dictionary = new DocumentDictionary(ir, FIELD_NAME, WEIGHT_FIELD_NAME);
- InputIterator inputIterator = (InputIterator) dictionary.getWordsIterator();
+ InputIterator inputIterator = dictionary.getEntryIterator();
BytesRef f;
while((f = inputIterator.next())!=null) {
Document doc = docs.remove(f.utf8ToString());
@@ -228,7 +228,7 @@ public class DocumentDictionaryTest exte
IndexReader ir = DirectoryReader.open(dir);
assertEquals(ir.numDocs(), docs.size());
Dictionary dictionary = new DocumentDictionary(ir, FIELD_NAME, WEIGHT_FIELD_NAME);
- InputIterator inputIterator = (InputIterator) dictionary.getWordsIterator();
+ InputIterator inputIterator = dictionary.getEntryIterator();
BytesRef f;
while((f = inputIterator.next())!=null) {
Document doc = docs.remove(f.utf8ToString());
Modified: lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java (original)
+++ lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentValueSourceDictionaryTest.java Sun Feb 9 22:30:22 2014
@@ -83,7 +83,7 @@ public class DocumentValueSourceDictiona
writer.close();
IndexReader ir = DirectoryReader.open(dir);
Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, new DoubleConstValueSource(10), PAYLOAD_FIELD_NAME);
- InputIterator inputIterator = (InputIterator) dictionary.getWordsIterator();
+ InputIterator inputIterator = (InputIterator) dictionary.getEntryIterator();
assertNull(inputIterator.next());
assertEquals(inputIterator.weight(), 0);
@@ -109,7 +109,7 @@ public class DocumentValueSourceDictiona
IndexReader ir = DirectoryReader.open(dir);
ValueSource[] toAdd = new ValueSource[] {new LongFieldSource(WEIGHT_FIELD_NAME_1), new LongFieldSource(WEIGHT_FIELD_NAME_2), new LongFieldSource(WEIGHT_FIELD_NAME_3)};
Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, new SumFloatFunction(toAdd), PAYLOAD_FIELD_NAME);
- InputIterator inputIterator = (InputIterator) dictionary.getWordsIterator();
+ InputIterator inputIterator = (InputIterator) dictionary.getEntryIterator();
BytesRef f;
while((f = inputIterator.next())!=null) {
Document doc = docs.remove(f.utf8ToString());
@@ -141,7 +141,7 @@ public class DocumentValueSourceDictiona
IndexReader ir = DirectoryReader.open(dir);
ValueSource[] toAdd = new ValueSource[] {new LongFieldSource(WEIGHT_FIELD_NAME_1), new LongFieldSource(WEIGHT_FIELD_NAME_2), new LongFieldSource(WEIGHT_FIELD_NAME_3)};
Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, new SumFloatFunction(toAdd));
- InputIterator inputIterator = (InputIterator) dictionary.getWordsIterator();
+ InputIterator inputIterator = (InputIterator) dictionary.getEntryIterator();
BytesRef f;
while((f = inputIterator.next())!=null) {
Document doc = docs.remove(f.utf8ToString());
@@ -195,7 +195,7 @@ public class DocumentValueSourceDictiona
ValueSource[] toAdd = new ValueSource[] {new LongFieldSource(WEIGHT_FIELD_NAME_1), new LongFieldSource(WEIGHT_FIELD_NAME_2)};
Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, new SumFloatFunction(toAdd), PAYLOAD_FIELD_NAME);
- InputIterator inputIterator = (InputIterator) dictionary.getWordsIterator();
+ InputIterator inputIterator = (InputIterator) dictionary.getEntryIterator();
BytesRef f;
while((f = inputIterator.next())!=null) {
Document doc = docs.remove(f.utf8ToString());
@@ -226,7 +226,7 @@ public class DocumentValueSourceDictiona
IndexReader ir = DirectoryReader.open(dir);
Dictionary dictionary = new DocumentValueSourceDictionary(ir, FIELD_NAME, new DoubleConstValueSource(10), PAYLOAD_FIELD_NAME);
- InputIterator inputIterator = (InputIterator) dictionary.getWordsIterator();
+ InputIterator inputIterator = (InputIterator) dictionary.getEntryIterator();
BytesRef f;
while((f = inputIterator.next())!=null) {
Document doc = docs.remove(f.utf8ToString());
Modified: lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/FileDictionaryTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/FileDictionaryTest.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/FileDictionaryTest.java (original)
+++ lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/FileDictionaryTest.java Sun Feb 9 22:30:22 2014
@@ -76,7 +76,7 @@ public class FileDictionaryTest extends
InputStream inputReader = new ByteArrayInputStream(fileInput.getValue().getBytes("UTF-8"));
FileDictionary dictionary = new FileDictionary(inputReader);
List<List<String>> entries = fileInput.getKey();
- InputIterator inputIter = dictionary.getWordsIterator();
+ InputIterator inputIter = dictionary.getEntryIterator();
assertFalse(inputIter.hasPayloads());
BytesRef term;
int count = 0;
@@ -98,7 +98,7 @@ public class FileDictionaryTest extends
InputStream inputReader = new ByteArrayInputStream(fileInput.getValue().getBytes("UTF-8"));
FileDictionary dictionary = new FileDictionary(inputReader);
List<List<String>> entries = fileInput.getKey();
- InputIterator inputIter = dictionary.getWordsIterator();
+ InputIterator inputIter = dictionary.getEntryIterator();
assertFalse(inputIter.hasPayloads());
BytesRef term;
int count = 0;
@@ -120,7 +120,7 @@ public class FileDictionaryTest extends
InputStream inputReader = new ByteArrayInputStream(fileInput.getValue().getBytes("UTF-8"));
FileDictionary dictionary = new FileDictionary(inputReader);
List<List<String>> entries = fileInput.getKey();
- InputIterator inputIter = dictionary.getWordsIterator();
+ InputIterator inputIter = dictionary.getEntryIterator();
assertTrue(inputIter.hasPayloads());
BytesRef term;
int count = 0;
@@ -146,7 +146,7 @@ public class FileDictionaryTest extends
InputStream inputReader = new ByteArrayInputStream(fileInput.getValue().getBytes("UTF-8"));
FileDictionary dictionary = new FileDictionary(inputReader);
List<List<String>> entries = fileInput.getKey();
- InputIterator inputIter = dictionary.getWordsIterator();
+ InputIterator inputIter = dictionary.getEntryIterator();
assertTrue(inputIter.hasPayloads());
BytesRef term;
int count = 0;
@@ -173,7 +173,7 @@ public class FileDictionaryTest extends
InputStream inputReader = new ByteArrayInputStream(fileInput.getValue().getBytes("UTF-8"));
FileDictionary dictionary = new FileDictionary(inputReader, " , ");
List<List<String>> entries = fileInput.getKey();
- InputIterator inputIter = dictionary.getWordsIterator();
+ InputIterator inputIter = dictionary.getEntryIterator();
assertTrue(inputIter.hasPayloads());
BytesRef term;
int count = 0;
Modified: lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/TestHighFrequencyDictionary.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/TestHighFrequencyDictionary.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/TestHighFrequencyDictionary.java (original)
+++ lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/TestHighFrequencyDictionary.java Sun Feb 9 22:30:22 2014
@@ -35,7 +35,7 @@ public class TestHighFrequencyDictionary
writer.close();
IndexReader ir = DirectoryReader.open(dir);
Dictionary dictionary = new HighFrequencyDictionary(ir, "bogus", 0.1f);
- BytesRefIterator tf = dictionary.getWordsIterator();
+ BytesRefIterator tf = dictionary.getEntryIterator();
assertNull(tf.next());
dir.close();
}
Modified: lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java (original)
+++ lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java Sun Feb 9 22:30:22 2014
@@ -110,6 +110,7 @@ public class AnalyzingInfixSuggesterTest
}
};
suggester.build(new InputArrayIterator(keys));
+ assertEquals(2, suggester.getCount());
suggester.close();
suggester = new AnalyzingInfixSuggester(TEST_VERSION_CURRENT, tempDir, a, a, 3) {
@@ -123,6 +124,7 @@ public class AnalyzingInfixSuggesterTest
assertEquals("a penny saved is a penny <b>ear</b>ned", results.get(0).key);
assertEquals(10, results.get(0).value);
assertEquals(new BytesRef("foobaz"), results.get(0).payload);
+ assertEquals(2, suggester.getCount());
suggester.close();
}
Modified: lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java (original)
+++ lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java Sun Feb 9 22:30:22 2014
@@ -912,6 +912,7 @@ public class AnalyzingSuggesterTest exte
new Input("a c", 4),
}));
+ assertEquals(3, suggester.getCount());
List<LookupResult> results = suggester.lookup("a", false, 3);
assertEquals(3, results.size());
assertEquals("a", results.get(0).key);
@@ -935,6 +936,7 @@ public class AnalyzingSuggesterTest exte
suggester.load(is);
is.close();
+ assertEquals(3, suggester.getCount());
results = suggester.lookup("a", false, 3);
assertEquals(3, results.size());
assertEquals("a", results.get(0).key);
Modified: lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestFreeTextSuggester.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestFreeTextSuggester.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestFreeTextSuggester.java (original)
+++ lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestFreeTextSuggester.java Sun Feb 9 22:30:22 2014
@@ -62,6 +62,7 @@ public class TestFreeTextSuggester exten
Analyzer a = new MockAnalyzer(random());
FreeTextSuggester sug = new FreeTextSuggester(a, a, 2, (byte) 0x20);
sug.build(new InputArrayIterator(keys));
+ assertEquals(2, sug.getCount());
for(int i=0;i<2;i++) {
@@ -95,6 +96,7 @@ public class TestFreeTextSuggester exten
sug = new FreeTextSuggester(a, a, 2, (byte) 0x20);
sug.load(is);
is.close();
+ assertEquals(2, sug.getCount());
}
}
@@ -171,6 +173,7 @@ public class TestFreeTextSuggester exten
public boolean hasPayloads() {
return false;
}
+
});
if (VERBOSE) {
System.out.println(sug.sizeInBytes() + " bytes");
Modified: lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/FSTCompletionTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/FSTCompletionTest.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/FSTCompletionTest.java (original)
+++ lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/FSTCompletionTest.java Sun Feb 9 22:30:22 2014
@@ -181,6 +181,7 @@ public class FSTCompletionTest extends L
FSTCompletionLookup lookup = new FSTCompletionLookup();
lookup.build(new InputArrayIterator(input));
+ assertEquals(input.size(), lookup.getCount());
for (Input tf : input) {
assertNotNull("Not found: " + tf.term.toString(), lookup.get(_TestUtil.bytesToCharSequence(tf.term, random())));
assertEquals(tf.term.utf8ToString(), lookup.lookup(_TestUtil.bytesToCharSequence(tf.term, random()), true, 1).get(0).key.toString());
Modified: lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/WFSTCompletionTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/WFSTCompletionTest.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/WFSTCompletionTest.java (original)
+++ lucene/dev/branches/lucene5376/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/WFSTCompletionTest.java Sun Feb 9 22:30:22 2014
@@ -156,6 +156,7 @@ public class WFSTCompletionTest extends
WFSTCompletionLookup suggester = new WFSTCompletionLookup(false);
suggester.build(new InputArrayIterator(keys));
+ assertEquals(numWords, suggester.getCount());
Random random = new Random(random().nextLong());
for (String prefix : allPrefixes) {
final int topN = _TestUtil.nextInt(random, 1, 10);
@@ -215,6 +216,7 @@ public class WFSTCompletionTest extends
WFSTCompletionLookup suggester = new WFSTCompletionLookup(false);
suggester.build(new InputArrayIterator(new Input[0]));
+ assertEquals(0, suggester.getCount());
List<LookupResult> result = suggester.lookup("a", false, 20);
assertTrue(result.isEmpty());
}
Modified: lucene/dev/branches/lucene5376/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java (original)
+++ lucene/dev/branches/lucene5376/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java Sun Feb 9 22:30:22 2014
@@ -37,6 +37,7 @@ import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs;
+import org.apache.lucene.store.BaseDirectoryWrapper;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.util.Bits;
@@ -61,7 +62,7 @@ public abstract class ThreadedIndexingAn
protected final AtomicInteger delCount = new AtomicInteger();
protected final AtomicInteger packCount = new AtomicInteger();
- protected MockDirectoryWrapper dir;
+ protected Directory dir;
protected IndexWriter writer;
private static class SubDocs {
@@ -436,8 +437,10 @@ public abstract class ThreadedIndexingAn
Random random = new Random(random().nextLong());
final LineFileDocs docs = new LineFileDocs(random, true);
final File tempDir = _TestUtil.getTempDir(testName);
- dir = newMockFSDirectory(tempDir); // some subclasses rely on this being MDW
- dir.setCheckIndexOnClose(false); // don't double-checkIndex, we do it ourselves.
+ dir = getDirectory(newMockFSDirectory(tempDir)); // some subclasses rely on this being MDW
+ if (dir instanceof BaseDirectoryWrapper) {
+ ((BaseDirectoryWrapper) dir).setCheckIndexOnClose(false); // don't double-checkIndex, we do it ourselves.
+ }
final IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random())).setInfoStream(new FailOnNonBulkMergesInfoStream());
Modified: lucene/dev/branches/lucene5376/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java (original)
+++ lucene/dev/branches/lucene5376/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java Sun Feb 9 22:30:22 2014
@@ -70,6 +70,7 @@ public class MockDirectoryWrapper extend
double randomIOExceptionRateOnOpen;
Random randomState;
boolean noDeleteOpenFile = true;
+ boolean assertNoDeleteOpenFile = false;
boolean preventDoubleWrite = true;
boolean trackDiskUsage = false;
boolean wrapLockFactory = true;
@@ -316,9 +317,22 @@ public class MockDirectoryWrapper extend
public void setNoDeleteOpenFile(boolean value) {
this.noDeleteOpenFile = value;
}
+
public boolean getNoDeleteOpenFile() {
return noDeleteOpenFile;
}
+
+ /**
+ * Trip a test assert if there is an attempt
+ * to delete an open file.
+ */
+ public void setAssertNoDeleteOpenFile(boolean value) {
+ this.assertNoDeleteOpenFile = value;
+ }
+
+ public boolean getAssertNoDeleteOpenFile() {
+ return assertNoDeleteOpenFile;
+ }
/**
* If 0.0, no exceptions will be thrown. Else this should
@@ -381,17 +395,17 @@ public class MockDirectoryWrapper extend
// sets the cause of the incoming ioe to be the stack
// trace when the offending file name was opened
- private synchronized IOException fillOpenTrace(IOException ioe, String name, boolean input) {
+ private synchronized Throwable fillOpenTrace(Throwable t, String name, boolean input) {
for(Map.Entry<Closeable,Exception> ent : openFileHandles.entrySet()) {
if (input && ent.getKey() instanceof MockIndexInputWrapper && ((MockIndexInputWrapper) ent.getKey()).name.equals(name)) {
- ioe.initCause(ent.getValue());
+ t.initCause(ent.getValue());
break;
} else if (!input && ent.getKey() instanceof MockIndexOutputWrapper && ((MockIndexOutputWrapper) ent.getKey()).name.equals(name)) {
- ioe.initCause(ent.getValue());
+ t.initCause(ent.getValue());
break;
}
}
- return ioe;
+ return t;
}
private void maybeYield() {
@@ -410,10 +424,15 @@ public class MockDirectoryWrapper extend
if (unSyncedFiles.contains(name))
unSyncedFiles.remove(name);
- if (!forced && noDeleteOpenFile) {
+ if (!forced && (noDeleteOpenFile || assertNoDeleteOpenFile)) {
if (openFiles.containsKey(name)) {
openFilesDeleted.add(name);
- throw fillOpenTrace(new IOException("MockDirectoryWrapper: file \"" + name + "\" is still open: cannot delete"), name, true);
+
+ if (!assertNoDeleteOpenFile) {
+ throw (IOException) fillOpenTrace(new IOException("MockDirectoryWrapper: file \"" + name + "\" is still open: cannot delete"), name, true);
+ } else {
+ throw (AssertionError) fillOpenTrace(new AssertionError("MockDirectoryWrapper: file \"" + name + "\" is still open: cannot delete"), name, true);
+ }
} else {
openFilesDeleted.remove(name);
}
@@ -448,8 +467,12 @@ public class MockDirectoryWrapper extend
throw new IOException("file \"" + name + "\" was already written to");
}
}
- if (noDeleteOpenFile && openFiles.containsKey(name)) {
- throw new IOException("MockDirectoryWrapper: file \"" + name + "\" is still open: cannot overwrite");
+ if ((noDeleteOpenFile || assertNoDeleteOpenFile) && openFiles.containsKey(name)) {
+ if (!assertNoDeleteOpenFile) {
+ throw new IOException("MockDirectoryWrapper: file \"" + name + "\" is still open: cannot overwrite");
+ } else {
+ throw new AssertionError("MockDirectoryWrapper: file \"" + name + "\" is still open: cannot overwrite");
+ }
}
if (crashed) {
@@ -533,7 +556,7 @@ public class MockDirectoryWrapper extend
// cannot open a file for input if it's still open for
// output, except for segments.gen and segments_N
if (openFilesForWrite.contains(name) && !name.startsWith("segments")) {
- throw fillOpenTrace(new IOException("MockDirectoryWrapper: file \"" + name + "\" is still open for writing"), name, false);
+ throw (IOException) fillOpenTrace(new IOException("MockDirectoryWrapper: file \"" + name + "\" is still open for writing"), name, false);
}
IndexInput delegateInput = in.openInput(name, LuceneTestCase.newIOContext(randomState, context));
@@ -612,7 +635,7 @@ public class MockDirectoryWrapper extend
openFiles = new HashMap<String,Integer>();
openFilesDeleted = new HashSet<String>();
}
- if (noDeleteOpenFile && openFiles.size() > 0) {
+ if (openFiles.size() > 0) {
// print the first one as its very verbose otherwise
Exception cause = null;
Iterator<Exception> stacktraces = openFileHandles.values().iterator();
@@ -622,7 +645,7 @@ public class MockDirectoryWrapper extend
// super() does not throw IOException currently:
throw new RuntimeException("MockDirectoryWrapper: cannot close: there are still open files: " + openFiles, cause);
}
- if (noDeleteOpenFile && openLocks.size() > 0) {
+ if (openLocks.size() > 0) {
throw new RuntimeException("MockDirectoryWrapper: cannot close: there are still open locks: " + openLocks);
}
@@ -908,7 +931,7 @@ public class MockDirectoryWrapper extend
// cannot open a file for input if it's still open for
// output, except for segments.gen and segments_N
if (openFilesForWrite.contains(name) && !name.startsWith("segments")) {
- throw fillOpenTrace(new IOException("MockDirectoryWrapper: file \"" + name + "\" is still open for writing"), name, false);
+ throw (IOException) fillOpenTrace(new IOException("MockDirectoryWrapper: file \"" + name + "\" is still open for writing"), name, false);
}
final IndexInputSlicer delegateHandle = in.createSlicer(name, context);
Modified: lucene/dev/branches/lucene5376/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/solr/CHANGES.txt?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/solr/CHANGES.txt (original)
+++ lucene/dev/branches/lucene5376/solr/CHANGES.txt Sun Feb 9 22:30:22 2014
@@ -78,8 +78,8 @@ Detailed Change List
New Features
----------------------
-* SOLR-5308: SOLR-5601: A new 'migrate' collection API to split all documents with a
- route key into another collection (shalin)
+* SOLR-5308: SOLR-5601: SOLR-5710: A new 'migrate' collection API to split all
+ documents with a route key into another collection (shalin)
* SOLR-5441: Expose number of transaction log files and their size via JMX.
(RafaÅ KuÄ via shalin)
@@ -143,6 +143,9 @@ New Features
* SOLR-5631: Add support for Lucene's FreeTextSuggester.
(Areek Zillur via Robert Muir)
+* SOLR-5695: Add support for Lucene's BlendedInfixSuggester.
+ (Areek Zillur)
+
* SOLR-1301: Add a Solr contrib that allows for building Solr indexes via
Hadoop's MapReduce. (Matt Revelle, Alexander Kanarsky, Steve Rowe,
Mark Miller, Greg Bowyer, Jason Rutherglen, Kris Jirapinyo, Jason Venner ,
@@ -288,6 +291,11 @@ Bug Fixes
* SOLR-5691: Sharing non thread safe WeakHashMap across thread can cause
problems. (Bojan Smid, Mark Miller)
+* SOLR-5693: Running on HDFS does work correctly with NRT search. (Mark Miller)
+
+* SOLR-5644: SplitShard does not handle not finding a shard leader well.
+ (Mark Miller, Anshum Gupta via shalin)
+
Optimizations
----------------------
@@ -310,6 +318,9 @@ Optimizations
* SOLR-4227: Wrap XML RequestWriter's OutputStreamWriter in a BufferedWriter
to avoid frequent converter invocations. (Conrad Herrmann, shalin)
+* SOLR-5624: Enable QueryResultCache for CollapsingQParserPlugin.
+ (David Boychuck, Joel Bernstein)
+
Other Changes
---------------------
@@ -369,6 +380,15 @@ Other Changes
* SOLR-5629: SolrIndexSearcher.name should include core name.
(Shikhar Bhushan via shalin)
+* SOLR-5702: Log config name found for collection at info level.
+ (Christine Poerschke via Mark Miller)
+
+* SOLR-5659: Add test for compositeId ending with an '!'.
+ (Markus Jelsma, Anshum Gupta via shalin)
+
+* SOLR-5700: Improve error handling of remote queries (proxied requests).
+ (Greg Chanan, Steve Davids via Mark Miller)
+
================== 4.6.1 ==================
Versions of Major Components
Modified: lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java (original)
+++ lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java Sun Feb 9 22:30:22 2014
@@ -71,7 +71,7 @@ public abstract class ElectionContext {
}
}
- abstract void runLeaderProcess(boolean weAreReplacement) throws KeeperException, InterruptedException, IOException;
+ abstract void runLeaderProcess(boolean weAreReplacement, int pauseTime) throws KeeperException, InterruptedException, IOException;
public void checkIfIamLeaderFired() {}
@@ -106,7 +106,7 @@ class ShardLeaderElectionContextBase ext
}
@Override
- void runLeaderProcess(boolean weAreReplacement) throws KeeperException,
+ void runLeaderProcess(boolean weAreReplacement, int pauseBeforeStart) throws KeeperException,
InterruptedException, IOException {
zkClient.makePath(leaderPath, ZkStateReader.toJSON(leaderProps),
@@ -154,7 +154,7 @@ final class ShardLeaderElectionContext e
* weAreReplacement: has someone else been the leader already?
*/
@Override
- void runLeaderProcess(boolean weAreReplacement) throws KeeperException,
+ void runLeaderProcess(boolean weAreReplacement, int pauseBeforeStart) throws KeeperException,
InterruptedException, IOException {
log.info("Running the leader process for shard " + shardId);
@@ -270,7 +270,7 @@ final class ShardLeaderElectionContext e
}
boolean success = false;
try {
- super.runLeaderProcess(weAreReplacement);
+ super.runLeaderProcess(weAreReplacement, 0);
success = true;
} catch (Exception e) {
SolrException.log(log, "There was a problem trying to register as the leader", e);
@@ -449,7 +449,7 @@ final class OverseerElectionContext exte
}
@Override
- void runLeaderProcess(boolean weAreReplacement) throws KeeperException,
+ void runLeaderProcess(boolean weAreReplacement, int pauseBeforeStart) throws KeeperException,
InterruptedException {
log.info("I am going to be the leader {}", id);
final String id = leaderSeqPath
@@ -458,6 +458,13 @@ final class OverseerElectionContext exte
zkClient.makePath(leaderPath, ZkStateReader.toJSON(myProps),
CreateMode.EPHEMERAL, true);
+ if(pauseBeforeStart >0){
+ try {
+ Thread.sleep(pauseBeforeStart);
+ } catch (InterruptedException e) {
+ log.warn("Wait interrupted ", e);
+ }
+ }
overseer.start(id);
}
Modified: lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/LeaderElector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/LeaderElector.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/LeaderElector.java (original)
+++ lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/LeaderElector.java Sun Feb 9 22:30:22 2014
@@ -161,7 +161,7 @@ public class LeaderElector {
// TODO: get this core param out of here
protected void runIamLeaderProcess(final ElectionContext context, boolean weAreReplacement) throws KeeperException,
InterruptedException, IOException {
- context.runLeaderProcess(weAreReplacement);
+ context.runLeaderProcess(weAreReplacement,0);
}
/**
Modified: lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/Overseer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/Overseer.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/Overseer.java (original)
+++ lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/Overseer.java Sun Feb 9 22:30:22 2014
@@ -59,10 +59,10 @@ public class Overseer {
public static final String ADD_ROUTING_RULE = "addroutingrule";
public static final String REMOVE_ROUTING_RULE = "removeroutingrule";
- private static final int STATE_UPDATE_DELAY = 1500; // delay between cloud state updates
+ public static final int STATE_UPDATE_DELAY = 1500; // delay between cloud state updates
private static Logger log = LoggerFactory.getLogger(Overseer.class);
-
+
static enum LeaderStatus { DONT_KNOW, NO, YES };
private long lastUpdatedTime = 0;
@@ -89,7 +89,7 @@ public class Overseer {
@Override
public void run() {
-
+
LeaderStatus isLeader = amILeader();
while (isLeader == LeaderStatus.DONT_KNOW) {
log.debug("am_i_leader unclear {}", isLeader);
Modified: lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java (original)
+++ lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionProcessor.java Sun Feb 9 22:30:22 2014
@@ -832,7 +832,13 @@ public class OverseerCollectionProcessor
}
// find the leader for the shard
- Replica parentShardLeader = clusterState.getLeader(collectionName, slice);
+ Replica parentShardLeader = null;
+ try {
+ parentShardLeader = zkStateReader.getLeaderRetry(collectionName, slice, 10000);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+
DocRouter.Range range = parentSlice.getRange();
if (range == null) {
range = new PlainIdRouter().fullRange();
@@ -1347,7 +1353,7 @@ public class OverseerCollectionProcessor
}
log.info("Common hash range between source shard: {} and target shard: {} = " + splitRange, sourceSlice.getName(), targetSlice.getName());
- Replica targetLeader = targetSlice.getLeader();
+ Replica targetLeader = zkStateReader.getLeaderRetry(targetCollection.getName(), targetSlice.getName(), 10000);
log.info("Asking target leader node: " + targetLeader.getNodeName() + " core: "
+ targetLeader.getStr("core") + " to buffer updates");
@@ -1391,7 +1397,7 @@ public class OverseerCollectionProcessor
log.info("Routing rule added successfully");
// Create temp core on source shard
- Replica sourceLeader = sourceSlice.getLeader();
+ Replica sourceLeader = zkStateReader.getLeaderRetry(sourceCollection.getName(), sourceSlice.getName(), 10000);
// create a temporary collection with just one node on the shard leader
String configName = zkStateReader.readConfigName(sourceCollection.getName());
@@ -1407,7 +1413,7 @@ public class OverseerCollectionProcessor
// refresh cluster state
clusterState = zkStateReader.getClusterState();
Slice tempSourceSlice = clusterState.getCollection(tempSourceCollectionName).getSlices().iterator().next();
- Replica tempSourceLeader = zkStateReader.getLeaderRetry(tempSourceCollectionName, tempSourceSlice.getName(), 60000);
+ Replica tempSourceLeader = zkStateReader.getLeaderRetry(tempSourceCollectionName, tempSourceSlice.getName(), 120000);
String tempCollectionReplica1 = tempSourceCollectionName + "_" + tempSourceSlice.getName() + "_replica1";
String coreNodeName = waitForCoreNodeName(clusterState.getCollection(tempSourceCollectionName),
Modified: lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/ZkController.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/ZkController.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/ZkController.java (original)
+++ lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/cloud/ZkController.java Sun Feb 9 22:30:22 2014
@@ -295,9 +295,8 @@ public final class ZkController {
public void forceOverSeer(){
try {
zkClient.delete("/overseer_elect/leader",-1, true);
- log.info("Forcing me to be leader {} ",getBaseUrl());
- overseerElector.getContext().runLeaderProcess(true);
- rejoinOverseerElection();
+ log.info("Forcing me to be leader {} ", getBaseUrl());
+ overseerElector.getContext().runLeaderProcess(true, Overseer.STATE_UPDATE_DELAY+100);
} catch (Exception e) {
throw new SolrException(ErrorCode.SERVER_ERROR, " Error becoming overseer ",e);
Modified: lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java (original)
+++ lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java Sun Feb 9 22:30:22 2014
@@ -43,6 +43,7 @@ import org.apache.solr.cloud.ZkControlle
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.QueryElevationParams;
import org.apache.solr.common.params.SolrParams;
+import org.apache.solr.common.util.StrUtils;
import org.apache.solr.schema.IndexSchema;
import org.apache.solr.search.grouping.GroupingSpecification;
import org.apache.solr.util.DOMUtil;
@@ -339,18 +340,6 @@ public class QueryElevationComponent ext
elev.put(obj.analyzed, obj);
}
- ElevationObj getElevationObj(String query, String[] ids, String[] ex) throws IOException {
- if (ids == null) {
- ids = new String[0];
- }
- if (ex == null) {
- ex = new String[0];
- }
-
- ElevationObj obj = new ElevationObj(query, Arrays.asList(ids), Arrays.asList(ex));
- return obj;
- }
-
String getAnalyzedQuery(String query) throws IOException {
if (analyzer == null) {
return query;
@@ -397,9 +386,9 @@ public class QueryElevationComponent ext
ElevationObj booster = null;
try {
if(boostStr != null || exStr != null) {
- String[] boosts = (boostStr != null) ? boostStr.split(",") : new String[0];
- String[] excludes = (exStr != null) ? exStr.split(",") : new String[0];
- booster = getElevationObj(qstr, boosts, excludes);
+ List<String> boosts = (boostStr != null) ? StrUtils.splitSmart(boostStr,",", true) : new ArrayList<String>(0);
+ List<String> excludes = (exStr != null) ? StrUtils.splitSmart(exStr, ",", true) : new ArrayList<String>(0);
+ booster = new ElevationObj(qstr, boosts, excludes);
} else {
IndexReader reader = req.getSearcher().getIndexReader();
qstr = getAnalyzedQuery(qstr);
Modified: lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java (original)
+++ lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java Sun Feb 9 22:30:22 2014
@@ -23,6 +23,7 @@ import org.apache.lucene.queries.functio
import org.apache.lucene.util.BytesRef;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.request.LocalSolrQueryRequest;
+import org.apache.solr.request.SolrRequestInfo;
import org.apache.solr.schema.TrieFloatField;
import org.apache.solr.schema.TrieIntField;
import org.apache.solr.schema.TrieLongField;
@@ -126,13 +127,12 @@ public class CollapsingQParserPlugin ext
public class CollapsingPostFilter extends ExtendedQueryBase implements PostFilter, ScoreFilter {
- private Object cacheId;
private String field;
private String max;
private String min;
private boolean needsScores = true;
private int nullPolicy;
- private Map context;
+ private Set<String> boosted;
public static final int NULL_POLICY_IGNORE = 0;
public static final int NULL_POLICY_COLLAPSE = 1;
public static final int NULL_POLICY_EXPAND = 2;
@@ -154,15 +154,25 @@ public class CollapsingQParserPlugin ext
}
public int hashCode() {
- return this.cacheId.hashCode()*((1+Float.floatToIntBits(this.getBoost()))*31);
+ int hashCode = field.hashCode();
+ hashCode = max!=null ? hashCode+max.hashCode():hashCode;
+ hashCode = min!=null ? hashCode+min.hashCode():hashCode;
+ hashCode = boosted!=null ? hashCode+boosted.hashCode():hashCode;
+ hashCode = hashCode+nullPolicy;
+ hashCode = hashCode*((1+Float.floatToIntBits(this.getBoost()))*31);
+ return hashCode;
}
public boolean equals(Object o) {
- //Uses the unique id for equals to ensure that the query result cache always fails.
+
if(o instanceof CollapsingPostFilter) {
CollapsingPostFilter c = (CollapsingPostFilter)o;
- //Do object comparison to be sure only the same object will return true.
- if(this.cacheId == c.cacheId && this.getBoost()==c.getBoost()) {
+ if(this.field.equals(c.field) &&
+ ((this.max == null && c.max == null) || (this.max != null && c.max != null && this.max.equals(c.max))) &&
+ ((this.min == null && c.min == null) || (this.min != null && c.min != null && this.min.equals(c.min))) &&
+ this.nullPolicy == c.nullPolicy &&
+ ((this.boosted == null && c.boosted == null) || (this.boosted == c.boosted)) &&
+ this.getBoost()==c.getBoost()) {
return true;
}
}
@@ -178,11 +188,9 @@ public class CollapsingQParserPlugin ext
}
public CollapsingPostFilter(SolrParams localParams, SolrParams params, SolrQueryRequest request) throws IOException {
- this.cacheId = new Object();
this.field = localParams.get("field");
this.max = localParams.get("max");
this.min = localParams.get("min");
- this.context = request.getContext();
if(this.min != null || this.max != null) {
this.needsScores = needsScores(params);
}
@@ -201,6 +209,7 @@ public class CollapsingQParserPlugin ext
private IntOpenHashSet getBoostDocs(SolrIndexSearcher indexSearcher, Set<String> boosted) throws IOException {
IntOpenHashSet boostDocs = null;
+
if(boosted != null) {
SchemaField idField = indexSearcher.getSchema().getUniqueKeyField();
String fieldName = idField.getName();
@@ -296,7 +305,14 @@ public class CollapsingQParserPlugin ext
int maxDoc = searcher.maxDoc();
int leafCount = searcher.getTopReaderContext().leaves().size();
- IntOpenHashSet boostDocs = getBoostDocs(searcher, (Set<String>) (this.context.get(QueryElevationComponent.BOOSTED)));
+ if(this.boosted == null) {
+ SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
+ if(info != null) {
+ this.boosted = (Set<String>)info.getReq().getContext().get(QueryElevationComponent.BOOSTED);
+ }
+ }
+
+ IntOpenHashSet boostDocs = getBoostDocs(searcher, this.boosted);
if(this.min != null || this.max != null) {
@@ -344,7 +360,7 @@ public class CollapsingQParserPlugin ext
}
}
- if(this.context.containsKey(QueryElevationComponent.BOOSTED)) {
+ if(this.boosted != null) {
return true;
}
Modified: lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java (original)
+++ lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java Sun Feb 9 22:30:22 2014
@@ -19,6 +19,20 @@ package org.apache.solr.servlet;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpHead;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.entity.InputStreamEntity;
+import org.apache.http.util.EntityUtils;
+import org.apache.http.Header;
+import org.apache.http.HeaderIterator;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpResponse;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
import org.apache.solr.common.cloud.Aliases;
@@ -42,6 +56,7 @@ import org.apache.solr.core.CoreContaine
import org.apache.solr.core.SolrConfig;
import org.apache.solr.core.SolrCore;
import org.apache.solr.core.SolrResourceLoader;
+import org.apache.solr.client.solrj.impl.HttpClientUtil;
import org.apache.solr.handler.ContentStreamHandlerBase;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrQueryRequestBase;
@@ -72,7 +87,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
-import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
@@ -85,7 +99,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import java.util.WeakHashMap;
/**
* This filter looks at the incoming URL maps them to handlers defined in solrconfig.xml
@@ -96,6 +109,7 @@ public class SolrDispatchFilter implemen
{
private static final String CONNECTION_HEADER = "Connection";
private static final String TRANSFER_ENCODING_HEADER = "Transfer-Encoding";
+ private static final String CONTENT_LENGTH_HEADER = "Content-Length";
final Logger log;
@@ -103,6 +117,7 @@ public class SolrDispatchFilter implemen
protected String pathPrefix = null; // strip this from the beginning of a path
protected String abortErrorMessage = null;
+ protected final HttpClient httpClient = HttpClientUtil.createClient(new ModifiableSolrParams());
private static final Charset UTF8 = Charset.forName("UTF-8");
@@ -492,9 +507,12 @@ public class SolrDispatchFilter implemen
}
}
}
-
+
private void remoteQuery(String coreUrl, HttpServletRequest req,
SolrQueryRequest solrReq, HttpServletResponse resp) throws IOException {
+ HttpRequestBase method = null;
+ HttpEntity httpEntity = null;
+ boolean success = false;
try {
String urlstr = coreUrl;
@@ -503,58 +521,58 @@ public class SolrDispatchFilter implemen
urlstr += queryString == null ? "" : "?" + queryString;
URL url = new URL(urlstr);
- HttpURLConnection con = (HttpURLConnection) url.openConnection();
- con.setRequestMethod(req.getMethod());
- con.setUseCaches(false);
-
boolean isPostOrPutRequest = "POST".equals(req.getMethod()) || "PUT".equals(req.getMethod());
-
- if (isPostOrPutRequest) {
- con.setDoOutput(true);
+
+ if ("GET".equals(req.getMethod())) {
+ method = new HttpGet(urlstr);
+ }
+ else if ("HEAD".equals(req.getMethod())) {
+ method = new HttpHead(urlstr);
+ }
+ else if (isPostOrPutRequest) {
+ HttpEntityEnclosingRequestBase entityRequest =
+ "POST".equals(req.getMethod()) ? new HttpPost(urlstr) : new HttpPut(urlstr);
+ HttpEntity entity = new InputStreamEntity(req.getInputStream(), req.getContentLength());
+ entityRequest.setEntity(entity);
+ method = entityRequest;
+ }
+ else {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "Unexpected method type: " + req.getMethod());
}
- con.setDoInput(true);
+
for (Enumeration<String> e = req.getHeaderNames(); e.hasMoreElements();) {
String headerName = e.nextElement();
- con.setRequestProperty(headerName, req.getHeader(headerName));
+ method.addHeader(headerName, req.getHeader(headerName));
+ }
+ // These headers not supported for HttpEntityEnclosingRequests
+ if (method instanceof HttpEntityEnclosingRequest) {
+ method.removeHeaders(TRANSFER_ENCODING_HEADER);
+ method.removeHeaders(CONTENT_LENGTH_HEADER);
}
- try {
- con.connect();
- InputStream is;
- OutputStream os;
- if (isPostOrPutRequest) {
- is = req.getInputStream();
- os = con.getOutputStream(); // side effect: method is switched to POST
- try {
- IOUtils.copyLarge(is, os);
- os.flush();
- } finally {
- IOUtils.closeQuietly(os);
- IOUtils.closeQuietly(is); // TODO: I thought we weren't supposed to explicitly close servlet streams
- }
- }
-
- resp.setStatus(con.getResponseCode());
-
- for (Iterator<Entry<String,List<String>>> i = con.getHeaderFields().entrySet().iterator(); i.hasNext();) {
- Map.Entry<String,List<String>> mapEntry = i.next();
- String header = mapEntry.getKey();
-
- // We pull out these two headers below because they can cause chunked
- // encoding issues with Tomcat and certain clients
- if (header != null && !header.equals(TRANSFER_ENCODING_HEADER)
- && !header.equals(CONNECTION_HEADER)) {
- for (String value : mapEntry.getValue()) {
- resp.addHeader(mapEntry.getKey(), value);
- }
- }
+ final HttpResponse response = httpClient.execute(method);
+ int httpStatus = response.getStatusLine().getStatusCode();
+ httpEntity = response.getEntity();
+
+ resp.setStatus(httpStatus);
+ for (HeaderIterator responseHeaders = response.headerIterator(); responseHeaders.hasNext();) {
+ Header header = responseHeaders.nextHeader();
+
+ // We pull out these two headers below because they can cause chunked
+ // encoding issues with Tomcat
+ if (header != null && !header.getName().equals(TRANSFER_ENCODING_HEADER)
+ && !header.getName().equals(CONNECTION_HEADER)) {
+ resp.addHeader(header.getName(), header.getValue());
}
-
- resp.setCharacterEncoding(con.getContentEncoding());
- resp.setContentType(con.getContentType());
-
- is = con.getInputStream();
- os = resp.getOutputStream();
+ }
+
+ if (httpEntity != null) {
+ if (httpEntity.getContentEncoding() != null) resp.setCharacterEncoding(httpEntity.getContentEncoding().getValue());
+ if (httpEntity.getContentType() != null) resp.setContentType(httpEntity.getContentType().getValue());
+
+ InputStream is = httpEntity.getContent();
+ OutputStream os = resp.getOutputStream();
try {
IOUtils.copyLarge(is, os);
os.flush();
@@ -562,15 +580,19 @@ public class SolrDispatchFilter implemen
IOUtils.closeQuietly(os); // TODO: I thought we weren't supposed to explicitly close servlet streams
IOUtils.closeQuietly(is);
}
- } finally {
- con.disconnect();
}
+ success = true;
} catch (IOException e) {
sendError(null, solrReq, req, resp, new SolrException(
SolrException.ErrorCode.SERVER_ERROR,
"Error trying to proxy request for url: " + coreUrl, e));
+ } finally {
+ EntityUtils.consumeQuietly(httpEntity);
+ if (method != null && !success) {
+ method.abort();
+ }
}
-
+
}
private String getRemotCoreUrl(CoreContainer cores, String collectionName, String origCorename) {
Modified: lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/spelling/suggest/fst/AnalyzingInfixLookupFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/spelling/suggest/fst/AnalyzingInfixLookupFactory.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/spelling/suggest/fst/AnalyzingInfixLookupFactory.java (original)
+++ lucene/dev/branches/lucene5376/solr/core/src/java/org/apache/solr/spelling/suggest/fst/AnalyzingInfixLookupFactory.java Sun Feb 9 22:30:22 2014
@@ -37,22 +37,25 @@ public class AnalyzingInfixLookupFactory
/**
* The analyzer used at "query-time" and "build-time" to analyze suggestions.
*/
- public static final String QUERY_ANALYZER = "suggestAnalyzerFieldType";
+ protected static final String QUERY_ANALYZER = "suggestAnalyzerFieldType";
/**
* The path where the underlying index is stored
* if no index is found, it will be generated by
* the AnalyzingInfixSuggester
*/
- public static final String INDEX_PATH = "indexPath";
+ protected static final String INDEX_PATH = "indexPath";
/**
* Minimum number of leading characters before PrefixQuery is used (default 4).
* Prefixes shorter than this are indexed as character ngrams
* (increasing index size but making lookups faster)
*/
- private static final String MIN_PREFIX_CHARS = "minPrefixChars";
+ protected static final String MIN_PREFIX_CHARS = "minPrefixChars";
+ /**
+ * Default path where the index for the suggester is stored/loaded from
+ * */
private static final String DEFAULT_INDEX_PATH = "analyzingInfixSuggesterIndexDir";
/**
Modified: lucene/dev/branches/lucene5376/solr/core/src/test-files/solr/collection1/conf/solrconfig-phrasesuggest.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/solr/core/src/test-files/solr/collection1/conf/solrconfig-phrasesuggest.xml?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/solr/core/src/test-files/solr/collection1/conf/solrconfig-phrasesuggest.xml (original)
+++ lucene/dev/branches/lucene5376/solr/core/src/test-files/solr/collection1/conf/solrconfig-phrasesuggest.xml Sun Feb 9 22:30:22 2014
@@ -118,6 +118,34 @@
</lst>
</searchComponent>
+
+ <searchComponent class="solr.SuggestComponent" name="blended_infix_suggest">
+ <lst name="suggester">
+ <str name="name">blended_infix_suggest_linear</str>
+ <str name="lookupImpl">BlendedInfixLookupFactory</str>
+ <str name="dictionaryImpl">FileDictionaryFactory</str>
+ <str name="buildOnCommit">false</str>
+ <str name="sourceLocation">blendedInfixSuggest.txt</str>
+
+ <!-- Suggester properties -->
+ <str name="blenderType">linear</str>
+ <str name="suggestAnalyzerFieldType">text</str>
+ </lst>
+
+ <lst name="suggester">
+ <str name="name">blended_infix_suggest_reciprocal</str>
+ <str name="lookupImpl">BlendedInfixLookupFactory</str>
+ <str name="dictionaryImpl">FileDictionaryFactory</str>
+ <str name="buildOnCommit">false</str>
+ <str name="sourceLocation">blendedInfixSuggest.txt</str>
+
+ <!-- Suggester properties -->
+ <str name="blenderType">reciprocal</str>
+ <str name="suggestAnalyzerFieldType">text</str>
+ </lst>
+
+ </searchComponent>
+
<!-- FuzzyLookup suggest component with FileDictionaryFactory -->
<searchComponent class="solr.SuggestComponent" name="fuzzy_suggest_analyzing_with_file_dict">
<lst name="suggester">
@@ -277,6 +305,15 @@
</requestHandler>
+ <requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/blended_infix_suggest">
+ <lst name="defaults">
+ <str name="suggest">true</str>
+ </lst>
+ <arr name="components">
+ <str>blended_infix_suggest</str>
+ </arr>
+ </requestHandler>
+
<requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/free_text_suggest">
<lst name="defaults">
<str name="suggest">true</str>
Modified: lucene/dev/branches/lucene5376/solr/core/src/test/org/apache/solr/cloud/ShardRoutingTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/solr/core/src/test/org/apache/solr/cloud/ShardRoutingTest.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/solr/core/src/test/org/apache/solr/cloud/ShardRoutingTest.java (original)
+++ lucene/dev/branches/lucene5376/solr/core/src/test/org/apache/solr/cloud/ShardRoutingTest.java Sun Feb 9 22:30:22 2014
@@ -215,6 +215,36 @@ public class ShardRoutingTest extends Ab
doAddDoc("f1!f2!doc5");
commit();
+
+ doDBQ("*:*");
+ commit();
+
+ doAddDoc("b!");
+ doAddDoc("c!doc1");
+ commit();
+ doQuery("b!,c!doc1", "q","*:*");
+ UpdateRequest req = new UpdateRequest();
+ req.deleteById("b!");
+ req.process(cloudClient);
+ commit();
+ doQuery("c!doc1", "q","*:*");
+
+ doDBQ("id:b!");
+ commit();
+ doQuery("c!doc1", "q","*:*");
+
+ doDBQ("*:*");
+ commit();
+
+ doAddDoc("a!b!");
+ doAddDoc("b!doc1");
+ doAddDoc("c!doc2");
+ doAddDoc("d!doc3");
+ doAddDoc("e!doc4");
+ doAddDoc("f1!f2!doc5");
+ doAddDoc("f1!f2!doc5/5");
+ commit();
+ doQuery("a!b!,b!doc1,c!doc2,d!doc3,e!doc4,f1!f2!doc5,f1!f2!doc5/5", "q","*:*");
}
Modified: lucene/dev/branches/lucene5376/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java (original)
+++ lucene/dev/branches/lucene5376/solr/core/src/test/org/apache/solr/search/QueryEqualityTest.java Sun Feb 9 22:30:22 2014
@@ -18,6 +18,7 @@ package org.apache.solr.search;
import java.util.HashSet;
import java.util.Set;
+import java.util.Map;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryUtils;
@@ -197,9 +198,32 @@ public class QueryEqualityTest extends S
public void testQueryCollapse() throws Exception {
SolrQueryRequest req = req("myField","foo_s");
+
try {
assertQueryEquals("collapse", req,
"{!collapse field=$myField}");
+
+ assertQueryEquals("collapse", req,
+ "{!collapse field=$myField max=a}");
+
+ assertQueryEquals("collapse", req,
+ "{!collapse field=$myField min=a}");
+
+ assertQueryEquals("collapse", req,
+ "{!collapse field=$myField max=a nullPolicy=expand}");
+
+ //Add boosted documents to the request context.
+ Map context = req.getContext();
+ Set boosted = new HashSet();
+ boosted.add("doc1");
+ boosted.add("doc2");
+ context.put("BOOSTED", boosted);
+
+ assertQueryEquals("collapse", req,
+ "{!collapse field=$myField min=a}",
+ "{!collapse field=$myField min=a nullPolicy=ignore}");
+
+
} finally {
req.close();
}
Modified: lucene/dev/branches/lucene5376/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java (original)
+++ lucene/dev/branches/lucene5376/solr/core/src/test/org/apache/solr/search/TestCollapseQParserPlugin.java Sun Feb 9 22:30:22 2014
@@ -140,9 +140,10 @@ public class TestCollapseQParserPlugin e
params.add("qf", "term_s");
params.add("qt", "/elevate");
assertQ(req(params), "*[count(//doc)=4]",
- "//result/doc[1]/float[@name='id'][.='1.0']");
-
-
+ "//result/doc[1]/float[@name='id'][.='1.0']",
+ "//result/doc[2]/float[@name='id'][.='2.0']",
+ "//result/doc[3]/float[@name='id'][.='3.0']",
+ "//result/doc[4]/float[@name='id'][.='6.0']");
//Test collapse by min int field and sort
Modified: lucene/dev/branches/lucene5376/solr/core/src/test/org/apache/solr/spelling/suggest/TestAnalyzeInfixSuggestions.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/solr/core/src/test/org/apache/solr/spelling/suggest/TestAnalyzeInfixSuggestions.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/solr/core/src/test/org/apache/solr/spelling/suggest/TestAnalyzeInfixSuggestions.java (original)
+++ lucene/dev/branches/lucene5376/solr/core/src/test/org/apache/solr/spelling/suggest/TestAnalyzeInfixSuggestions.java Sun Feb 9 22:30:22 2014
@@ -1,7 +1,10 @@
package org.apache.solr.spelling.suggest;
+import java.io.File;
+
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.params.SpellingParams;
+import org.junit.AfterClass;
import org.junit.BeforeClass;
/*
@@ -30,6 +33,16 @@ public class TestAnalyzeInfixSuggestions
assertQ(req("qt", URI_DEFAULT, "q", "", SpellingParams.SPELLCHECK_BUILD, "true"));
}
+ @AfterClass
+ public static void afterClass() throws Exception {
+ File indexPathDir = new File("analyzingInfixSuggesterIndexDir");
+ File indexPathDirTmp = new File("analyzingInfixSuggesterIndexDir.tmp");
+ if (indexPathDir.exists())
+ recurseDelete(indexPathDir);
+ if (indexPathDirTmp.exists())
+ recurseDelete(indexPathDirTmp);
+ }
+
public void testSingle() throws Exception {
assertQ(req("qt", URI_DEFAULT, "q", "japan", SpellingParams.SPELLCHECK_COUNT, "1"),
@@ -63,4 +76,5 @@ public class TestAnalyzeInfixSuggestions
"//lst[@name='spellcheck']/lst[@name='suggestions']/lst[@name='japan']/arr[@name='suggestion']/str[3][.='Add decompose compound <b>Japan</b>ese Katakana token capability to Kuromoji']"
);
}
+
}
\ No newline at end of file
Modified: lucene/dev/branches/lucene5376/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java (original)
+++ lucene/dev/branches/lucene5376/solr/solrj/src/java/org/apache/solr/common/cloud/CompositeIdRouter.java Sun Feb 9 22:30:22 2014
@@ -191,10 +191,11 @@ public class CompositeIdRouter extends H
String[] parts = key.split(SEPARATOR);
this.key = key;
pieces = parts.length;
- hashes = new int[pieces];
numBits = new int[2];
- if (key.endsWith("!"))
+ if (key.endsWith("!") && pieces < 3)
pieces++;
+ hashes = new int[pieces];
+
if (pieces == 3) {
numBits[0] = 8;
numBits[1] = 8;
@@ -204,7 +205,7 @@ public class CompositeIdRouter extends H
triLevel = false;
}
- for (int i = 0; i < parts.length; i++) {
+ for (int i = 0; i < pieces; i++) {
if (i < pieces - 1) {
int commaIdx = parts[i].indexOf(bitsSeparator);
@@ -213,7 +214,11 @@ public class CompositeIdRouter extends H
parts[i] = parts[i].substring(0, commaIdx);
}
}
- hashes[i] = Hash.murmurhash3_x86_32(parts[i], 0, parts[i].length(), 0);
+ //Last component of an ID that ends with a '!'
+ if(i >= parts.length)
+ hashes[i] = Hash.murmurhash3_x86_32("", 0, "".length(), 0);
+ else
+ hashes[i] = Hash.murmurhash3_x86_32(parts[i], 0, parts[i].length(), 0);
}
masks = getMasks();
}
Modified: lucene/dev/branches/lucene5376/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java?rev=1566454&r1=1566453&r2=1566454&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java (original)
+++ lucene/dev/branches/lucene5376/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java Sun Feb 9 22:30:22 2014
@@ -144,10 +144,15 @@ public class ZkStateReader {
configName = props.getStr(CONFIGNAME_PROP);
}
- if (configName != null && !zkClient.exists(CONFIGS_ZKNODE + "/" + configName, true)) {
- log.error("Specified config does not exist in ZooKeeper:" + configName);
- throw new ZooKeeperException(ErrorCode.SERVER_ERROR,
- "Specified config does not exist in ZooKeeper:" + configName);
+ if (configName != null) {
+ if (!zkClient.exists(CONFIGS_ZKNODE + "/" + configName, true)) {
+ log.error("Specified config does not exist in ZooKeeper:" + configName);
+ throw new ZooKeeperException(ErrorCode.SERVER_ERROR,
+ "Specified config does not exist in ZooKeeper:" + configName);
+ } else if (log.isInfoEnabled()) {
+ log.info("path={} {}={} specified config exists in ZooKeeper",
+ new Object[] {path, CONFIGNAME_PROP, configName});
+ }
}
return configName;
@@ -521,7 +526,8 @@ public class ZkStateReader {
}
Thread.sleep(50);
}
- throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "No registered leader was found, collection:" + collection + " slice:" + shard);
+ throw new SolrException(ErrorCode.SERVICE_UNAVAILABLE, "No registered leader was found after waiting for "
+ + timeout + "ms " + ", collection: " + collection + " slice: " + shard);
}
/**