本文整理汇总了Python中com.googlecode.fascinator.common.solr.SolrResult.getNumFound方法的典型用法代码示例。如果您正苦于以下问题:Python SolrResult.getNumFound方法的具体用法?Python SolrResult.getNumFound怎么用?Python SolrResult.getNumFound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.googlecode.fascinator.common.solr.SolrResult
的用法示例。
在下文中一共展示了SolrResult.getNumFound方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handleQuery
# 需要导入模块: from com.googlecode.fascinator.common.solr import SolrResult [as 别名]
# 或者: from com.googlecode.fascinator.common.solr.SolrResult import getNumFound [as 别名]
def handleQuery(self, query, fieldName, formatStr):
out = ByteArrayOutputStream()
req = SearchRequest(query)
req.setParam("fq", 'item_type:"object"')
req.setParam("fq", 'workflow_id:"dataset"')
req.setParam("rows", "1000")
self.indexer.search(req, out)
res = SolrResult(ByteArrayInputStream(out.toByteArray()))
hits = HashSet()
if (res.getNumFound() > 0):
results = res.getResults()
for searchRes in results:
searchResList = searchRes.getList(fieldName)
if (searchResList.isEmpty()==False):
for hit in searchResList:
if self.term is not None:
if hit.find(self.term) != -1:
hits.add(hit)
else:
hits.add(hit)
self.writer.print("[")
hitnum = 0
for hit in hits:
if (hitnum > 0):
self.writer.print(","+formatStr % {"hit":hit})
else:
self.writer.print(formatStr % {"hit":hit})
hitnum += 1
self.writer.print("]")
else:
self.writer.println("[\"\"]")
self.writer.close()
示例2: export
# 需要导入模块: from com.googlecode.fascinator.common.solr import SolrResult [as 别名]
# 或者: from com.googlecode.fascinator.common.solr.SolrResult import getNumFound [as 别名]
def export(self, exportType):
exportQuery = "%s:%s" % (self.facetField, self.facetFieldValue)
outputType = "text/%s; charset=UTF-8" % type
responseHeader = "attachment; filename=%s.%s" % (self.facetFieldValue, exportType)
try:
out = ByteArrayOutputStream()
recnumreq = SearchRequest(exportQuery)
recnumreq.setParam("fl","create_timestamp")
recnumreq.setParam("rows", "0")
self.indexer.search(recnumreq, out)
recnumres = SolrResult(ByteArrayInputStream(out.toByteArray()))
self.__rowsFoundSolr = "%s" % recnumres.getNumFound()
except:
self.errorMsg = "Export query failure. The issue has been logged (%s - %s)." % (sys.exc_info()[0], sys.exc_info()[1])
self.log.error("Export query threw an exception (package type was %s): %s - %s" % (self.facetFieldValue, sys.exc_info()[0], sys.exc_info()[1]))
return
out = ByteArrayOutputStream()
req = SearchRequest(exportQuery)
req.setParam("wt", exportType)
req.setParam("rows", self.__rowsFoundSolr)
self.indexer.search(req, out)
self.response.setHeader("Content-Disposition", responseHeader)
writer = self.response.getPrintWriter(outputType)
writer.println(out.toString("UTF-8"))
writer.close()
示例3: handleGrantNumber
# 需要导入模块: from com.googlecode.fascinator.common.solr import SolrResult [as 别名]
# 或者: from com.googlecode.fascinator.common.solr.SolrResult import getNumFound [as 别名]
def handleGrantNumber(self):
out = ByteArrayOutputStream()
req = SearchRequest("grant_numbers:%s*" % self.term)
req.setParam("fq", 'item_type:"object"')
req.setParam("fq", 'workflow_id:"dataset"')
req.setParam("rows", "1000")
self.indexer.search(req, out)
res = SolrResult(ByteArrayInputStream(out.toByteArray()))
hits = HashSet()
if (res.getNumFound() > 0):
creatorResults = res.getResults()
for creatorRes in creatorResults:
creatorList = creatorRes.getList("grant_numbers")
if (creatorList.isEmpty()==False):
for hit in creatorList:
hits.add(hit)
self.writer.print("[")
hitnum = 0
for hit in hits:
if (hitnum > 0):
self.writer.print(",\"%s\"" % hit)
else:
self.writer.print("\"%s\"" % hit)
hitnum += 1
self.writer.print("]")
else:
self.writer.println("[\"\"]")
self.writer.close()
示例4: handleWorkflowStep
# 需要导入模块: from com.googlecode.fascinator.common.solr import SolrResult [as 别名]
# 或者: from com.googlecode.fascinator.common.solr.SolrResult import getNumFound [as 别名]
def handleWorkflowStep(self):
out = ByteArrayOutputStream()
req = SearchRequest("workflow_step_label:[* TO *]" )
req.setParam("fq", 'item_type:"object"')
req.setParam("fq", 'workflow_id:"dataset"')
req.setParam("rows", "1000")
self.indexer.search(req, out)
res = SolrResult(ByteArrayInputStream(out.toByteArray()))
hits = HashSet()
if (res.getNumFound() > 0):
recordTypeResults = res.getResults()
for recordTypeResult in recordTypeResults:
recordTypeList = recordTypeResult.getList("workflow_step_label")
if (recordTypeList.isEmpty()==False):
for hit in recordTypeList:
hits.add(hit)
self.writer.println("[")
hitnum = 0
for hit in hits:
if (hitnum > 0):
self.writer.println(",{\"value\": \"%s\",\n\"label\": \"%s\"}" % (hit,hit))
else:
self.writer.println("{\"value\": \"%s\",\n\"label\": \"%s\"}" % (hit,hit))
hitnum += 1
self.writer.println("]")
else:
self.writer.println("[\"\"]")
self.writer.close()
示例5: _searchSets
# 需要导入模块: from com.googlecode.fascinator.common.solr import SolrResult [as 别名]
# 或者: from com.googlecode.fascinator.common.solr.SolrResult import getNumFound [as 别名]
def _searchSets(self, startPage=1):
req = SearchRequest(self.getQuery())
req.setParam("fq", 'item_type:"object"')
req.setParam("rows", str(self.getRecordsPerPage()))
req.setParam("start", str((startPage - 1) * self.getRecordsPerPage()))
req.addParam("fq", self.getFilterQuery())
req.setParam("fl", self.getReturnFields())
req.setParam("sort", "date_object_modified desc, f_dc_title asc")
if not self.isAdmin():
req.addParam("fq", self.getSecurityQuery())
out = ByteArrayOutputStream()
self.indexer.search(req, out)
result = SolrResult(ByteArrayInputStream(out.toByteArray()))
self._setPaging(result.getNumFound())
result.getJsonObject().put("lastPage", str(self.paging.getLastPage()))
result.getJsonObject().put("curPage", str(startPage))
return result
示例6: __init__
# 需要导入模块: from com.googlecode.fascinator.common.solr import SolrResult [as 别名]
# 或者: from com.googlecode.fascinator.common.solr.SolrResult import getNumFound [as 别名]
class ReportsData:
def __init__(self):
pass
def __activate__(self, context):
#import pydevd;pydevd.settrace()
self.velocityContext = context
self.vc("sessionState").remove("fq")
self.services = self.vc("Services")
self.log = context["log"]
self.__harvestList = None
self.__search()
# Get from velocity context
def vc(self, index):
if self.velocityContext[index] is not None:
return self.velocityContext[index]
else:
print "ERROR: Requested context entry '" + index + "' doesn't exist"
return None
def __search(self):
indexer = self.services.getIndexer()
# Security prep work
isAdmin = self.vc("page").authentication.is_admin()
if not isAdmin:
print "ERROR: User is not an admin '"
return None
req = SearchRequest('eventType:harvestStart')
req.setParam("rows", "100")
out = ByteArrayOutputStream()
indexer.searchByIndex(req, out, "eventLog")
self.__harvestList = SolrResult(ByteArrayInputStream(out.toByteArray()))
def getHarvestlist(self):
return self.__harvestList.getResults()
def getItemCount(self):
return self.__harvestList.getNumFound()
示例7: __init__
# 需要导入模块: from com.googlecode.fascinator.common.solr import SolrResult [as 别名]
# 或者: from com.googlecode.fascinator.common.solr.SolrResult import getNumFound [as 别名]
#.........这里部分代码省略.........
print "ERROR: Requested context entry '" + index + "' doesn't exist"
return None
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 getLatest(self):
return self.__latest.getResults()
def getMine(self):
return self.__mine.getResults()
def getWorkflows(self):
return self.__workflows.getResults()
def getItemCount(self):
return self.__result.getNumFound()
def getServicesStages(self):
return self.__servicesStages
示例8: __init__
# 需要导入模块: from com.googlecode.fascinator.common.solr import SolrResult [as 别名]
# 或者: from com.googlecode.fascinator.common.solr.SolrResult import getNumFound [as 别名]
#.........这里部分代码省略.........
fromDate = self.__request.getFromDate()
untilDate = self.__request.getUntilDate()
if fromDate is not None:
fromStr = fromDate.isoformat() + "Z"
self.log.debug("From Date: '{}'", fromStr)
if untilDate is not None:
untilStr = untilDate.isoformat() + "Z"
self.log.debug("Until Date: '{}'", untilStr)
queryStr = "last_modified:[%s TO %s]" % (fromStr, untilStr)
else:
queryStr = "last_modified:[%s TO *]" % (fromStr)
self.log.debug("Date query: '{}'", queryStr)
req.addParam("fq", queryStr)
else:
if untilDate is not None:
untilStr = untilDate.isoformat() + "Z"
self.log.debug("Until Date: '{}'", untilDate.isoformat())
queryStr = "last_modified:[* TO %s]" % (untilStr)
self.log.debug("Date query: '{}'", queryStr)
req.addParam("fq", queryStr)
# Check if there's resumption token exist in the formData
newToken = None
if self.__currentToken is not None:
start = int(self.__currentToken.getStart())
totalFound = int(self.__currentToken.getTotalFound())
nextTokenStart = start + recordsPerPage
if nextTokenStart < totalFound:
newToken = self.__currentToken
newToken.resetExpiry(self.__sessionExpiry)
newToken.setStart(nextTokenStart)
# or start a new resumption token
else:
start = 0
newToken = ResumptionToken(None, recordsPerPage, self.__metadataPrefix, self.__sessionExpiry)
req.setParam("start", str(start))
out = ByteArrayOutputStream()
self.services.indexer.search(req, out)
self.__result = SolrResult(ByteArrayInputStream(out.toByteArray()))
totalFound = self.__result.getNumFound()
if totalFound == 0:
newToken = None
# If an ID was requested, and not found, this is an error
if id is not None and id != "":
self.__request.setError("idDoesNotExist", "ID: '%s' not found" % id)
else:
self.__request.setError("noRecordsMatch", "No records match this request")
# We need to store this for NEW tokens
elif self.__currentToken is None:
# Assuming there are enough results to even keep the token
if newToken.getStart() < totalFound:
newToken.setTotalFound(totalFound)
else:
newToken = None
# Check if we need to remove the resumption token
else:
if (start + recordsPerPage) >= totalFound:
self.tokensDB.removeToken(self.__currentToken)
self.lastPage = True
# Store/update the resumption token
if newToken is not None:
# Brand new token
if self.__currentToken is None:
self.tokensDB.storeToken(newToken)
# Or update an old token
else:
self.tokensDB.updateToken(newToken)
self.__currentToken = newToken
def getToken(self):
if self.isInView(self.__metadataPrefix) and not self.lastPage:
return self.__currentToken
return None
def getMetadataFormats(self):
if self.oaiConfig is None:
self.oaiConfig = self.systemConfig.getJsonSimpleMap(["portal", "oai-pmh", "metadataFormats"])
return self.oaiConfig
def encodeXml(self, string):
return StringEscapeUtils.escapeXml(string)
def getPayload(self, oid, metadataFileName):
# First get the Object from storage
object = None
try:
object = self.services.getStorage().getObject(oid)
except StorageException, e:
return None
# Check whether the payload exists
try:
return object.getPayload(metadataFileName)
except StorageException, e:
return None
示例9: __activate__
# 需要导入模块: from com.googlecode.fascinator.common.solr import SolrResult [as 别名]
# 或者: from com.googlecode.fascinator.common.solr.SolrResult import getNumFound [as 别名]
#.........这里部分代码省略.........
req.addParam("fq", URLDecoder.decode(q, "UTF-8"))
portalQuery = self.__portal.query
if portalQuery:
req.addParam("fq", portalQuery)
req.addParam("fq", 'item_type:"object"')
if req.getParams("fq"):
self.__selected = ArrayList(req.getParams("fq"))
if self.__useSessionNavigation:
self.sessionState.set("fq", self.__selected)
self.sessionState.set("searchQuery", portalSearchQuery)
self.sessionState.set("pageNum", self.__pageNum)
# Make sure 'fq' has already been set in the session
if not self.page.authentication.is_admin():
current_user = self.page.authentication.get_username()
security_roles = self.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 + ")"
req.addParam("fq", security_query)
req.setParam("start", str((self.__pageNum - 1) * recordsPerPage))
#print " * search.py:", req.toString(), self.__pageNum
out = ByteArrayOutputStream()
self.services.indexer.search(req, out)
self.__result = SolrResult(ByteArrayInputStream(out.toByteArray()))
if self.__result is not None:
self.__paging = Pagination(self.__pageNum,
self.__result.getNumFound(),
self.__portal.recordsPerPage)
def __escapeQuery(self, q):
temp = ""
chars = "+-&|!(){}[]^\"~*?:\\"
for c in q:
if c in chars:
temp += "\%s" % c
else:
temp += c
return temp
# eq = q
# # escape all solr/lucene special chars
# # from http://lucene.apache.org/java/2_4_0/queryparsersyntax.html#Escaping%20Special%20Characters
# for c in "+-&|!(){}[]^\"~*?:\\":
# eq = eq.replace(c, "\\%s" % c)
# ## Escape UTF8
# try:
# return URLEncoder.encode(eq, "UTF-8")
# except UnsupportedEncodingException, e:
# print "Error during UTF8 escape! ", repr(eq)
# return eq
def getQueryTime(self):
return int(self.__result.getQueryTime()) / 1000.0;
def getPaging(self):
return self.__paging
def getResult(self):
示例10: __activate__
# 需要导入模块: from com.googlecode.fascinator.common.solr import SolrResult [as 别名]
# 或者: from com.googlecode.fascinator.common.solr.SolrResult import getNumFound [as 别名]
def __activate__(self, context):
response = context["response"]
log = context["log"]
writer = response.getPrintWriter("text/plain; charset=UTF-8")
auth = context["page"].authentication
sessionState = context["sessionState"]
result = JsonObject()
result.put("status", "error")
result.put("message", "An unknown error has occurred")
if auth.is_admin():
services = context["Services"]
formData = context["formData"]
func = formData.get("func")
oid = formData.get("oid")
portalId = formData.get("portalId")
portalManager = services.portalManager
if func == "reharvest":
# One object
if oid:
log.info(" * Reharvesting object '{}'", oid)
portalManager.reharvest(oid)
result.put("status", "ok")
result.put("message", "Object '%s' queued for reharvest")
# The whole portal
elif portalId:
log.info(" * Reharvesting view '{}'", portalId)
sessionState.set("reharvest/running/" + portalId, "true")
# TODO security filter - not necessary because this requires admin anyway?
portal = portalManager.get(portalId)
query = "*:*"
if portal.query != "":
query = portal.query
if portal.searchQuery != "":
if query == "*:*":
query = portal.searchQuery
else:
query = query + " AND " + portal.searchQuery
# query solr to get the objects to reharvest
rows = 25
req = SearchRequest(query)
req.setParam("fq", 'item_type:"object"')
req.setParam("rows", str(rows))
req.setParam("fl", "id")
done = False
count = 0
while not done:
req.setParam("start", str(count))
out = ByteArrayOutputStream()
services.indexer.search(req, out)
json = SolrResult(ByteArrayInputStream(out.toByteArray()))
objectIds = HashSet(json.getFieldList("id"))
if not objectIds.isEmpty():
portalManager.reharvest(objectIds)
count = count + rows
total = json.getNumFound()
log.info(" * Queued {} of {}...", (min(count, total), total))
done = (count >= total)
sessionState.remove("reharvest/running/" + portalId)
result.put("status", "ok")
result.put("message", "Objects in '%s' queued for reharvest" % portalId)
else:
response.setStatus(500)
result.put("message", "No object or view specified for reharvest")
elif func == "reindex":
if oid:
log.info(" * Reindexing object '{}'", oid)
services.indexer.index(oid)
services.indexer.commit()
result.put("status", "ok")
result.put("message", "Object '%s' queued for reindex" % portalId)
else:
response.setStatus(500)
result.put("message", "No object specified to reindex")
else:
response.setStatus(500)
result.put("message", "Unknown action '%s'" % func)
else:
response.setStatus(500)
result.put("message", "Only administrative users can access this API")
writer.println(result.toString())
writer.close()
示例11: __reportSearch
# 需要导入模块: from com.googlecode.fascinator.common.solr import SolrResult [as 别名]
# 或者: from com.googlecode.fascinator.common.solr.SolrResult import getNumFound [as 别名]
def __reportSearch(self):
self.reportId = self.request.getParameter("id")
self.format = self.request.getParameter("format")
self.report = self.reportManager.getReports().get(self.reportId)
self.reportQuery = self.report.getQueryAsString()
self.log.debug("Report query: " + self.reportQuery)
#Get a total number of records
try:
out = ByteArrayOutputStream()
recnumreq = SearchRequest(self.reportQuery)
recnumreq.setParam("rows", "0")
self.indexer.search(recnumreq, out)
recnumres = SolrResult(ByteArrayInputStream(out.toByteArray()))
self.__rowsFoundSolr = "%s" % recnumres.getNumFound()
except:
self.errorMsg = "Query failure. The issue has been logged (%s - %s)." % (sys.exc_info()[0], sys.exc_info()[1])
self.log.error("Reporting threw an exception (report was %s): %s - %s" % (self.report.getLabel(), sys.exc_info()[0], sys.exc_info()[1]))
return
#Setup the main query
req = SearchRequest(self.reportQuery)
req.setParam("fq", 'item_type:"object"')
req.setParam("fq", 'workflow_id:"dataset"')
req.setParam("rows", self.__rowsFoundSolr)
try:
#Now do the master search
out = ByteArrayOutputStream()
self.indexer.search(req, out)
self.__reportResult = SolrResult(ByteArrayInputStream(out.toByteArray()))
self.__checkResults()
except:
self.errorMsg = "Query failure. The issue has been logged (%s - %s)." % (sys.exc_info()[0], sys.exc_info()[1])
self.log.error("Reporting threw an exception (report was %s): %s - %s" % (self.report.getLabel(), sys.exc_info()[0], sys.exc_info()[1]))
return
#At this point the display template has enough to go with.
#We just need to handle the CSV now
if (self.format == "csv"):
#Setup the main query - we need to requery to make sure we return
#only the required fields. We'll use the specific IDs that met the
#__checkResults check
req = SearchRequest(self.reportQuery)
req.setParam("fq", 'item_type:"object"')
req.setParam("fq", 'workflow_id:"dataset"')
req.setParam("rows", self.__rowsFoundSolr)
req.setParam("csv.mv.separator",";")
#we need to get a list of the matching IDs from Solr
#this doesn't work for long queries so it's abandoned
#but left here commented to make sure we don't try it again
#idQry = ""
#for item in self.getProcessedResultsList():
# idQry += item.get("id") + " OR "
#req.setParam("fq", 'id:(%s)' % idQry[:len(idQry)-4])
#Create a list of IDs for reference when preparing the CSV
idQryList = []
for item in self.getProcessedResultsList():
idQryList.append(item.get("id"))
#Setup SOLR query with the required fields
self.fields = self.systemConfig.getArray("redbox-reports","csv-output-fields")
#We must have an ID field and it must be the first field
fieldString = "id,"
if self.fields is not None:
for field in self.fields:
fieldString = fieldString+ field.get("field-name")+","
fieldString = fieldString[:-1]
req.setParam("fl",fieldString)
out = ByteArrayOutputStream()
try:
self.indexer.search(req, out, self.format)
except:
#We can't get the result back from SOLR so fail back to the template display
self.errorMsg = "Query failure. Failed to load the data - this issue has been logged (%s - %s)." % (sys.exc_info()[0], sys.exc_info()[1])
self.log.error("Reporting threw an exception (report was %s); Error: %s - %s" % (self.report.getLabel(), sys.exc_info()[0], sys.exc_info()[1]))
return
try:
csvResponseString = String(out.toByteArray(),"utf-8")
csvResponseLines = csvResponseString.split("\n")
except:
#We can't get the result back from SOLR so fail back to the template display
self.errorMsg = "Query failure. Failed to prepare the CSV - this issue has been logged (%s - %s)." % (sys.exc_info()[0], sys.exc_info()[1])
self.log.error("Reporting threw an exception (report was %s); Error: %s - %s" % (self.report.getLabel(), sys.exc_info()[0], sys.exc_info()[1]))
return
fileName = self.urlEncode(self.report.getLabel())
self.log.debug("Generating CSV report with file name: " + fileName)
self.response.setHeader("Content-Disposition", "attachment; filename=%s.csv" % fileName)
sw = StringWriter()
parser = CSVParser()
writer = CSVWriter(sw)
count = 0
prevLine = ""
badRowFlag = False
#.........这里部分代码省略.........
示例12: __init__
# 需要导入模块: from com.googlecode.fascinator.common.solr import SolrResult [as 别名]
# 或者: from com.googlecode.fascinator.common.solr.SolrResult import getNumFound [as 别名]
#.........这里部分代码省略.........
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"')
def getLatest(self):
return self.__latest.getResults()
def getAlerts(self):
return self.__alerts.getResults()
def getItemCount(self):
return self.__result.getNumFound()
def getStages(self):
return self.__stages
def getEmbargoes(self):
return self.__embargoes.getResults()
def _searchEmbargoes(self):
req = SearchRequest("item_type:object")
req.setParam("fq", 'redbox\:embargo.redbox\:isEmbargoed:on')
req.addParam("fq", 'workflow_step:final-review')
req.addParam("fq", "")
req.setParam("fl","id,date_embargoed,dc_title")
req.setParam("rows", "25")
req.setParam("sort", "date_embargoed asc, dc_title asc");
out = ByteArrayOutputStream()
indexer = Services.getIndexer()
indexer.search(req, out)
self.__embargoes = SolrResult(ByteArrayInputStream(out.toByteArray()))
self.velocityContext["log"].info("searchEmbargoes call ended" + str(self.__embargoes))
def formatDate(self, date):
dfSource = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
dfTarget = SimpleDateFormat("dd/MM/yyyy")
return dfTarget.format(dfSource.parse(date))