mirror of https://github.com/apache/lucene.git
use the new non-deprecated getFields() method, clean up some imports
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@416475 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8ebdf9fc86
commit
daee07ee37
|
@ -16,17 +16,18 @@ package org.apache.lucene.index;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.analysis.WhitespaceAnalyzer;
|
||||
import org.apache.lucene.document.*;
|
||||
import org.apache.lucene.search.Similarity;
|
||||
import org.apache.lucene.store.Directory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.analysis.WhitespaceAnalyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.search.Similarity;
|
||||
import org.apache.lucene.store.Directory;
|
||||
|
||||
class DocHelper {
|
||||
public static final String FIELD_1_TEXT = "field one text";
|
||||
|
@ -257,13 +258,6 @@ class DocHelper {
|
|||
}
|
||||
|
||||
public static int numFields(Document doc) {
|
||||
Enumeration fields = doc.fields();
|
||||
int result = 0;
|
||||
while (fields.hasMoreElements()) {
|
||||
String name = fields.nextElement().toString();
|
||||
name += ""; // avoid compiler warning
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
return doc.getFields().size();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,19 +16,25 @@ package org.apache.lucene.index;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.lucene.analysis.WhitespaceAnalyzer;
|
||||
import org.apache.lucene.document.*;
|
||||
import org.apache.lucene.search.Similarity;
|
||||
import org.apache.lucene.store.FSDirectory;
|
||||
import org.apache.lucene.store.RAMDirectory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.lucene.analysis.WhitespaceAnalyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.document.LoadFirstFieldSelector;
|
||||
import org.apache.lucene.document.SetBasedFieldSelector;
|
||||
import org.apache.lucene.search.Similarity;
|
||||
import org.apache.lucene.store.FSDirectory;
|
||||
import org.apache.lucene.store.RAMDirectory;
|
||||
|
||||
public class TestFieldsReader extends TestCase {
|
||||
private RAMDirectory dir = new RAMDirectory();
|
||||
|
@ -137,9 +143,9 @@ public class TestFieldsReader extends TestCase {
|
|||
Document doc = reader.doc(0, fieldSelector);
|
||||
assertTrue("doc is null and it shouldn't be", doc != null);
|
||||
int count = 0;
|
||||
Enumeration enumeration = doc.fields();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
Field field = (Field) enumeration.nextElement();
|
||||
List l = doc.getFields();
|
||||
for (Iterator iter = l.iterator(); iter.hasNext();) {
|
||||
Field field = (Field) iter.next();
|
||||
assertTrue("field is null and it shouldn't be", field != null);
|
||||
String sv = field.stringValue();
|
||||
assertTrue("sv is null and it shouldn't be", sv != null);
|
||||
|
|
|
@ -16,26 +16,26 @@ package org.apache.lucene.index;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Field;
|
||||
import org.apache.lucene.document.MapFieldSelector;
|
||||
import org.apache.lucene.search.BooleanClause.Occur;
|
||||
import org.apache.lucene.search.BooleanQuery;
|
||||
import org.apache.lucene.search.Hits;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.Searcher;
|
||||
import org.apache.lucene.search.TermQuery;
|
||||
import org.apache.lucene.search.BooleanClause.Occur;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.store.RAMDirectory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
|
||||
public class TestParallelReader extends TestCase {
|
||||
|
||||
private Searcher parallel;
|
||||
|
@ -87,9 +87,9 @@ public class TestParallelReader extends TestCase {
|
|||
Document doc24 = pr.document(1, new MapFieldSelector(Arrays.asList(new String[] {"f4"})));
|
||||
Document doc223 = pr.document(1, new MapFieldSelector(new String[] {"f2", "f3"}));
|
||||
|
||||
assertEquals(1, numFields(doc11));
|
||||
assertEquals(1, numFields(doc24));
|
||||
assertEquals(2, numFields(doc223));
|
||||
assertEquals(1, doc11.getFields().size());
|
||||
assertEquals(1, doc24.getFields().size());
|
||||
assertEquals(2, doc223.getFields().size());
|
||||
|
||||
assertEquals("v1", doc11.get("f1"));
|
||||
assertEquals("v2", doc24.get("f4"));
|
||||
|
@ -97,14 +97,6 @@ public class TestParallelReader extends TestCase {
|
|||
assertEquals("v2", doc223.get("f3"));
|
||||
}
|
||||
|
||||
private int numFields(Document doc) {
|
||||
int num;
|
||||
Enumeration e = doc.fields();
|
||||
for (num=0; e.hasMoreElements(); num++)
|
||||
e.nextElement();
|
||||
return num;
|
||||
}
|
||||
|
||||
public void testIncompatibleIndexes() throws IOException {
|
||||
// two documents:
|
||||
Directory dir1 = getDir1();
|
||||
|
|
|
@ -16,16 +16,17 @@ package org.apache.lucene.index;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.lucene.store.RAMDirectory;
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.search.DefaultSimilarity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.lucene.document.Document;
|
||||
import org.apache.lucene.document.Fieldable;
|
||||
import org.apache.lucene.search.DefaultSimilarity;
|
||||
import org.apache.lucene.store.RAMDirectory;
|
||||
|
||||
public class TestSegmentReader extends TestCase {
|
||||
private RAMDirectory dir = new RAMDirectory();
|
||||
|
@ -62,9 +63,9 @@ public class TestSegmentReader extends TestCase {
|
|||
//There are 2 unstored fields on the document that are not preserved across writing
|
||||
assertTrue(DocHelper.numFields(result) == DocHelper.numFields(testDoc) - DocHelper.unstored.size());
|
||||
|
||||
Enumeration fields = result.fields();
|
||||
while (fields.hasMoreElements()) {
|
||||
Fieldable field = (Fieldable) fields.nextElement();
|
||||
List fields = result.getFields();
|
||||
for (Iterator iter = fields.iterator(); iter.hasNext();) {
|
||||
Fieldable field = (Fieldable) iter.next();
|
||||
assertTrue(field != null);
|
||||
assertTrue(DocHelper.nameValues.containsKey(field.name()));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue