oodt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattm...@apache.org
Subject svn commit: r1034648 - in /incubator/oodt/trunk: CHANGES.txt filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/TestLuceneCatalog.java
Date Sat, 13 Nov 2010 05:00:47 GMT
Author: mattmann
Date: Sat Nov 13 05:00:46 2010
New Revision: 1034648

URL: http://svn.apache.org/viewvc?rev=1034648&view=rev
Log:
- fix for OODT-57 LuceneCatalog.getNumHits() doesn't properly translate the given Query object
into the equivalent Lucene query

Modified:
    incubator/oodt/trunk/CHANGES.txt
    incubator/oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java
    incubator/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/TestLuceneCatalog.java

Modified: incubator/oodt/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/oodt/trunk/CHANGES.txt?rev=1034648&r1=1034647&r2=1034648&view=diff
==============================================================================
--- incubator/oodt/trunk/CHANGES.txt (original)
+++ incubator/oodt/trunk/CHANGES.txt Sat Nov 13 05:00:46 2010
@@ -1,6 +1,12 @@
 Apache OODT Change Log
 ======================
 
+Release 0.2 (Current Development)
+
+* OODT-57 LuceneCatalog.getNumHits() doesn't properly translate the 
+  given Query object into the equivalent Lucene query (Gabe Resneck via mattmann)
+
+
 
 Release 0.1-incubating 
 --------------------------------------------

Modified: incubator/oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java
URL: http://svn.apache.org/viewvc/incubator/oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java?rev=1034648&r1=1034647&r2=1034648&view=diff
==============================================================================
--- incubator/oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java
(original)
+++ incubator/oodt/trunk/filemgr/src/main/java/org/apache/oodt/cas/filemgr/catalog/LuceneCatalog.java
Sat Nov 13 05:00:46 2010
@@ -1226,47 +1226,9 @@ public class LuceneCatalog implements Ca
                     "product_type_id", type.getProductTypeId()));
             booleanQuery.add(prodTypeTermQuery, BooleanClause.Occur.MUST);
 
-            for (Iterator<QueryCriteria> i = query.getCriteria().iterator(); i.hasNext();)
{
-                // add a new query for each of the query criteria
-                QueryCriteria crit = i.next();
-                Element termElem = null;
-
-                try {
-                    termElem = valLayer.getElementByName(crit.getElementName());
-                } catch (ValidationLayerException e) {
-                    LOG.log(Level.WARNING,
-                            "ValidationLayer exception when looking up element definition
for: ["
-                                    + crit.getElementName() + "]: Message: "
-                                    + e.getMessage());
-                    continue;
-                }
-
-                if (crit instanceof TermQueryCriteria) {
-                    String val = ((TermQueryCriteria) crit).getValue();
-                    TermQuery tq = new TermQuery(new Term(termElem
-                            .getElementName(), val));
-                    booleanQuery.add(tq, BooleanClause.Occur.MUST);
-                } else if (crit instanceof RangeQueryCriteria) {
-                    String startVal = ((RangeQueryCriteria) crit)
-                            .getStartValue();
-                    String endVal = ((RangeQueryCriteria) crit).getEndValue();
-                    boolean inclusive = ((RangeQueryCriteria) crit)
-                            .getInclusive();
-                    Term startTerm = null, endTerm = null;
-                    if (!startVal.equals("")) {
-                        startTerm = new Term(termElem.getElementName(),
-                                startVal);
-                    }
-
-                    if (!endVal.equals("")) {
-                        endTerm = new Term(termElem.getElementName(), endVal);
-                    }
-
-                    RangeQuery rq = new RangeQuery(startTerm, endTerm,
-                            inclusive);
-                    booleanQuery.add(rq, BooleanClause.Occur.MUST);
-                }
-            }
+            //convert filemgr query into a lucene query
+            for (QueryCriteria queryCriteria : query.getCriteria()) 
+                booleanQuery.add(this.getQuery(queryCriteria), BooleanClause.Occur.MUST);
 
             Sort sort = new Sort(new SortField("CAS.ProductReceivedTime",
                     SortField.STRING, true));

Modified: incubator/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/TestLuceneCatalog.java
URL: http://svn.apache.org/viewvc/incubator/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/TestLuceneCatalog.java?rev=1034648&r1=1034647&r2=1034648&view=diff
==============================================================================
--- incubator/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/TestLuceneCatalog.java
(original)
+++ incubator/oodt/trunk/filemgr/src/test/org/apache/oodt/cas/filemgr/catalog/TestLuceneCatalog.java
Sat Nov 13 05:00:46 2010
@@ -27,10 +27,13 @@ import java.util.Vector;
 import org.apache.oodt.cas.filemgr.catalog.LuceneCatalog;
 import org.apache.oodt.cas.filemgr.catalog.LuceneCatalogFactory;
 import org.apache.oodt.cas.filemgr.metadata.CoreMetKeys;
+import org.apache.oodt.cas.filemgr.structs.BooleanQueryCriteria;
 import org.apache.oodt.cas.filemgr.structs.Product;
 import org.apache.oodt.cas.filemgr.structs.ProductPage;
 import org.apache.oodt.cas.filemgr.structs.ProductType;
+import org.apache.oodt.cas.filemgr.structs.Query;
 import org.apache.oodt.cas.filemgr.structs.Reference;
+import org.apache.oodt.cas.filemgr.structs.TermQueryCriteria;
 import org.apache.oodt.cas.filemgr.structs.exceptions.CatalogException;
 import org.apache.oodt.cas.metadata.Metadata;
 
@@ -367,7 +370,73 @@ public class TestLuceneCatalog extends T
             fail(e.getMessage());
         }
     }
