本文整理汇总了Python中com.googlecode.fascinator.common.solr.SolrResult类的典型用法代码示例。如果您正苦于以下问题:Python SolrResult类的具体用法?Python SolrResult怎么用?Python SolrResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SolrResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handleWorkflowStep
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()
示例2: export
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
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: findPublishedRecords
def findPublishedRecords(self):
#req = SearchRequest("published:\"true\"")
req = SearchRequest("storage_id:\"c6a214670dc644e5ebdaede4a2243f67\"")
out = ByteArrayOutputStream()
self.indexer.search(req, out)
solrResult = SolrResult(ByteArrayInputStream(out.toByteArray()))
return solrResult.getResults()
示例5: handleQuery
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()
示例6: checkAprovedRequests
def checkAprovedRequests(self, provisioned=0, startPage=1):
""" A customised query for package type of arms at workflow_step of arms-approved
Get a list of requests filtered by provisioning_checklist
"""
workflowStep = "arms-approved"
if self.packageType:
req = SearchRequest(self.packageType)
else:
req = SearchRequest("packageType:arms")
req.addParam("fq", 'workflow_step:' + workflowStep)
if provisioned:
req.addParam("fq", '-provisioning_checklist.4:null')
else:
req.addParam("fq", 'provisioning_checklist.4:null')
req.setParam("sort", "date_object_modified desc, f_dc_title asc")
req.setParam("fl","id,dc_title,date-provisioned")
out = ByteArrayOutputStream()
self.indexer.search(req, out)
solrResults = SolrResult(ByteArrayInputStream(out.toByteArray()))
if solrResults:
results = solrResults.getResults()
if results:
results = self.mergeEvents(results, ["arms_draft","arms_redraft","arms_review","arms_approved","arms_rejected"])
self._setPaging(results.size())
return results
else:
return ArrayList()
示例7: findPackagesToTransition
def findPackagesToTransition(self, fromWorkflowId, fromWorkflowStage):
req = SearchRequest("workflow_id:"+fromWorkflowId+" AND _query_:\"workflow_step:"+fromWorkflowStage+"\"")
req.setParam("fq", "owner:[* TO *]")
req.setParam("fq", "security_filter:[* TO *]")
out = ByteArrayOutputStream()
self.indexer.search(req, out)
solrResult = SolrResult(ByteArrayInputStream(out.toByteArray()))
return solrResult.getResults()
示例8: checkRequests
def checkRequests(self, checklist_filter=['1'], role_filter='reviewer', exclusive=True, startPage=1):
""" A customised query for arms at arms-review
Get a list of requests filtered by provisioning_checklist
For assessor, it is user based and queries against committee-responses.metadata
"""
workflowStep = "arms-review"
if self.packageType:
req = SearchRequest(self.packageType)
else:
req = SearchRequest("packageType:arms")
req.addParam("fq", 'workflow_step:' + workflowStep)
for item in ['1','2','3','4']:
if item in checklist_filter:
req.addParam("fq", '-provisioning_checklist.' + item + ':null' + ' AND provisioning_checklist.' + item + ':[* TO *]')
else:
if exclusive:
# ensure that brand new submissions (not yet saved by reviewer) are also returned
req.addParam("fq", 'provisioning_checklist.' + item + ':null' + ' OR (*:* -provisioning_checklist.' + item + ':[* TO *])')
req.setParam("sort", "date_object_modified desc, f_dc_title asc")
req.setParam("fl",self.returnFields)
out = ByteArrayOutputStream()
self.indexer.search(req, out)
solrResults = SolrResult(ByteArrayInputStream(out.toByteArray()))
if solrResults:
results = solrResults.getResults()
if results:
packageResults = results
results = self.mergeEvents(packageResults, ["arms_draft","arms_redraft","arms_review","arms_approved","arms_rejected"])
returnArray = JSONArray()
if role_filter.startswith('assessor'):
if role_filter == 'assessor':
query_status = ['new', 'draft']
elif role_filter == 'assessor-assessed':
query_status = ['submitted']
x = Assessment()
x.activate(self.velocityContext)
i = 0
rows = self.recordsPerPage
start = (startPage - 1) * self.recordsPerPage
for r in results:
status = x.queryStatus(r.get("id"))
if status in query_status:
if i >= start and i - start < rows:
if status == 'submitted':
assessment_submitted_date = x.queryMyAttr('date')
if assessment_submitted_date:
r.getJsonObject().put('date', assessment_submitted_date)
returnArray.add(r)
i = i + 1
else:
returnArray = results
self._setPaging(returnArray.size())
return returnArray
else:
return ArrayList()
示例9: getAttachments
def getAttachments(self):
attachmentType = "review-attachments"
req = SearchRequest("attached_to:%s AND attachment_type:%s" % (self.oid, attachmentType))
req.setParam("rows", "1000")
out = ByteArrayOutputStream()
self.Services.indexer.search(req, out)
response = SolrResult(ByteArrayInputStream(out.toByteArray()))
return response.getResults()
示例10: findPackagesToPurge
def findPackagesToPurge(self,packageType):
req = SearchRequest("display_type:"+packageType +" AND date_object_created:[* TO NOW-7DAY]")
req.setParam("fq", "owner:[* TO *]")
req.setParam("fq", "security_filter:[* TO *]")
req.setParam("fl", "storage_id,date_object_created,date_object_modified")
out = ByteArrayOutputStream()
self.indexer.search(req, out)
solrResult = SolrResult(ByteArrayInputStream(out.toByteArray()))
return solrResult.getResults()
示例11: _packageResults
def _packageResults(self, req, solrLog=None):
out = ByteArrayOutputStream()
if solrLog:
self.indexer.searchByIndex(req, out, solrLog)
else:
self.indexer.searchByIndex(req, out)
solrResults = SolrResult(ByteArrayInputStream(out.toByteArray()))
if solrResults:
return solrResults.getResults()
else:
return ArrayList()
示例12: __init__
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()
示例13: getFacetFields
def getFacetFields(self):
try:
out = ByteArrayOutputStream()
req = SearchRequest("*:*")
req.setParam("fl","facet_counts")
req.setParam("facet", "on")
req.setParam("facet.field", self.facetField)
req.setParam("wt", "json")
self.indexer.search(req, out)
res = SolrResult(ByteArrayInputStream(out.toByteArray()))
facets = res.getFacets()
facet = facets.get(self.facetField)
if facet is not None and facet.values().size() > 0:
self.facetFields = facet.values()
else:
self.errorMsg = "No facet field values to export. Please enter/harvest some data first."
except:
self.errorMsg = "Get facet field query failure. The issue has been logged (%s - %s)." % (sys.exc_info()[0], sys.exc_info()[1])
self.log.error("Get facet field threw an exception : %s - %s" % (sys.exc_info()[0], sys.exc_info()[1]))
return
示例14: getAttachedFiles
def getAttachedFiles(self, oid):
# Build a query
req = SearchRequest("attached_to:%s" % oid)
req.setParam("rows", "1000")
# Run a search
out = ByteArrayOutputStream()
self.Services.getIndexer().search(req, out)
result = SolrResult(ByteArrayInputStream(out.toByteArray()))
# Process results
docs = JSONArray()
for doc in result.getResults():
attachmentType = self.escapeHtml(WordUtils.capitalizeFully(doc.getFirst("attachment_type").replace("-", " ")))
accessRights = self.escapeHtml(WordUtils.capitalizeFully(doc.getFirst("access_rights")))
entry = JsonObject()
entry.put("filename", self.escapeHtml(doc.getFirst("filename")))
entry.put("attachment_type", attachmentType)
entry.put("access_rights", accessRights)
entry.put("id", self.escapeHtml(doc.getFirst("id")))
docs.add(entry)
return docs
示例15: __activate__
def __activate__(self, context):
formData = context["formData"]
services = context["Services"]
response = context["response"]
# Prepare a query
q = formData.get("q")
if q is not None and q != "":
query = "(item_type:object AND " + self.titleTokens(q.strip()) + ")"
else:
query = "item_type:object"
# Can't link to yourself AND we're not interested in attachments
oid = formData.get("qs")
query += " AND -storage_id:\""+oid+"\""
# And we're not interested in attachments
query += " AND display_type:\"package-dataset\""
req = SearchRequest(query)
req.setParam("fl", "dc_title,storage_id,pidProperty")
limit = formData.get("limit")
if limit is None:
limit = 10
req.setParam("rows", limit)
# Search Solr
indexer = services.getIndexer()
out = ByteArrayOutputStream()
indexer.search(req, out)
result = SolrResult(ByteArrayInputStream(out.toByteArray()))
# Build a response
list = []
for doc in result.getResults():
title = doc.getFirst("dc_title")
#oid = doc.getFirst("storage_id")
oid = doc.getFirst("pidProperty")
list.append("%s::%s" % (oid, title))
result = "\n".join(list)
writer = response.getPrintWriter("text/plain; charset=UTF-8")
writer.println(result)
writer.close()