Skip to content

Commit

Permalink
Introduce UBI to the SolrJ client.
Browse files Browse the repository at this point in the history
I suspect lots of places for fixing.  Like pulling out field names into a UBIParams.java file.   May want to name space ubi query params under "ubi."..  what about in JSON query?
  • Loading branch information
epugh committed Dec 9, 2024
1 parent 56ec0d0 commit dc378fe
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
52 changes: 52 additions & 0 deletions solr/solrj/src/java/org/apache/solr/client/solrj/SolrQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,58 @@ public SolrQuery setHighlight(boolean b) {
return this;
}

/**
* Enable User Behavior Insights tracking for this query.
*
* @param b
*/
public SolrQuery setUBITracking(boolean b) {
if (b) {
this.set("ubi", true);
} else {
// makes me wonder if this should be all under ubi.* namespace.
// so ubi.application, ubi.query_id....
this.remove("ubi");
this.remove("application");
this.remove("query_id");
this.remove("client_id");
this.remove("user_query");
// this.remove("object_id_fields");
this.remove("query_attributes");
}
return this;
}

/** Determine status of User Behavior Insights tracking for this query. */
public boolean getUBITracking() {
return this.getBool("ubi", false);
}

public SolrQuery setApplication(String application) {
this.set("application", application);
return this;
}

public SolrQuery setQueryId(String queryId) {
this.set("query_id", queryId);
return this;
}

public SolrQuery setClientId(String clientId) {
this.set("client_id", clientId);
return this;
}

public SolrQuery setUserQuery(String userQuery) {
this.set("user_query", userQuery);
return this;
}

/**
* public SolrQuery setQueryAttributes(Map queryAttributes) { this.set("query_attributes",
* queryAttributes); return this; }
*/

/**
* Add field for MoreLikeThis. Automatically enables MoreLikeThis.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,17 @@ public void testMoreLikeThis() {
assertEquals(15, solrQuery.setMoreLikeThisMaxQueryTerms(15).getMoreLikeThisMaxQueryTerms());
assertEquals(16, solrQuery.setMoreLikeThisCount(16).getMoreLikeThisCount());
}

public void testUserBehaviorInsights() {
SolrQuery solrQuery = new SolrQuery();
solrQuery.setUBITracking(true);
assertTrue(solrQuery.getUBITracking());

assertNull(solrQuery.get("query_id"));
solrQuery.setQueryId("12345");
assertEquals("12345", solrQuery.get("query_id"));

// need to figure out how to test query_attributes

}
}

0 comments on commit dc378fe

Please sign in to comment.