- /* 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);
+ /* Create a new search hash for fast identification of results */
+ searchhash = hash_new(sizeof(int));
+ for(n = 0; n < nvec; ++n) {
+ int *const ip = xmalloc(sizeof (int *));
+ static const int minus_1 = -1;
+ *ip = n;
+ /* The filename itself lives in the hash */
+ hash_add(searchhash, vec[n], ip, HASH_INSERT_OR_REPLACE);
+ /* So do its ancestor directories */
+ for(s = vec[n] + 1; *s; ++s) {
+ if(*s == '/') {
+ *s = 0;
+ hash_add(searchhash, vec[n], &minus_1, HASH_INSERT_OR_REPLACE);
+ *s = '/';
+ }