Thanks for replying. Actually I used history.search() before history.getVisits, similarly as example here. In fact my approach may be similar as yours in Historia, especially the part of “query all HistoryItem using a keyword, and then fetch all the VisitItem associated with each HistoryItem”.
The main problem in my case is, in addition to querying the VisitItems associated with the keyword, I need to get all the referrer visits and all of their descendants in order to display the browsing history in “threads”, based on the clickstream. As I didn’t see any API to query VisitItem by VisitIDs, or query VisitItem by their referrer’s visitID, I actually carried out a generic search (with empty keyword) to pull all the HistoryItems within a period (like within a month), and then construct the threads by walking through all of them and checking referringVisitId. With my own browsing history, I had 4k+ HistoryItems within last month, and fetching VisitItems for all of them will take 5+ seconds.