def process_tags(self, result): tags = [] tagsDict = {} # Build a dictionary of the tags for doc in result: # Get Anotar data from Solr data doc = JsonSimple(doc.get("jsonString")) # Get actual tag text tag = doc.getString(None, ["content", "literal"]) # Find out if they have locators locs = doc.getJsonSimpleList(["annotates", "locators"]).size() if locs == 0: # Basic tags, just aggregate counts if tag in tagsDict: # We've seen it before, just increment the counter existing = tagsDict[tag] count = existing.getInteger(0, ["tagCount"]) existing.getJsonObject().put("tagCount", str(count + 1)) else: # First time, store this object doc.getJsonObject().put("tagCount", str(1)) tagsDict[tag] = doc else: # Tags with a locator, special case for images etc. tags.append(doc.toString()) # Push all the 'basic' counts into the list to return for tag in tagsDict: tags.append(tagsDict[tag].toString()) return "[" + ",".join(tags) + "]"
def process_tags(self, result): tags = [] tagsDict = {} # Build a dictionary of the tags for doc in result: # Get Anotar data from Solr data doc = JsonSimple(doc.get("jsonString")) # Get actual tag text tag = doc.getString(None, ["content", "literal"]) # Find out if they have locators locs = doc.getJsonSimpleList(["annotates", "locators"]).size() if locs == 0: # Basic tags, just aggregate counts if tag in tagsDict: # We've seen it before, just increment the counter existing = tagsDict[tag] count = existing.getInteger(0, ["tagCount"]) existing.getJsonObject().put("tagCount", str(count + 1)) else: # First time, store this object doc.getJsonObject().put("tagCount", str(1)) tagsDict[tag] = doc else: # Tags with a locator, special case for images etc. tags.append(doc.toString()) # Push all the 'basic' counts into the list to return for tag in tagsDict: tags.append(tagsDict[tag].toString()) return "[" + ",".join(tags) + "]"
def __activate__(self, context): self.vc = context responseType = "text/html; charset=UTF-8" responseMsg = "" func = self.vc("formData").get("func") if func == "placeName": try: placeName = self.vc("formData").get("q") url = "http://ws.geonames.org/searchJSON?fuzzy=0.7&q=" + placeName client = BasicHttpClient(url) get = GetMethod(url) statusInt = client.executeMethod(get) r = str(statusInt) json = JsonSimple(get.getResponseBodyAsString().strip()) for geoName in json.getJsonSimpleList("geonames"): responseMsg += "%s, %s|%s \n" % (geoName.getString(None, "name"), geoName.getString(None, "countryName"), geoName.getString(None, "geonameId")) except Exception, e: print "exception: ", str(e) r = str(e), None responseType = "text/plain; charset=UTF-8"
def __activate__(self, context): self.vc = context responseType = "text/html; charset=UTF-8" responseMsg = "" func = self.vc("formData").get("func") if func == "placeName": try: placeName = self.vc("formData").get("q") url = "http://ws.geonames.org/searchJSON?fuzzy=0.7&q=" + placeName client = BasicHttpClient(url) get = GetMethod(url) statusInt = client.executeMethod(get) r = str(statusInt) json = JsonSimple(get.getResponseBodyAsString().strip()) for geoName in json.getJsonSimpleList("geonames"): responseMsg += "%s, %s|%s \n" % (geoName.getString( None, "name"), geoName.getString(None, "countryName"), geoName.getString( None, "geonameId")) except Exception, e: print "exception: ", str(e) r = str(e), None responseType = "text/plain; charset=UTF-8"
def __search(self): indexer = Services.getIndexer() portalQuery = Services.getPortalManager().get( self.vc("portalId")).getQuery() portalSearchQuery = Services.getPortalManager().get( self.vc("portalId")).getSearchQuery() # Security prep work current_user = self.vc("page").authentication.get_username() security_roles = self.vc("page").authentication.get_roles_list() security_filter = 'security_filter:("' + '" OR "'.join( security_roles) + '")' security_exceptions = 'security_exception:"' + current_user + '"' owner_query = 'owner:"' + current_user + '"' security_query = "(" + security_filter + ") OR (" + security_exceptions + ") OR (" + owner_query + ")" isAdmin = self.vc("page").authentication.is_admin() req = SearchRequest("*:*") req.setParam("fq", 'item_type:"object"') if portalQuery: req.addParam("fq", portalQuery) if portalSearchQuery: req.addParam("fq", portalSearchQuery) req.addParam("fq", "") req.setParam("rows", "0") req.setParam("facet", "true") req.setParam("facet.field", "workflow_step") if not isAdmin: req.addParam("fq", security_query) out = ByteArrayOutputStream() indexer.search(req, out) steps = SolrResult(ByteArrayInputStream(out.toByteArray())) self.__steps = steps.getFacets().get("workflow_step") wfConfig = JsonSimple( FascinatorHome.getPathFile("harvest/workflows/dataset.json")) jsonStageList = wfConfig.getJsonSimpleList(["stages"]) stages = [] for jsonStage in jsonStageList: wfStage = WorkflowStage(jsonStage, self.__steps) stages.append(wfStage) self.__stages = stages req = SearchRequest("*:*") req.setParam("fq", 'item_type:"object"') if portalQuery: req.addParam("fq", portalQuery) if portalSearchQuery: req.addParam("fq", portalSearchQuery) req.addParam("fq", "") req.setParam("rows", "25") req.setParam("sort", "last_modified desc, f_dc_title asc") if not isAdmin: req.addParam("fq", security_query) out = ByteArrayOutputStream() indexer.search(req, out) self.__result = SolrResult(ByteArrayInputStream(out.toByteArray())) req.addParam("fq", "workflow_step:%s" % stages[0].getName()) out = ByteArrayOutputStream() indexer.search(req, out) self.__alerts = SolrResult(ByteArrayInputStream(out.toByteArray())) req = SearchRequest( "last_modified:[NOW-1MONTH TO *] AND workflow_step:live") req.setParam("fq", 'item_type:"object"') if portalQuery: req.addParam("fq", portalQuery) if portalSearchQuery: req.addParam("fq", portalSearchQuery) req.setParam("rows", "10") req.setParam("sort", "last_modified desc, f_dc_title asc") if not isAdmin: req.addParam("fq", security_query) out = ByteArrayOutputStream() indexer.search(req, out) self.__latest = SolrResult(ByteArrayInputStream(out.toByteArray())) self.vc("sessionState").set("fq", 'item_type:"object"')
def __search(self): indexer = self.services.getIndexer() portalQuery = self.services.getPortalManager().get(self.vc("portalId")).getQuery() portalSearchQuery = self.services.getPortalManager().get(self.vc("portalId")).getSearchQuery() # Security prep work current_user = self.vc("page").authentication.get_username() security_roles = self.vc("page").authentication.get_roles_list() security_filter = 'security_filter:("' + '" OR "'.join(security_roles) + '")' security_exceptions = 'security_exception:"' + current_user + '"' owner_query = 'owner:"' + current_user + '"' security_query = "(" + security_filter + ") OR (" + security_exceptions + ") OR (" + owner_query + ")" isAdmin = self.vc("page").authentication.is_admin() req = SearchRequest("last_modified:[NOW-1MONTH TO *]") req.setParam("fq", 'item_type:"object"') if portalQuery: req.addParam("fq", portalQuery) if portalSearchQuery: req.addParam("fq", portalSearchQuery) req.setParam("rows", "10") req.setParam("sort", "last_modified desc, f_dc_title asc"); if not isAdmin: req.addParam("fq", security_query) out = ByteArrayOutputStream() indexer.search(req, out) self.__latest = SolrResult(ByteArrayInputStream(out.toByteArray())) req = SearchRequest(owner_query) req.setParam("fq", 'item_type:"object"') if portalQuery: req.addParam("fq", portalQuery) if portalSearchQuery: req.addParam("fq", portalSearchQuery) req.setParam("rows", "10") req.setParam("sort", "last_modified desc, f_dc_title asc"); if not isAdmin: req.addParam("fq", security_query) out = ByteArrayOutputStream() indexer.search(req, out) self.__mine = SolrResult(ByteArrayInputStream(out.toByteArray())) req = SearchRequest('workflow_security:"' + current_user + '"') req.setParam("fq", 'item_type:"object"') if portalQuery: req.addParam("fq", portalQuery) if portalSearchQuery: req.addParam("fq", portalSearchQuery) req.setParam("rows", "10") req.setParam("sort", "last_modified desc, f_dc_title asc"); if not isAdmin: req.addParam("fq", security_query) out = ByteArrayOutputStream() indexer.search(req, out) self.__workflows = SolrResult(ByteArrayInputStream(out.toByteArray())) req = SearchRequest("*:*") req.setParam("fq", 'item_type:"object"') if portalQuery: req.addParam("fq", portalQuery) if portalSearchQuery: req.addParam("fq", portalSearchQuery) req.addParam("fq", "") req.setParam("rows", "0") if not isAdmin: req.addParam("fq", security_query) out = ByteArrayOutputStream() indexer.search(req, out) self.vc("sessionState").set("fq", 'item_type:"object"') #sessionState.set("query", portalQuery.replace("\"", "'")) # Load in the services UI workflow selfSubmitWfConfig = JsonSimple(FascinatorHome.getPathFile("harvest/workflows/servicesUI.json")) selfSubmitJsonStageList = selfSubmitWfConfig.getJsonSimpleList(["stages"]) servicesStages = [] for jsonStage in selfSubmitJsonStageList: wfStage = WorkflowStage(jsonStage, self.__steps) servicesStages.append(wfStage) self.__selfservicesStages = servicesStages self.__result = SolrResult(ByteArrayInputStream(out.toByteArray()))
def __search(self): indexer = Services.getIndexer() portalQuery = Services.getPortalManager().get(self.vc("portalId")).getQuery() portalSearchQuery = Services.getPortalManager().get(self.vc("portalId")).getSearchQuery() # Security prep work current_user = self.vc("page").authentication.get_username() security_roles = self.vc("page").authentication.get_roles_list() security_filter = 'security_filter:("' + '" OR "'.join(security_roles) + '")' security_exceptions = 'security_exception:"' + current_user + '"' owner_query = 'owner:"' + current_user + '"' security_query = "(" + security_filter + ") OR (" + security_exceptions + ") OR (" + owner_query + ")" isAdmin = self.vc("page").authentication.is_admin() req = SearchRequest("*:*") req.setParam("fq", 'item_type:"object"') if portalQuery: req.addParam("fq", portalQuery) if portalSearchQuery: req.addParam("fq", portalSearchQuery) req.addParam("fq", "") req.setParam("rows", "0") req.setParam("facet", "true") req.setParam("facet.field", "workflow_step") if not isAdmin: req.addParam("fq", security_query) out = ByteArrayOutputStream() indexer.search(req, out) steps = SolrResult(ByteArrayInputStream(out.toByteArray())) self.__steps = steps.getFacets().get("workflow_step") wfConfig = JsonSimple(FascinatorHome.getPathFile("harvest/workflows/dataset.json")) jsonStageList = wfConfig.getJsonSimpleList(["stages"]) stages = [] for jsonStage in jsonStageList: wfStage = WorkflowStage(jsonStage, self.__steps) stages.append(wfStage) self.__stages = stages req = SearchRequest("*:*") req.setParam("fq", 'item_type:"object"') if portalQuery: req.addParam("fq", portalQuery) if portalSearchQuery: req.addParam("fq", portalSearchQuery) req.addParam("fq", "") req.setParam("rows", "25") req.setParam("sort", "last_modified desc, f_dc_title asc"); if not isAdmin: req.addParam("fq", security_query) out = ByteArrayOutputStream() indexer.search(req, out) self.__result = SolrResult(ByteArrayInputStream(out.toByteArray())) req.addParam("fq", "workflow_step:%s" % stages[0].getName()) out = ByteArrayOutputStream() indexer.search(req, out) self.__alerts = SolrResult(ByteArrayInputStream(out.toByteArray())) req = SearchRequest("last_modified:[NOW-1MONTH TO *] AND workflow_step:live") req.setParam("fq", 'item_type:"object"') if portalQuery: req.addParam("fq", portalQuery) if portalSearchQuery: req.addParam("fq", portalSearchQuery) req.setParam("rows", "10") req.setParam("sort", "last_modified desc, f_dc_title asc"); if not isAdmin: req.addParam("fq", security_query) out = ByteArrayOutputStream() indexer.search(req, out) self.__latest = SolrResult(ByteArrayInputStream(out.toByteArray())) self._searchEmbargoes() self.vc("sessionState").set("fq", 'item_type:"object"')