mirror of https://github.com/apache/lucene.git
tests: fix resource leaks and simplify
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1022927 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e8a0629ac1
commit
2a8c9dfa3f
|
@ -46,173 +46,103 @@ public class TermVectorComponentTest extends SolrTestCaseJ4 {
|
|||
public static void beforeClass() throws Exception {
|
||||
initCore("solrconfig.xml","schema.xml");
|
||||
|
||||
assertNull(h.validateUpdate(adoc("id", "0",
|
||||
assertU(adoc("id", "0",
|
||||
"test_posofftv", "This is a title and another title",
|
||||
"test_basictv", "This is a title and another title",
|
||||
"test_notv", "This is a title and another title",
|
||||
"test_postv", "This is a title and another title",
|
||||
"test_offtv", "This is a title and another title"
|
||||
)));
|
||||
assertNull(h.validateUpdate(adoc("id", "1",
|
||||
));
|
||||
assertU(adoc("id", "1",
|
||||
"test_posofftv", "The quick reb fox jumped over the lazy brown dogs.",
|
||||
"test_basictv", "The quick reb fox jumped over the lazy brown dogs.",
|
||||
"test_notv", "The quick reb fox jumped over the lazy brown dogs.",
|
||||
"test_postv", "The quick reb fox jumped over the lazy brown dogs.",
|
||||
"test_offtv", "The quick reb fox jumped over the lazy brown dogs."
|
||||
)));
|
||||
assertNull(h.validateUpdate(adoc("id", "2",
|
||||
));
|
||||
assertU(adoc("id", "2",
|
||||
"test_posofftv", "This is a document",
|
||||
"test_basictv", "This is a document",
|
||||
"test_notv", "This is a document",
|
||||
"test_postv", "This is a document",
|
||||
"test_offtv", "This is a document"
|
||||
)));
|
||||
assertNull(h.validateUpdate(adoc("id", "3",
|
||||
));
|
||||
assertU(adoc("id", "3",
|
||||
"test_posofftv", "another document",
|
||||
"test_basictv", "another document",
|
||||
"test_notv", "another document",
|
||||
"test_postv", "another document",
|
||||
"test_offtv", "another document"
|
||||
)));
|
||||
));
|
||||
//bunch of docs that are variants on blue
|
||||
assertNull(h.validateUpdate(adoc("id", "4",
|
||||
assertU(adoc("id", "4",
|
||||
"test_posofftv", "blue",
|
||||
"test_basictv", "blue",
|
||||
"test_notv", "blue",
|
||||
"test_postv", "blue",
|
||||
"test_offtv", "blue"
|
||||
)));
|
||||
assertNull(h.validateUpdate(adoc("id", "5",
|
||||
));
|
||||
assertU(adoc("id", "5",
|
||||
"test_posofftv", "blud",
|
||||
"test_basictv", "blud",
|
||||
"test_notv", "blud",
|
||||
"test_postv", "blud",
|
||||
"test_offtv", "blud"
|
||||
)));
|
||||
assertNull(h.validateUpdate(adoc("id", "6",
|
||||
));
|
||||
assertU(adoc("id", "6",
|
||||
"test_posofftv", "boue",
|
||||
"test_basictv", "boue",
|
||||
"test_notv", "boue",
|
||||
"test_postv", "boue",
|
||||
"test_offtv", "boue"
|
||||
)));
|
||||
assertNull(h.validateUpdate(adoc("id", "7",
|
||||
));
|
||||
assertU(adoc("id", "7",
|
||||
"test_posofftv", "glue",
|
||||
"test_basictv", "glue",
|
||||
"test_notv", "glue",
|
||||
"test_postv", "glue",
|
||||
"test_offtv", "glue"
|
||||
)));
|
||||
assertNull(h.validateUpdate(adoc("id", "8",
|
||||
));
|
||||
assertU(adoc("id", "8",
|
||||
"test_posofftv", "blee",
|
||||
"test_basictv", "blee",
|
||||
"test_notv", "blee",
|
||||
"test_postv", "blee",
|
||||
"test_offtv", "blee"
|
||||
)));
|
||||
assertNull(h.validateUpdate(adoc("id", "9",
|
||||
));
|
||||
assertU(adoc("id", "9",
|
||||
"test_posofftv", "blah",
|
||||
"test_basictv", "blah",
|
||||
"test_notv", "blah",
|
||||
"test_postv", "blah",
|
||||
"test_offtv", "blah"
|
||||
)));
|
||||
));
|
||||
|
||||
assertNull(h.validateUpdate(commit()));
|
||||
}
|
||||
|
||||
static String tv = "tvrh";
|
||||
|
||||
@Test
|
||||
public void testBasics() throws Exception {
|
||||
SolrCore core = h.getCore();
|
||||
SearchComponent tvComp = core.getSearchComponent("tvComponent");
|
||||
assertTrue("tvComp is null and it shouldn't be", tvComp != null);
|
||||
ModifiableSolrParams params = new ModifiableSolrParams();
|
||||
params.add(CommonParams.Q, "id:0");
|
||||
params.add(CommonParams.QT, "tvrh");
|
||||
params.add(TermVectorParams.TF, "true");
|
||||
params.add(TermVectorComponent.COMPONENT_NAME, "true");
|
||||
SolrRequestHandler handler = core.getRequestHandler("tvrh");
|
||||
SolrQueryResponse rsp;
|
||||
rsp = new SolrQueryResponse();
|
||||
rsp.add("responseHeader", new SimpleOrderedMap());
|
||||
handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
|
||||
NamedList values = rsp.getValues();
|
||||
NamedList termVectors = (NamedList) values.get(TermVectorComponent.TERM_VECTORS);
|
||||
assertTrue("termVectors is null and it shouldn't be", termVectors != null);
|
||||
if (VERBOSE) System.out.println("TVs:" + termVectors);
|
||||
NamedList doc = (NamedList) termVectors.getVal(0);
|
||||
assertTrue("doc is null and it shouldn't be", doc != null);
|
||||
assertEquals(doc.size(), 5);
|
||||
NamedList field = (NamedList) doc.get("test_posofftv");
|
||||
assertTrue("field is null and it shouldn't be", field != null);
|
||||
assertTrue(field.size() + " does not equal: " + 2, field.size() == 2);
|
||||
NamedList titl = (NamedList) field.get("titl");
|
||||
assertTrue("titl is null and it shouldn't be", titl != null);
|
||||
assertTrue(titl.get("tf") + " does not equal: " + 2, ((Integer) titl.get("tf")) == 2);
|
||||
//there should not be any positions or offsets
|
||||
NamedList positions = (NamedList) titl.get("positions");
|
||||
assertTrue("positions is not null and it should be", positions == null);
|
||||
NamedList offsets = (NamedList) titl.get("offsets");
|
||||
assertTrue("offsets is not null and it should be", offsets == null);
|
||||
String uniqueKeyFieldName = (String) termVectors.getVal(1);
|
||||
assertTrue("uniqueKeyFieldName is null and it shouldn't be", uniqueKeyFieldName != null);
|
||||
assertTrue(uniqueKeyFieldName + " is not equal to " + "id", uniqueKeyFieldName.equals("id") == true);
|
||||
|
||||
assertJQ(req("json.nl","map", "qt",tv, "q", "id:0", TermVectorComponent.COMPONENT_NAME, "true", TermVectorParams.TF, "true")
|
||||
,"/termVectors=={'doc-0':{'uniqueKey':'0'," +
|
||||
" 'test_basictv':{'anoth':{'tf':1},'titl':{'tf':2}}," +
|
||||
" 'test_offtv':{'anoth':{'tf':1},'titl':{'tf':2}}," +
|
||||
" 'test_posofftv':{'anoth':{'tf':1},'titl':{'tf':2}}," +
|
||||
" 'test_postv':{'anoth':{'tf':1},'titl':{'tf':2}}}," +
|
||||
" 'uniqueKeyFieldName':'id'}"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptions() throws Exception {
|
||||
SolrCore core = h.getCore();
|
||||
SearchComponent tvComp = core.getSearchComponent("tvComponent");
|
||||
assertTrue("tvComp is null and it shouldn't be", tvComp != null);
|
||||
ModifiableSolrParams params = new ModifiableSolrParams();
|
||||
params.add(CommonParams.Q, "id:0");
|
||||
params.add(CommonParams.QT, "tvrh");
|
||||
params.add(TermVectorParams.TF, "true");
|
||||
params.add(TermVectorParams.DF, "true");
|
||||
params.add(TermVectorParams.OFFSETS, "true");
|
||||
params.add(TermVectorParams.POSITIONS, "true");
|
||||
params.add(TermVectorParams.TF_IDF, "true");
|
||||
params.add(TermVectorComponent.COMPONENT_NAME, "true");
|
||||
|
||||
SolrRequestHandler handler = core.getRequestHandler("tvrh");
|
||||
SolrQueryResponse rsp;
|
||||
rsp = new SolrQueryResponse();
|
||||
rsp.add("responseHeader", new SimpleOrderedMap());
|
||||
handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);
|
||||
NamedList values = rsp.getValues();
|
||||
NamedList termVectors = (NamedList) values.get(TermVectorComponent.TERM_VECTORS);
|
||||
assertTrue("termVectors is null and it shouldn't be", termVectors != null);
|
||||
// System.out.println("TVs: " + termVectors);
|
||||
NamedList doc = (NamedList) termVectors.getVal(0);
|
||||
assertTrue("doc is null and it shouldn't be", doc != null);
|
||||
assertEquals(doc.size(), 5);
|
||||
NamedList offtv = (NamedList) doc.get("test_posofftv");
|
||||
assertTrue("offtv is null and it shouldn't be", offtv != null);
|
||||
assertTrue("offtv Size: " + offtv.size() + " is not: " + 2, offtv.size() == 2);
|
||||
NamedList another = (NamedList) offtv.get("anoth");
|
||||
NamedList offsets = (NamedList) another.get("offsets");
|
||||
assertTrue("offsets is null and it shouldn't be", offsets != null);
|
||||
assertTrue("offsets Size: " + offsets.size() + " is not greater than: " + 0, offsets.size() > 0);
|
||||
NamedList pos = (NamedList) another.get("positions");
|
||||
assertTrue("pos is null and it shouldn't be", pos != null);
|
||||
assertTrue("pos Size: " + pos.size() + " is not greater than: " + 0, pos.size() > 0);
|
||||
Integer df = (Integer) another.get("df");
|
||||
assertTrue("df is null and it shouldn't be", df != null);
|
||||
assertTrue(df + " does not equal: " + 2, df == 2);
|
||||
Double tfIdf = (Double) another.get("tf-idf");
|
||||
assertTrue("tfIdf is null and it shouldn't be", tfIdf != null);
|
||||
assertTrue(tfIdf + " does not equal: " + 0.5, tfIdf == 0.5);
|
||||
assertJQ(req("json.nl","map", "qt",tv, "q", "id:0", TermVectorComponent.COMPONENT_NAME, "true"
|
||||
, TermVectorParams.TF, "true", TermVectorParams.DF, "true", TermVectorParams.OFFSETS, "true", TermVectorParams.POSITIONS, "true", TermVectorParams.TF_IDF, "true")
|
||||
,"/termVectors/doc-0/test_posofftv/anoth=={'tf':1, 'offsets':{'start':20, 'end':27}, 'positions':{'position':1}, 'df':2, 'tf-idf':0.5}"
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
<field name="test_basictv" type="text" termVectors="true"/>
|
||||
<field name="test_notv" type="text" termVectors="false"/>
|
||||
<field name="test_postv" type="text" termVectors="true" termPositions="true"/>
|
||||
<field name="test_offtv" type="text" termVectors="true" termOffsets="true"/>
|
||||
<field name="test_posofftv" type="text" termVectors="true"
|
||||
termPositions="true" termOffsets="true"/>
|
||||
*/
|
||||
@Test
|
||||
public void testPerField() throws Exception {
|
||||
SolrCore core = h.getCore();
|
||||
|
|
Loading…
Reference in New Issue