- /* We will replace the choose tree with a tree structured view of search
- * results. First we must disabled the choose tree's widgets. */
- delete_widgets(root);
- /* Put the tracks into order, grouped by directory. They'll probably
- * come back this way anyway in current versions of the server, but it's
- * cheap not to rely on it (compared with the massive effort we expend
- * later on) */
- qsort(vec, nvec, sizeof(char *), compare_track_for_qsort);
- searchresults = vec;
- nsearchresults = nvec;
- cn = root = newnode(0/*parent*/, "", "Search results", "",
- CN_EXPANDABLE|CN_EXPANDED, fill_search_node);
- /* Construct the initial tree. We do this in a single pass and expand
- * everything, so you can actually see your search results. */
- for(n = 0; n < nsearchresults; ++n) {
- /* Firstly we might need to go up a few directories to each an ancestor
- * of this track */
- while(!is_descendant(cn->path, searchresults[n])) {
- /* We report the update on each node the last time we see it (With
- * display=0, the main purpose of this is to get the order of the
- * children right.) */
- updated_node(cn, 0);
- cn = cn->parent;
- }
- /* Secondly we might need to insert some new directories */
- while(!is_child(cn->path, searchresults[n])) {
- /* Figure out the subdirectory */
- dir = xstrndup(searchresults[n],
- strchr(searchresults[n] + strlen(cn->path) + 1,
- '/') - searchresults[n]);
- cn = newnode(cn, dir,
- trackname_transform("dir", dir, "display"),
- trackname_transform("dir", dir, "sort"),
- CN_EXPANDABLE|CN_EXPANDED, fill_search_node);
- }
- /* Finally we can insert the track as a child of the current
- * directory */
- newnode(cn, searchresults[n],
- trackname_transform("track", searchresults[n], "display"),
- trackname_transform("track", searchresults[n], "sort"),
- 0/*flags*/, 0/*fill*/);
- }
- while(cn) {
- /* Update all the nodes back up to the root */
- updated_node(cn, 0);
- cn = cn->parent;
- }
- /* Now it's worth displaying the tree */
- redisplay_tree();
- } else if(root != realroot) {
- delete_widgets(root);
- root = realroot;
- redisplay_tree();
+ /* Create a new search hash for fast identification of results */
+ searchhash = hash_new(1);
+ for(n = 0; n < nvec; ++n)
+ hash_add(searchhash, vec[n], "", HASH_INSERT_OR_REPLACE);
+ /* We don't yet know that the results are visible */
+ nsearchvisible = 0;
+ /* Initiate expansion */
+ expand_from(root);
+ } else {
+ searchhash = 0; /* for the gc */