All Downloads are FREE. Search and download functionalities are using the official Maven repository.

portal.default.redbox.scripts.actions.keywords.py Maven / Gradle / Ivy

There is a newer version: 1.10.2
Show newest version
from com.googlecode.fascinator.api.indexer import SearchRequest
from com.googlecode.fascinator.common.solr import SolrResult
from java.io import ByteArrayInputStream, ByteArrayOutputStream
from java.util import TreeSet

class KeywordsData:
    def __activate__(self, context):
        formData = context["formData"]
        services = context["Services"]
        response = context["response"]
        query = "keywords:[* TO *]"
        q = formData.get("q")
        if q:
            query += " AND keywords:(%(q)s OR %(q)s*)" % { "q": q }
        req = SearchRequest(query)
        req.setParam("fl", "keywords")
        req.setParam("rows", "50")
        keywords = TreeSet()
        indexer = services.getIndexer()
        out = ByteArrayOutputStream()
        indexer.search(req, out)
        result = SolrResult(ByteArrayInputStream(out.toByteArray()))
        for doc in result.getResults():
            for keyword in doc.getList("keywords"):
                if keyword.startswith(q):
                    keywords.add(keyword)
        writer = response.getPrintWriter("text/plain; charset=UTF-8")
        writer.println("\n".join(keywords))
        writer.close()




© 2015 - 2024 Weber Informatics LLC | Privacy Policy