Interface ResultHitWriter

  • All Known Implementing Classes:
    FullNodeHitWriter, SelectivePropHitWriter, SimpleHitWriter

    public interface ResultHitWriter
    ResultHitWriter writes a search result Hit into a JSONWriter. This is used in the standard servlet for the query builder to allow different output renderings. The appropriate ResultHitWriter is selected by passing the desired name in the query using p.hitwriter=NAME as request parameter.

    Implementations of this interface must be defined as an OSGi component factory. The name of the factory must be the fully qualified name of this interface plus "/" and a distinct short name of the renderer (that will be used in request parameters to select it, NAME above). For example for a ResultHitWriter under the name "damasset", the SCR annotation would look like this:

     @Component(factory="com.day.cq.search.result.ResultHitWriter/damasset")
     
    Since:
    5.2
    • Method Detail

      • write

        void write​(Hit hit,
                   JSONWriter writer,
                   Query query)
            throws RepositoryException,
                   JSONException
        Writes a given Hit into the JSONWriter. This will be called for each hit of the result page. The surrounding json structure is an array and each entry should be a simple object. The caller will have invoked the writer.object() already and will call writer.endObject() directly after this method returns.
        Parameters:
        hit - the result hit to render
        writer - to output json
        query - the original query; can be used to access custom parameters set in the predicate root group ( query.getPredicates().get("param", "default"))
        Throws:
        RepositoryException - in case access on the hit failed
        JSONException - in case there is a problem with writing to the jsonwriter