本文整理汇总了Python中au.edu.usq.fascinator.api.indexer.SearchRequest类的典型用法代码示例。如果您正苦于以下问题:Python SearchRequest类的具体用法?Python SearchRequest怎么用?Python SearchRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SearchRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __getStorageId
def __getStorageId(self, oid):
req = SearchRequest('id:"%s"' % oid)
req.addParam("fl", "storage_id")
out = ByteArrayOutputStream()
Services.indexer.search(req, out)
json = JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
return json.getList("response/docs").get(0).get("storage_id")
示例2: __isIndexed
def __isIndexed(self, oid):
query = 'id:"%s"' % oid
req = SearchRequest(query)
req.addParam("fq", 'item_type:"object"')
out = ByteArrayOutputStream()
self.Services.indexer.search(req, out)
solrData = SolrResult(ByteArrayInputStream(out.toByteArray()))
return solrData.getNumFound()!=0
示例3: __activate__
def __activate__(self, context):
response = context["response"]
writer = response.getPrintWriter("text/plain; charset=UTF-8")
auth = context["page"].authentication
result = JsonConfigHelper()
result.set("status", "error")
result.set("message", "An unknown error has occurred")
if auth.is_logged_in() and 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":
if oid:
print "Reharvesting object '%s'" % oid
portalManager.reharvest("oid")
result.set("status", "ok")
result.set("message", "Object '%s' queued for reharvest")
elif portalId:
print " Reharvesting view '%s'" % portalId
# TODO security filter
# TODO this should loop through the whole portal,
# not just the first page of results
portal = portalManager.get(portalId)
req = SearchRequest(portal.query)
req.setParam("fq", 'item_type:"object"')
out = ByteArrayOutputStream();
services.indexer.search(req, out)
json = JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
objectIds = json.getList("response/docs//id")
if not objectIds.isEmpty():
portalManager.reharvest(objectIds)
result.set("status", "ok")
result.set("message", "Objects in '%s' queued for reharvest" % portalId)
else:
response.setStatus(500)
result.set("message", "No object or view specified for reharvest")
elif func == "reindex":
if oid:
print "Reindexing object '%s'" % oid
services.indexer.index(oid)
services.indexer.commit()
result.set("status", "ok")
result.set("message", "Objects in '%s' queued for reharvest" % portalId)
else:
response.setStatus(500)
result.set("message", "No object specified to reindex")
else:
response.setStatus(500)
result.set("message", "Unknown action '%s'" % func)
else:
response.setStatus(500)
result.set("message", "Only administrative users can access this API")
writer.println(result.toString())
writer.close()
示例4: search_solr
def search_solr(self):
query = "(rootUri:"
if self.rootUriList:
query += "(" + " OR ".join(self.rootUriList) + ")"
else:
query += "\"" + self.rootUri + "\""
if self.type:
query += " AND type:\"" + self.type + "\""
query += ")"
#print "**********", query
req = SearchRequest(query)
req.setParam("facet", "false")
req.setParam("rows", str(99999))
req.setParam("sort", "dateCreated asc")
req.setParam("start", str(0))
#security_roles = page.authentication.get_roles_list();
#security_query = 'security_filter:("' + '" OR "'.join(security_roles) + '")'
#req.addParam("fq", security_query)
out = ByteArrayOutputStream()
Services.indexer.annotateSearch(req, out)
result = JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
result = result.getJsonList("response/docs")
# Every annotation for this URI
if self.type == "http://www.purl.org/anotar/ns/type/0.1#Tag":
return self.process_tags(result)
else:
return self.process_response(result)
示例5: __loadSolrData
def __loadSolrData(self, oid):
portal = self.vc("page").getPortal()
query = 'id:"%s"' % oid
if portal.getSearchQuery():
query += " AND " + portal.getSearchQuery()
req = SearchRequest(query)
req.addParam("fq", 'item_type:"object"')
req.addParam("fq", portal.getQuery())
out = ByteArrayOutputStream()
self.vc("Services").getIndexer().search(req, out)
return SolrResult(ByteArrayInputStream(out.toByteArray()))
示例6: __loadSolrData
def __loadSolrData(self, oid):
portal = self.page.getPortal()
query = 'id:"%s"' % oid
if self.isDetail() and portal.getSearchQuery():
query += " AND " + portal.getSearchQuery()
req = SearchRequest(query)
req.addParam("fq", 'item_type:"object"')
if self.isDetail():
req.addParam("fq", portal.getQuery())
out = ByteArrayOutputStream()
self.services.getIndexer().search(req, out)
self.__solrData = JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
示例7: __getMetadata
def __getMetadata(self, oid):
req = SearchRequest('id:%s' % oid)
req.setParam("fq", 'item_type:"object"')
# Make sure 'fq' has already been set in the session
##security_roles = self.authentication.get_roles_list();
##security_query = 'security_filter:("' + '" OR "'.join(security_roles) + '")'
##req.addParam("fq", security_query)
out = ByteArrayOutputStream()
self.__indexer.search(req, out)
result = JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
#self.log.info("result={}", result.toString())
return result.getJsonList("response/docs").get(0)
示例8: __isLinked
def __isLinked(self, ids, map):
query = 'package_node_id:("' + '" OR "'.join(ids) + '")'
req = SearchRequest(query)
req.setParam("fq", 'recordtype:"master"')
req.addParam("fq", 'item_type:"object"')
req.setParam("rows", "9999")
out = ByteArrayOutputStream()
self.__indexer.search(req, out)
result = JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
currentList = []
for doc in result.getJsonList("response/docs"):
currentList.extend(doc.getList("package_node_id"))
if type(map).__name__ == "LinkedHashMap":
for author in map.keySet():
authorDocs = map.get(author)
for doc in authorDocs:
if doc.get("id") in currentList:
doc.set("linked", "true")
else:
for author in map.keys():
authorList = map[author]
for count in authorList:
doc = authorList[count]
if doc.get("id") in currentList:
doc.set("linked", "true")
示例9: __getAuthorDetails
def __getAuthorDetails(self, citationIds):
query = " OR id:".join(citationIds)
req = SearchRequest('id:%s' % query)
req.setParam("fq", 'recordtype:"author"')
req.addParam("fq", 'item_type:"object"')
req.setParam("rows", "9999")
# Make sure 'fq' has already been set in the session
##security_roles = self.authentication.get_roles_list();
##security_query = 'security_filter:("' + '" OR "'.join(security_roles) + '")'
##req.addParam("fq", security_query)
out = ByteArrayOutputStream()
self.__indexer.search(req, out)
result = JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
return result.getJsonList("response/docs")
示例10: getAuthorities
def getAuthorities(self):
req = SearchRequest('package_node_id:%s' % self.metadata.get("id"))
req.setParam("fq", 'recordtype:"master"')
req.addParam("fq", 'item_type:"object"')
req.setParam("rows", "9999")
# Make sure 'fq' has already been set in the session
##security_roles = self.authentication.get_roles_list();
##security_query = 'security_filter:("' + '" OR "'.join(security_roles) + '")'
##req.addParam("fq", security_query)
out = ByteArrayOutputStream()
indexer = self.services.getIndexer()
indexer.search(req, out)
result = JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
docs = result.getJsonList("response/docs")
return docs
示例11: getSearchTerms
def getSearchTerms(self):
searchTerms = []
prefix = self.getSuggestionPrefix()
query = '%(prefix)s OR %(prefix)s*' % { "prefix" : prefix }
req = SearchRequest(query)
req.addParam("fq", self.page.getPortal().getQuery())
req.addParam("fq", 'item_type:"object"')
req.setParam("rows", "50")
req.setParam("fl", "score,id,dc_title")
req.setParam("sort", "score desc")
out = ByteArrayOutputStream()
indexer = self.services.getIndexer()
indexer.search(req, out)
result = JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
docs = result.getJsonList("response/docs")
for doc in docs:
dc_title = doc.getList("dc_title").get(0)
searchTerms.append(dc_title)
return '", "'.join(searchTerms)
示例12: __search
def __search(self):
recordsPerPage = self.__portal.recordsPerPage
query = formData.get("query")
if query is None or query == "":
query = "*:*"
req = SearchRequest(query)
req.setParam("facet", "true")
req.setParam("rows", str(recordsPerPage))
req.setParam("facet.field", self.__portal.facetFieldList)
req.setParam("facet.sort", "true")
req.setParam("facet.limit", str(self.__portal.facetCount))
req.setParam("sort", "f_dc_title asc")
# setup facets
action = formData.get("action")
value = formData.get("value")
fq = sessionState.get("fq")
if fq is not None:
self.__pageNum = 1
req.setParam("fq", fq)
if action == "add_fq":
self.__pageNum = 1
name = formData.get("name")
print " * add_fq: %s" % value
req.addParam("fq", URLDecoder.decode(value, "UTF-8"))
elif action == "remove_fq":
self.__pageNum = 1
req.removeParam("fq", URLDecoder.decode(value, "UTF-8"))
elif action == "clear_fq":
self.__pageNum = 1
req.removeParam("fq")
elif action == "select-page":
self.__pageNum = int(value)
req.addParam("fq", 'item_type:"object"')
portalQuery = self.__portal.query
print " * portalQuery=%s" % portalQuery
if portalQuery:
req.addParam("fq", portalQuery)
self.__selected = req.getParams("fq")
sessionState.set("fq", self.__selected)
sessionState.set("pageNum", self.__pageNum)
req.setParam("start", str((self.__pageNum - 1) * recordsPerPage))
print " * search.py:", req.toString(), self.__pageNum
out = ByteArrayOutputStream()
Services.indexer.search(req, out)
self.__result = JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
if self.__result is not None:
self.__paging = Pagination(self.__pageNum,
int(self.__result.get("response/numFound")),
self.__portal.recordsPerPage)
示例13: __search
def __search(self):
recordsPerPage = self.__portal.recordsPerPage
query = None
if query is None or query == "":
query = formData.get("query")
if query is None or query == "":
query = "*:*"
req = SearchRequest(query)
req.setParam("facet", "true")
req.setParam("rows", "1000")
req.setParam("facet.field", self.__portal.facetFieldList)
req.setParam("facet.sort", "true")
req.setParam("facet.limit", str(self.__portal.facetCount))
req.setParam("sort", "f_dc_title asc")
# setup facets
action = formData.get("verb")
value = formData.get("value")
fq = sessionState.get("fq")
if fq is not None:
self.__pageNum = 1
req.setParam("fq", fq)
if action == "add_fq":
self.__pageNum = 1
name = formData.get("name")
print " * add_fq: %s" % value
req.addParam("fq", URLDecoder.decode(value, "UTF-8"))
elif action == "remove_fq":
self.__pageNum = 1
req.removeParam("fq", URLDecoder.decode(value, "UTF-8"))
elif action == "clear_fq":
self.__pageNum = 1
req.removeParam("fq")
elif action == "select-page":
self.__pageNum = int(value)
req.addParam("fq", 'item_type:"object"')
portalQuery = self.__portal.query
print " * portalQuery=%s" % portalQuery
if portalQuery:
req.addParam("fq", portalQuery)
self.__selected = req.getParams("fq")
sessionState.set("fq", self.__selected)
sessionState.set("pageNum", self.__pageNum)
req.setParam("start", str((self.__pageNum - 1) * recordsPerPage))
print " * single.py:", req.toString(), self.__pageNum
out = ByteArrayOutputStream()
Services.indexer.search(req, out)
self.__result = JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
if self.__result is not None:
self.__paging = Pagination(
self.__pageNum, int(self.__result.get("response/numFound")), self.__portal.recordsPerPage
)
print " * single.py: updating manifest..."
portal = self.getPortal()
manifest = portal.getJsonMap("manifest")
# add new items from search
for doc in self.__result.getList("response/docs"):
hashId = md5.new(doc.get("id")).hexdigest()
node = portal.get("manifest//node-%s" % hashId)
if node is None:
portal.set("manifest/node-%s/title" % hashId, doc.get("dc_title").get(0))
portal.set("manifest/node-%s/id" % hashId, doc.get("id"))
# remove manifest items missing from search result
# print manifest
for key in manifest.keySet():
item = manifest.get(key)
id = item.get("id")
doc = self.__result.getList('response/docs[@id="%s"]' % id)
if len(doc) == 0:
portal.removePath("manifest//%s" % key)
Services.getPortalManager().save(portal)
示例14: __getSolrData
def __getSolrData(self):
prefix = self.getSearchTerms()
if prefix != "":
query = 'dc_title:"%(prefix)s" OR dc_title:"%(prefix)s*"' % { "prefix" : prefix }
else:
query = "*:*"
portal = self.services.portalManager.get(self.portalId)
if portal.searchQuery != "*:*":
query = query + " AND " + portal.searchQuery
req = SearchRequest(query)
req.setParam("fq", 'item_type:"object"')
if portal.query:
req.addParam("fq", portal.query)
req.setParam("fl", "score")
req.setParam("sort", "score desc, f_dc_title asc")
req.setParam("start", self.getStartIndex())
req.setParam("rows", self.getItemsPerPage())
try:
out = ByteArrayOutputStream()
indexer = self.services.getIndexer()
indexer.search(req, out)
return JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
except Exception, e:
self.log.error("Failed to lookup '{}': {}", prefix, str(e))
示例15: __getSolrData
def __getSolrData(self):
prefix = self.getSearchTerms()
if prefix:
query = '%(prefix)s OR %(prefix)s*' % { "prefix" : prefix }
else:
query = "*:*"
req = SearchRequest(query)
req.addParam("fq", 'item_type:"object"')
req.setParam("fl", "score")
req.setParam("sort", "score desc")
req.setParam("start", self.getStartIndex())
req.setParam("rows", self.getItemsPerPage())
try:
out = ByteArrayOutputStream()
indexer = self.services.getIndexer()
indexer.search(req, out)
return JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
except Exception, e:
self.log.error("Failed to lookup '{}': {}", prefix, str(e))