Apache Solr open-source search software
SOLR-11093: tests - templatize graph query test for different field types, remove schema-graph.xml
yonika26d1023ff32
diff --git a/solr/core/src/test-files/solr/collection1/conf/schema-graph.xml b/solr/core/src/test-files/solr/collection1/conf/schema-graph.xmldeleted file mode 100644index a75ce663818..00000000000--- a/solr/core/src/test-files/solr/collection1/conf/schema-graph.xml+++ /dev/null@@ -1,71 +0,0 @@-<?xml version="1.0" encoding="UTF-8" ?>-<!-- 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. -->--<!-- This is a stripped down schema that includes the node_id and edge_id- fields to test graph queries -->--<schema name="graphexample" version="1.6">- <!-- field names should consist of alphanumeric or underscore characters- only and not start with a digit. This is not currently strictly enforced,- but other field names will not have first class support from all components- and back compatibility is not guaranteed. Names with both leading and trailing- underscores (e.g. _version_) are reserved. -->- <!-- unique id for all records in the index. -->- <field name="id" type="string" indexed="true" stored="true"- required="true" multiValued="false" />-- <!-- If you remove this field, you must _also_ disable the update log in- solrconfig.xml or Solr won't start. _version_ and update log are required- for SolrCloud -->- <field name="_version_" type="long" indexed="true" stored="true" />-- <!-- points to the root document of a block of nested documents. Required- for nested document support, may be removed otherwise (not used in graph- query test) -->- <field name="_root_" type="string" indexed="true" stored="false" />-- <!-- the field that contains the "node_id" for graph traversal -->- <field name="node_id" type="string" indexed="true" stored="true"- multiValued="false" omitNorms="true" termVectors="true" />- <!-- multi-valued field that contains the edge id's for graph traversal -->- <field name="edge_id" type="string" indexed="true" stored="true"- multiValued="true" omitNorms="true" omitPositions="true" termVectors="true" />-- <!-- typical title/text fields -->- <field name="title" type="text_general" indexed="true" stored="true"- multiValued="true" omitNorms="true" omitPositions="true" termVectors="true" />- <field name="text" type="text_general" indexed="true" stored="true"- multiValued="true" omitNorms="true" omitPositions="true" termVectors="true" />-- <!-- catch all field for indexing unknown fields. -->- <dynamicField name="*" type="string" indexed="true"- stored="true" multiValued="true" />- <!-- call out the explicit doc id. -->- <uniqueKey>id</uniqueKey>- <!-- Field types -->- <fieldType name="string" class="solr.StrField"- sortMissingLast="true" />- <fieldType name="long" class="solr.TrieLongField"- precisionStep="0" positionIncrementGap="0" />- <fieldType name="text_general" class="solr.TextField"- positionIncrementGap="100">- <analyzer type="index">- <tokenizer class="solr.StandardTokenizerFactory" />- <filter class="solr.LowerCaseFilterFactory" />- </analyzer>- <analyzer type="query">- <tokenizer class="solr.StandardTokenizerFactory" />- <filter class="solr.LowerCaseFilterFactory" />- </analyzer>- </fieldType>--</schema>diff --git a/solr/core/src/test/org/apache/solr/search/join/GraphQueryTest.java b/solr/core/src/test/org/apache/solr/search/join/GraphQueryTest.javaindex 357363c0c4a..b8f8fc867a8 100644--- a/solr/core/src/test/org/apache/solr/search/join/GraphQueryTest.java+++ b/solr/core/src/test/org/apache/solr/search/join/GraphQueryTest.java@@ -18,8 +18,6 @@ package org.apache.solr.search.join;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.common.params.SolrParams;-import org.apache.solr.common.util.NamedList;-import org.apache.solr.request.SolrQueryRequest;import org.junit.BeforeClass;import org.junit.Test;@@ -28,89 +26,78 @@ public class GraphQueryTest extends SolrTestCaseJ4 {@BeforeClasspublic static void beforeTests() throws Exception {- initCore("solrconfig.xml","schema-graph.xml");+ initCore("solrconfig.xml","schema_latest.xml");}-+@Testpublic void testGraph() throws Exception {+ doGraph( params("node_id","node_s", "edge_id","edge_ss") );+ // TODO: try with numeric fields... doGraph( params("node_id","node_i", "edge_id","edge_is") );+ }++ public void doGraph(SolrParams p) throws Exception {+ String node_id = p.get("node_id");+ String edge_id = p.get("edge_id");+// 1 -> 2 -> 3 -> ( 4 5 )// 7 -> 1// 8 -> ( 1 2 )- assertU(adoc("id", "doc_1", "node_id", "1", "edge_id", "2", "text", "foo", "title", "foo10"));- assertU(adoc("id", "doc_2", "node_id", "2", "edge_id", "3", "text", "foo"));+ assertU(adoc("id", "doc_1", node_id, "1", edge_id, "2", "text", "foo", "title", "foo10" ));+ assertU(adoc("id", "doc_2", node_id, "2", edge_id, "3", "text", "foo" ));assertU(commit());- assertU(adoc("id", "doc_3", "node_id", "3", "edge_id", "4", "edge_id", "5", "table", "foo"));- assertU(adoc("id", "doc_4", "node_id", "4", "table", "foo"));+ assertU(adoc("id", "doc_3", node_id, "3", edge_id, "4", edge_id, "5"));+ assertU(adoc("id", "doc_4", node_id, "4" ));assertU(commit());- assertU(adoc("id", "doc_5", "node_id", "5", "edge_id", "7", "table", "bar"));- assertU(adoc("id", "doc_6", "node_id", "6", "edge_id", "3" ));- assertU(adoc("id", "doc_7", "node_id", "7", "edge_id", "1" ));- assertU(adoc("id", "doc_8", "node_id", "8", "edge_id", "1", "edge_id", "2" ));- assertU(adoc("id", "doc_9", "node_id", "9"));+ assertU(adoc("id", "doc_5", node_id, "5", edge_id, "7" ));+ assertU(adoc("id", "doc_6", node_id, "6", edge_id, "3" ));+ assertU(adoc("id", "doc_7", node_id, "7", edge_id, "1" ));+ assertU(adoc("id", "doc_8", node_id, "8", edge_id, "1", edge_id, "2" ));+ assertU(adoc("id", "doc_9", node_id, "9"));assertU(commit());// update docs so they're in a new segment.- assertU(adoc("id", "doc_1", "node_id", "1", "edge_id", "2", "text", "foo"));- assertU(adoc("id", "doc_2", "node_id", "2", "edge_id", "3", "edge_id", "9", "text", "foo11"));+ assertU(adoc("id", "doc_1", node_id, "1", edge_id, "2", "text", "foo"));+ assertU(adoc("id", "doc_2", node_id, "2", edge_id, "3", edge_id, "9", "text", "foo11"));assertU(commit());// a graph for testing traversal filter 10 - 11 -> (12 | 13)- assertU(adoc("id", "doc_10", "node_id", "10", "edge_id", "11", "title", "foo"));- assertU(adoc("id", "doc_11", "node_id", "11", "edge_id", "12", "edge_id", "13", "text", "foo11"));- assertU(adoc("id", "doc_12", "node_id", "12", "text", "foo10"));- assertU(adoc("id", "doc_13", "node_id", "13", "edge_id", "12", "text", "foo10"));+ assertU(adoc("id", "doc_10", node_id, "10", edge_id, "11", "title", "foo"));+ assertU(adoc("id", "doc_11", node_id, "11", edge_id, "12", edge_id, "13", "text", "foo11"));+ assertU(adoc("id", "doc_12", node_id, "12", "text", "foo10"));+ assertU(adoc("id", "doc_13", node_id, "13", edge_id, "12", "text", "foo10"));assertU(commit());// Now we have created a simple graph// start traversal from node id to edge id- String gQuery = "{!graph from=\"node_id\" to=\"edge_id\"}id:doc_1";- SolrQueryRequest qr = createRequest(gQuery);- assertQ(qr,"//*[@numFound='7']");-- String g2Query = "{!graph from=\"node_id\" to=\"edge_id\" returnRoot=\"true\" returnOnlyLeaf=\"false\"}id:doc_8";- qr = createRequest(g2Query);- assertQ(qr,"//*[@numFound='8']");-- String g3Query = "{!graph from=\"node_id\" to=\"edge_id\" returnRoot=\"false\" returnOnlyLeaf=\"false\"}id:doc_8";- qr = createRequest(g3Query);- assertQ(qr,"//*[@numFound='7']");-- String g4Query = "{!graph from=\"node_id\" to=\"edge_id\" returnRoot=\"true\" returnOnlyLeaf=\"false\" traversalFilter=\"text:foo11\"}id:doc_8";- qr = createRequest(g4Query);- assertQ(qr,"//*[@numFound='2']");-- String g5Query = "{!graph from=\"node_id\" to=\"edge_id\" returnRoot=\"true\" returnOnlyLeaf=\"false\" maxDepth=0}id:doc_8";- qr = createRequest(g5Query);- assertQ(qr,"//*[@numFound='1']");-- String g6Query = "{!graph from=\"node_id\" to=\"edge_id\" returnRoot=\"true\" returnOnlyLeaf=\"false\" maxDepth=1}id:doc_8";- qr = createRequest(g6Query);- assertQ(qr,"//*[@numFound='3']");-- String g7Query = "{!graph from=\"node_id\" to=\"edge_id\" returnRoot=\"false\" returnOnlyLeaf=\"false\" maxDepth=1}id:doc_8";- qr = createRequest(g7Query);- assertQ(qr,"//*[@numFound='2']");-- String g8Query = "{!graph from=\"node_id\" to=\"edge_id\" returnRoot=\"false\" returnOnlyLeaf=\"true\" maxDepth=2}id:doc_8";- qr = createRequest(g8Query);- assertQ(qr,"//*[@numFound='1']");-- String g9Query = "{!graph from=\"node_id\" to=\"edge_id\" maxDepth=1}id:doc_1";- qr = createRequest(g9Query);- assertQ(qr,"//*[@numFound='2']");-- String g10Query = "{!graph from=\"node_id\" to=\"edge_id\" returnRoot=false maxDepth=1}id:doc_1";- qr = createRequest(g10Query);- assertQ(qr,"//*[@numFound='1']");- }- private SolrQueryRequest createRequest(String query) {- SolrQueryRequest qr = req(query);- NamedList<Object> par = qr.getParams().toNamedList();- par.add("debug", "true");- par.add("rows", "10");- par.add("fl", "id,node_id,edge_id");- par.remove("qt");- SolrParams newp = SolrParams.toSolrParams(par);- qr.setParams(newp);- return qr;+ // TODO: assert which documents actually come back+ assertJQ(req(p, "q","{!graph from=${node_id} to=${edge_id}}id:doc_1")+ , "/response/numFound==7"+ );+ assertJQ(req(p, "q","{!graph from=${node_id} to=${edge_id} returnRoot=true returnOnlyLeaf=false}id:doc_8")+ , "/response/numFound==8"+ );+ assertJQ(req(p, "q","{!graph from=${node_id} to=${edge_id} returnRoot=false returnOnlyLeaf=false}id:doc_8")+ , "/response/numFound==7"+ );+ assertJQ(req(p, "q","{!graph from=${node_id} to=${edge_id} returnRoot=true returnOnlyLeaf=false traversalFilter='text:foo11'}id:doc_8")+ , "/response/numFound==2"+ );+ assertJQ(req(p, "q","{!graph from=${node_id} to=${edge_id} returnRoot=true returnOnlyLeaf=false maxDepth=0}id:doc_8")+ , "/response/numFound==1"+ );+ assertJQ(req(p, "q","{!graph from=${node_id} to=${edge_id} returnRoot=true returnOnlyLeaf=false maxDepth=1}id:doc_8")+ , "/response/numFound==3"+ );+ assertJQ(req(p, "q","{!graph from=${node_id} to=${edge_id} returnRoot=false returnOnlyLeaf=false maxDepth=1}id:doc_8")+ , "/response/numFound==2"+ );+ assertJQ(req(p, "q","{!graph from=${node_id} to=${edge_id} returnRoot=false returnOnlyLeaf=true maxDepth=2}id:doc_8")+ , "/response/numFound==1"+ );+ assertJQ(req(p, "q","{!graph from=${node_id} to=${edge_id} maxDepth=1}id:doc_1")+ , "/response/numFound==2"+ );+ assertJQ(req(p, "q","{!graph from=${node_id} to=${edge_id} returnRoot=false maxDepth=1}id:doc_1")+ , "/response/numFound==1"+ );}}