Class ClickHandler

java.lang.Object
org.codelibs.fess.api.v2.handlers.ClickHandler

public class ClickHandler extends Object
Handles POST /api/v2/click.

Records a click on a search result. The request body is a small JSON document with doc_id, query_id, rank (the 1-based result position) and an optional rt (epoch millis of the originating search). The handler validates doc_id against a conservative [A-Za-z0-9_-]+ regex (no dots / slashes — open-redirect and path-traversal mitigation), looks the document up via SearchHelper, then appends a ClickLog via SearchLogHelper.

Behaviour matches v1's GoAction click-logging block but without the redirect — v2 clients handle navigation themselves. When the search log feature is disabled the handler succeeds with logged:false so the client doesn't need to branch on configuration. When the user has no session (anonymous), the handler also returns logged:false because a click log without a session id is meaningless.

Order of checks (m-15): HTTP method → feature flag → session check (anonymous short-circuits before body parse) → body parse → doc_id validation. This avoids wasting CPU on JSON parsing for anonymous callers or when the search-log feature is disabled.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    handle(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res)
    Processes one /api/v2/click request.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ClickHandler

      public ClickHandler()
      Default constructor. The handler is stateless and intended to be instantiated once by the API manager and shared across concurrent requests.
  • Method Details

    • handle

      public void handle(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws IOException
      Processes one /api/v2/click request.
      Parameters:
      req - the incoming HTTP request
      res - the HTTP response to write to
      Throws:
      IOException - if writing the envelope fails