-
+    
+    public void testPagedQuery(){
+    	// Add a couple of Products and associated Metadata
+    	Product testProduct = null;
+    	for(int i = 0; i < catPageSize + 1; i++){
+    		testProduct = Product.getDefaultFlatProduct("test" + i,
+					"urn:oodt:GenericFile");
+    		testProduct.getProductType().setName("GenericFile");
+    		Reference ref = new Reference("file:///foo.txt", "file:///bar.txt", 100);
+            Vector<Reference> references = new Vector<Reference>();
+            references.add(ref);
+            testProduct.setProductReferences(references);
+    		Metadata met = new Metadata();
+    		met.addMetadata("Filename", "tempProduct" + i);
+    		met.addMetadata("ProductStructure", "Flat");
+    		try {
+                myCat.addProduct(testProduct);
+                myCat.addMetadata(met, testProduct);
+            } catch (Exception e) {
+                e.printStackTrace();
+                fail(e.getMessage());
+            }
+    	}
+    	
+    	// Formulate a test query
+    	Query query = new Query();
+    	BooleanQueryCriteria bqc = new BooleanQueryCriteria();
+    	try{
+    		bqc.setOperator(BooleanQueryCriteria.AND);
+    	}catch (Exception e){
+    		e.printStackTrace();
+            fail(e.getMessage());
+    	}
+    	TermQueryCriteria tqc = new TermQueryCriteria();
+    	tqc.setElementName("ProductStructure");
+    	tqc.setValue("Flat");
+    	try{
+    		bqc.addTerm(tqc);
+    	}catch (Exception e){
+    		e.printStackTrace();
+            fail(e.getMessage());
+    	}
+    	tqc = new TermQueryCriteria();
+    	tqc.setElementName("Filename");
+    	tqc.setValue("tempProduct1");
+    	try{
+    		bqc.addTerm(tqc);
+    	}catch (Exception e){
+    		e.printStackTrace();
+            fail(e.getMessage());
+    	}
+    	query.addCriterion(bqc);
+    	
+    	// Perform the query and validate results
+    	ProductPage page = null;
+    	try{
+    		page = myCat.pagedQuery(query, testProduct.getProductType(), 1);
+    	}catch (Exception e){
+    		e.printStackTrace();
+            fail(e.getMessage());
+    	}
+    	assertEquals(page.getPageProducts().size(), 1);
+    	assertEquals(page.getPageProducts().get(0).getProductName(), "test1");
+    	assertEquals(page.getPageNum(), 1);
+    	assertEquals(page.getTotalPages(), 1);
+    }
+	
     private static Product getTestProduct() {
         Product testProduct = Product.getDefaultFlatProduct("test",
                 "urn:oodt:GenericFile");



Mime
View raw message