Loosen the match when nothing has been clicked
A shopper typed "linen shirt navy", then "navy linen shirt", then "blue linen shirt", and clicked nothing on any of the three lists. The ranker scores each query as it arrives, and what the shopper did with the two before it arrives after the third list is on the screen. Three searches with no click say the catalog's words are not this shopper's words. The next list should match more loosely, or show the nearest categories, while the shopper is still at the search box.
searches_session- Searches run this visit
result_clicks_session- Results opened from a search this visit
last_queries_session- The queries typed this visit
Switches to a looser match and shows the nearest categories above the list once a visit reaches three searches with no result opened, and passes the earlier queries in as synonyms for this one.
from snowplow_signals import (
Attribute, Event, EventProperty, StreamAttributeGroup, domain_sessionid,
)
search = Event(name="search", vendor="com.example", version="1-0-0")
search_result_click = Event(name="search_result_click", vendor="com.example", version="1-0-0")
searches_session = Attribute(
name="searches_session",
type="int32",
events=[search],
aggregation="counter",
default_value=0,
)
result_clicks_session = Attribute(
name="result_clicks_session",
type="int32",
events=[search_result_click],
aggregation="counter",
default_value=0,
)
last_queries_session = Attribute(
name="last_queries_session",
type="string_list",
events=[search],
aggregation="unique_list",
property=EventProperty(vendor="com.example", name="search", major_version=1, path="query"),
)
# Keyed on the visit, so the counts start from zero each time the shopper comes back.
shop_search_dead_end = StreamAttributeGroup(
name="shop_search_dead_end",
version=1,
attribute_key=domain_sessionid,
owner="you@example.com",
attributes=[searches_session, result_clicks_session, last_queries_session],
)// In the code that sends a search request to your search engine
const shopper = await signals.getServiceAttributes({
name: "shop_search_dead_end",
attribute_key: "domain_sessionid",
identifier: sessionId,
});
// { searches_session: 3, result_clicks_session: 0, last_queries_session: ["linen shirt navy", "navy linen shirt", "blue linen shirt"] }
if (shopper.searches_session >= 3 && shopper.result_clicks_session === 0) {
search.query({
q: query,
synonyms: shopper.last_queries_session,
match: "loose",
showCategories: true,
});
}