Modified: xml/xindice/trunk/java/tests/src/org/apache/xindice/core/indexer/ValueIndexerTest.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/core/indexer/ValueIndexerTest.java?rev=628599&r1=628598&r2=628599&view=diff ============================================================================== --- xml/xindice/trunk/java/tests/src/org/apache/xindice/core/indexer/ValueIndexerTest.java (original) +++ xml/xindice/trunk/java/tests/src/org/apache/xindice/core/indexer/ValueIndexerTest.java Sun Feb 17 18:33:55 2008 @@ -23,7 +23,9 @@ import org.apache.xindice.core.DBException; import org.apache.xindice.core.Database; import org.apache.xindice.core.DatabaseTest; +import org.apache.xindice.core.data.Value; import org.apache.xindice.util.Configuration; +import org.apache.xindice.util.XindiceException; import org.apache.xindice.xml.dom.DOMParser; import junit.framework.TestCase; @@ -78,6 +80,11 @@ return ind.queryMatches(query); } + private IndexMatch[] query(Indexer ind, String pattern, Value[] values, int op) throws DBException { + IndexPattern indPattern = new IndexPattern(collection.getSymbols(), pattern, null); + IndexQuery query = new IndexQuery(indPattern, op, values); + return ind.queryMatches(query); + } public void testStringIndex() throws Exception { Indexer ind = createIndex("StrIndex", "[EMAIL PROTECTED]", "string"); @@ -98,6 +105,25 @@ assertEquals(2, match.length); } + public void testWildcardIndex() throws Exception { + Indexer ind = createIndex("StrIndex", "[EMAIL PROTECTED]", "string"); + + Document document = DOMParser.toDocument("<test1 value='abc'/>"); + collection.insertDocument("key1", document); + + document = DOMParser.toDocument("<test value='abe'/>"); + collection.insertDocument("key2", document); + + document = DOMParser.toDocument("<test1 value='bcd'/>"); + collection.insertDocument("key3", document); + + document = DOMParser.toDocument("<test value='aac'/>"); + collection.insertDocument("key", document); + + IndexMatch[] match = query(ind, "[EMAIL PROTECTED]", "ab", IndexQuery.SW); + assertEquals(1, match.length); + } + public void testElementEmptyStringIndex() throws Exception { Indexer ind = createIndex("StrIndex", "test", "string"); @@ -183,7 +209,7 @@ IndexMatch[] match = query(ind, "[EMAIL PROTECTED]", "71.48941", IndexQuery.LT); assertEquals(6, match.length); - match = query(ind, "[EMAIL PROTECTED]", "-211.499539", IndexQuery.LT); + match = query(ind, "[EMAIL PROTECTED]", "-211.499539", IndexQuery.LT); assertEquals(2, match.length); } @@ -255,5 +281,178 @@ match = query(ind, "[EMAIL PROTECTED]", "2", IndexQuery.EQ); assertEquals("Did not find new XML document in the index: ", 1, match.length); + } + + public void testStringAbsolutePathIndex() throws Exception { + Indexer ind = createIndex("StrIndex", "/doc/[EMAIL PROTECTED]", "string"); + + Document document = DOMParser.toDocument("<doc><test value='abc'/></doc>"); + collection.insertDocument("key1", document); + + document = DOMParser.toDocument("<doc><test value='abe'/></doc>"); + collection.insertDocument("key2", document); + + document = DOMParser.toDocument("<doc><test value='bcd'/></doc>"); + collection.insertDocument("key3", document); + + document = DOMParser.toDocument("<doc><test value='aac'/></doc>"); + collection.insertDocument("key", document); + + IndexMatch[] match = query(ind, "/doc/[EMAIL PROTECTED]", "ab", IndexQuery.SW); + assertEquals(2, match.length); + } + + public void testStringRelativePathIndex() throws Exception { + Indexer ind = createIndex("StrIndex", "[EMAIL PROTECTED]", "string"); + + Document document = DOMParser.toDocument("<doc1><test value='abc'/></doc1>"); + collection.insertDocument("key1", document); + + document = DOMParser.toDocument("<doc><test value='abe'/></doc>"); + collection.insertDocument("key2", document); + + document = DOMParser.toDocument("<doc1><test value='bcd'/></doc1>"); + collection.insertDocument("key3", document); + + document = DOMParser.toDocument("<doc><test value='aac'/></doc>"); + collection.insertDocument("key", document); + + // index pattern is more general and therefore will return keys that not necesserily match the query + IndexMatch[] match = query(ind, "/doc/[EMAIL PROTECTED]", "ab", IndexQuery.SW); + assertEquals(2, match.length); + } + + public void testQueryEQ() throws Exception { + Indexer ind = createIndex("Index", "[EMAIL PROTECTED]", "long"); + fillQueryData(); + + IndexMatch[] match = query(ind, "[EMAIL PROTECTED]", "8", IndexQuery.EQ); + assertEquals(1, match.length); + + match = query(ind, "[EMAIL PROTECTED]", "9", IndexQuery.EQ); + assertEquals(2, match.length); + } + + public void testQueryNEQ() throws Exception { + Indexer ind = createIndex("Index", "[EMAIL PROTECTED]", "long"); + fillQueryData(); + + IndexMatch[] match = query(ind, "[EMAIL PROTECTED]", "8", IndexQuery.NEQ); + assertEquals(4, match.length); + + match = query(ind, "[EMAIL PROTECTED]", "9", IndexQuery.NEQ); + assertEquals(3, match.length); + } + + public void testQueryGT() throws Exception { + Indexer ind = createIndex("Index", "[EMAIL PROTECTED]", "long"); + fillQueryData(); + + IndexMatch[] match = query(ind, "[EMAIL PROTECTED]", "8", IndexQuery.GT); + assertEquals(3, match.length); + + match = query(ind, "[EMAIL PROTECTED]", "9", IndexQuery.GT); + assertEquals(1, match.length); + } + + public void testQueryGEQ() throws Exception { + Indexer ind = createIndex("Index", "[EMAIL PROTECTED]", "long"); + fillQueryData(); + + IndexMatch[] match = query(ind, "[EMAIL PROTECTED]", "10", IndexQuery.GEQ); + assertEquals(1, match.length); + + match = query(ind, "[EMAIL PROTECTED]", "9", IndexQuery.GEQ); + assertEquals(3, match.length); + } + + public void testQueryLT() throws Exception { + Indexer ind = createIndex("Index", "[EMAIL PROTECTED]", "long"); + fillQueryData(); + + IndexMatch[] match = query(ind, "[EMAIL PROTECTED]", "7", IndexQuery.LT); + assertEquals(0, match.length); + + match = query(ind, "[EMAIL PROTECTED]", "9", IndexQuery.LT); + assertEquals(2, match.length); + } + + public void testQueryLEQ() throws Exception { + Indexer ind = createIndex("Index", "[EMAIL PROTECTED]", "long"); + fillQueryData(); + + IndexMatch[] match = query(ind, "[EMAIL PROTECTED]", "7", IndexQuery.LEQ); + assertEquals(1, match.length); + + match = query(ind, "[EMAIL PROTECTED]", "9", IndexQuery.LEQ); + assertEquals(4, match.length); + } + + public void testQueryIN() throws Exception { + Indexer ind = createIndex("Index", "[EMAIL PROTECTED]", "long"); + fillQueryData(); + + IndexMatch[] match = query(ind, "[EMAIL PROTECTED]", new Value[] {new Value("7"), new Value("9")}, IndexQuery.IN); + assertEquals(3, match.length); + } + + public void testQueryBW() throws Exception { + Indexer ind = createIndex("Index", "[EMAIL PROTECTED]", "long"); + fillQueryData(); + + IndexMatch[] match = query(ind, "[EMAIL PROTECTED]", new Value[] {new Value("8"), new Value("10")}, IndexQuery.BW); + assertEquals(4, match.length); + + match = query(ind, "[EMAIL PROTECTED]", new Value[] {new Value("8"), new Value("9")}, IndexQuery.BW); + assertEquals(3, match.length); + } + + public void testQueryBWX() throws Exception { + Indexer ind = createIndex("Index", "[EMAIL PROTECTED]", "long"); + fillQueryData(); + + IndexMatch[] match = query(ind, "[EMAIL PROTECTED]", new Value[] {new Value("8"), new Value("10")}, IndexQuery.BWX); + assertEquals(2, match.length); + } + + public void testQueryNBW() throws Exception { + Indexer ind = createIndex("Index", "[EMAIL PROTECTED]", "long"); + fillQueryData(); + + IndexMatch[] match = query(ind, "[EMAIL PROTECTED]", new Value[] {new Value("8"), new Value("10")}, IndexQuery.NBW); + assertEquals(3, match.length); + } + + public void testQueryNBWX() throws Exception { + Indexer ind = createIndex("Index", "[EMAIL PROTECTED]", "long"); + fillQueryData(); + + IndexMatch[] match = query(ind, "[EMAIL PROTECTED]", new Value[] {new Value("8"), new Value("9")}, IndexQuery.NBWX); + assertEquals(2, match.length); + } + + public void testQueryNIN() throws Exception { + Indexer ind = createIndex("Index", "[EMAIL PROTECTED]", "long"); + fillQueryData(); + + IndexMatch[] match = query(ind, "[EMAIL PROTECTED]", new Value[] {new Value("7"), new Value("9")}, IndexQuery.NIN); + assertEquals(2, match.length); + } + + private void fillQueryData() throws XindiceException { + Document document = DOMParser.toDocument("<test value='10'/>"); + collection.insertDocument("key1", document); + + document = DOMParser.toDocument("<test value='9'/>"); + collection.insertDocument("key2", document); + + document = DOMParser.toDocument("<test value='8'/>"); + collection.insertDocument("key3", document); + + document = DOMParser.toDocument("<test value='9'/>"); + collection.insertDocument("key4", document); + + document = DOMParser.toDocument("<test value='7'/>"); + collection.insertDocument("key5", document); } }
Modified: xml/xindice/trunk/java/tests/src/org/apache/xindice/core/query/TextQueryResolverTest.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/core/query/TextQueryResolverTest.java?rev=628599&r1=628598&r2=628599&view=diff ============================================================================== --- xml/xindice/trunk/java/tests/src/org/apache/xindice/core/query/TextQueryResolverTest.java (original) +++ xml/xindice/trunk/java/tests/src/org/apache/xindice/core/query/TextQueryResolverTest.java Sun Feb 17 18:33:55 2008 @@ -79,8 +79,8 @@ collection.insertDocument("key5", document); HashMap patterns = new HashMap(); - patterns.put("test1", "[EMAIL PROTECTED]"); - patterns.put("test2", "[EMAIL PROTECTED]"); + patterns.put("test1", "a"); + patterns.put("test2", "b"); idx = createIndex("test", patterns); } Modified: xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/IndexedSearchTest.java URL: http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/IndexedSearchTest.java?rev=628599&r1=628598&r2=628599&view=diff ============================================================================== --- xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/IndexedSearchTest.java (original) +++ xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/IndexedSearchTest.java Sun Feb 17 18:33:55 2008 @@ -899,7 +899,7 @@ "//person[info[ftcontains('text')]]/[EMAIL PROTECTED] = 'yes']", // query "SENA", // index name "Lucene", // index type - "info", // index pattern + "info", // index pattern 8, // indexed query speedup expected (conservative) new String[] { // test docs specifically for this test "<?xml version='1.0'?>" + @@ -935,4 +935,39 @@ aTest.runTest(); } + + /** + * Tests a starts-with search query for an attribute value that should be resolvable using indexed searching + * on a value index with a more complex index pattern. + */ + public void testAbsoluteIndexPatternStartsWithSearch() throws Exception { + // search all records whose last name begins with 'Smi' + IndexerTestDefinition aTest = new IndexerTestDefinition( + "testSpecificElementSpecificAttributeValueIndexedStartsWithSearch", // description + "/person/phone[starts-with(@call, 'n')]", // query + "SESA", // index name + "Value", // index type + "/person/[EMAIL PROTECTED]", // index pattern + 6, // indexed query speedup expected (conservative) + new String[] { // test docs specifically for this test + "<?xml version='1.0'?>" + + "<person number3='yes'>" + + "<first surname='no' given='yes'>Sally</first>" + + "<last surname='yes'>aSm</last>" + + "<phone call='no' type='work'>555-345-6789</phone>" + + "<address> " + + "<street>" + + "<number given='no' />" + + "</street>" + + "</address>" + + "</person>" + }, + 1, // expected result count + new Object[] { // expected resources to check for (can be empty or partial set) + new Integer(0), "<phone call='no' type='work'>555-345-6789</phone>" + }); + + aTest.runTest(); + } + }