The wikibase.entityselector.search hook does not handle pagination at all, which makes it difficult to use for improving search results.
The hook is only fired after the initial search, not when clicking "more", so the following only logs data once for a given search, no matter how many times you click "more":
mw.hook("wikibase.entityselector.search").add(function (data, addPromise) { console.log(data); });
Suggestions added via the promise do not get paginated, so the following shows between 20 and 27 results (the 20 results added via the promise plus the original results):
var suggestions = [ { id: "Q1" },{ id: "Q2" },{ id: "Q3" },{ id: "Q4" }, { id: "Q5" },{ id: "Q6" },{ id: "Q7" },{ id: "Q8" }, { id: "Q9" },{ id: "Q10" },{ id: "Q11" },{ id: "Q12" }, { id: "Q13" },{ id: "Q14" },{ id: "Q15" },{ id: "Q16" }, { id: "Q17" },{ id: "Q18" },{ id: "Q19" },{ id: "Q20" } ]; mw.hook("wikibase.entityselector.search").add(function (data, addPromise) { addPromise(suggestions); });
Suggestions added via the promise do not override results added after clicking "more", so the following does not override "River (given name)" in the second set of results when searching for "river":
mw.hook("wikibase.entityselector.search").add(function (data, addPromise) { addPromise([{ id: "Q66103377", label: "custom result" }]); });