def searchForMetadata(self, formValues, typeFilter=None):
     """
     @summary: does a search for all
     @param formValues: the formValues received from the search interface post
     @return: returns a list of dictinaries with results or an empty list 
     """                    
     # get all metadata documents that match search values
     results = self.portal_catalog.searchResults(meta_type = "Metadata")
     obResults = [x.getObject() for x in results]
     
     allStandards = XPathConfig.getMergedStandards()
     
     # filter for a given metadata standard
     if typeFilter:
         obResults = [x for x in obResults if x.getMetadatatype().lower().strip() == typeFilter.strip().lower()]        
             
     for field in formValues.keys():
         if field == "common_Title":
             obResults = [x for x in obResults if x.mTitle.lower().find(formValues['common_Title'].lower()) != -1]
         if field == "common_Date":
             # XXX change this to not include time  but just the date
             parts = formValues['common_Date'].split("-")
             d = date(int(parts[0]), int(parts[1]), int(parts[2]))                
             obResults = [x for x in obResults if x.mDate == d]                
         if field == "common_Keywords":
             obResults = [x for x in obResults if x.mKeywords.lower().find(formValues['common_Keywords'].lower()) != -1]                
         if field == "common_Abstract":
             obResults = [x for x in obResults if x.mAbstract.lower().find(formValues['common_Abstract'].lower()) != -1]
         if field == "common_Organization":
             obResults = [x for x in obResults if x.mOrganization.lower().find(formValues['common_Organization'].lower()) != -1]
         if field == "common_Language":
             obResults = [x for x in obResults if x.mLanguage.lower().find(formValues['common_Language'].lower()) != -1]
         if field == "common_Bounds":
             maxy = formValues["common_Bounds_North"]
             miny = formValues["common_Bounds_South"]
             maxx = formValues["common_Bounds_East"]
             minx = formValues["common_Bounds_West"]
             # check for intersect with metadata bounds
             # checkExtent(self, metaExtent, checkExtent, "Intersects"):
             obResults = [x for x in obResults if x.mBounds] # filter out all metadata without bounds                
             obResults = [x for x in obResults if self.checkExtent(x.mBounds, [minx,miny,maxx,maxy], "Intersects")] 
         
         # handle the standards, except common fields
         if not field in XPathConfig.COMMON.keys():
             # its a standard field
             fieldValue = formValues[field]
             xpathString = allStandards[field]                
             # use xpath from config to search for field                
             obResults = [x for x in obResults if str(x.getFirstExpressionResult(xpathString, minidom.parseString(x.xml))).lower().find(fieldValue.lower()) != -1] 
                     
     return obResults
 def getComminutySearchDict(self, formValues):
     """
     """     
     all = XPathConfig.getMergedStandards()   
     searchDict = {}
     for field in formValues.keys():            
         if formValues[field].lower().strip() != "" and field in all.keys():
             if field.find("common_Bounds") != -1:
                 searchDict["common_Bounds_North"] = formValues["common_Bounds_North"]
                 searchDict["common_Bounds_South"] = formValues["common_Bounds_South"]
                 searchDict["common_Bounds_East"] = formValues["common_Bounds_East"]
                 searchDict["common_Bounds_West"] = formValues["common_Bounds_West"]
             searchDict[field] = formValues[field] 
             
     return searchDict
    def getComminutySearchDict(self, formValues):
        """
        """
        all = XPathConfig.getMergedStandards()
        searchDict = {}
        for field in formValues.keys():
            if formValues[field].lower().strip() != "" and field in all.keys():
                if field.find("common_Bounds") != -1:
                    searchDict["common_Bounds_North"] = formValues[
                        "common_Bounds_North"]
                    searchDict["common_Bounds_South"] = formValues[
                        "common_Bounds_South"]
                    searchDict["common_Bounds_East"] = formValues[
                        "common_Bounds_East"]
                    searchDict["common_Bounds_West"] = formValues[
                        "common_Bounds_West"]
                searchDict[field] = formValues[field]

        return searchDict
    def searchForMetadata(self, formValues, typeFilter=None):
        """
        @summary: does a search for all
        @param formValues: the formValues received from the search interface post
        @return: returns a list of dictinaries with results or an empty list 
        """
        # get all metadata documents that match search values
        results = self.portal_catalog.searchResults(meta_type="Metadata")
        obResults = [x.getObject() for x in results]

        allStandards = XPathConfig.getMergedStandards()

        # filter for a given metadata standard
        if typeFilter:
            obResults = [
                x for x in obResults if x.getMetadatatype().lower().strip() ==
                typeFilter.strip().lower()
            ]

        for field in formValues.keys():
            if field == "common_Title":
                obResults = [
                    x for x in obResults if x.mTitle.lower().find(
                        formValues['common_Title'].lower()) != -1
                ]
            if field == "common_Date":
                # XXX change this to not include time  but just the date
                parts = formValues['common_Date'].split("-")
                d = date(int(parts[0]), int(parts[1]), int(parts[2]))
                obResults = [x for x in obResults if x.mDate == d]
            if field == "common_Keywords":
                obResults = [
                    x for x in obResults if x.mKeywords.lower().find(
                        formValues['common_Keywords'].lower()) != -1
                ]
            if field == "common_Abstract":
                obResults = [
                    x for x in obResults if x.mAbstract.lower().find(
                        formValues['common_Abstract'].lower()) != -1
                ]
            if field == "common_Organization":
                obResults = [
                    x for x in obResults if x.mOrganization.lower().find(
                        formValues['common_Organization'].lower()) != -1
                ]
            if field == "common_Language":
                obResults = [
                    x for x in obResults if x.mLanguage.lower().find(
                        formValues['common_Language'].lower()) != -1
                ]
            if field == "common_Bounds":
                maxy = formValues["common_Bounds_North"]
                miny = formValues["common_Bounds_South"]
                maxx = formValues["common_Bounds_East"]
                minx = formValues["common_Bounds_West"]
                # check for intersect with metadata bounds
                # checkExtent(self, metaExtent, checkExtent, "Intersects"):
                obResults = [x for x in obResults if x.mBounds
                             ]  # filter out all metadata without bounds
                obResults = [
                    x for x in obResults if self.checkExtent(
                        x.mBounds, [minx, miny, maxx, maxy], "Intersects")
                ]

            # handle the standards, except common fields
            if not field in XPathConfig.COMMON.keys():
                # its a standard field
                fieldValue = formValues[field]
                xpathString = allStandards[field]
                # use xpath from config to search for field
                obResults = [
                    x for x in obResults if str(
                        x.getFirstExpressionResult(
                            xpathString, minidom.parseString(
                                x.xml))).lower().find(fieldValue.lower()) != -1
                ]

        return obResults