Class ClickHandler
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidhandle(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Processes one/api/v2/clickrequest.
-
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/clickrequest.- Parameters:
req- the incoming HTTP requestres- the HTTP response to write to- Throws:
IOException- if writing the envelope fails
-