chiark / gitweb /
More sensible ordering of search results in web interface.
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 29 Nov 2009 15:55:32 +0000 (15:55 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 29 Nov 2009 15:55:32 +0000 (15:55 +0000)
Fixes issue #46.

CHANGES.html
cgi/macros-disorder.c
lib/trackname.h
lib/trackorder.c
lib/tracksort.c

index 81e2a86db14649619a680a50c3184a9017be2234..50503430a9af92a368bc0f89a7903ee0138658fd 100644 (file)
@@ -213,6 +213,11 @@ span.command {
           <td>disobedience doesn't configure its back end</td>
         </tr>
 
+        <tr>
+          <td><a href="http://code.google.com/p/disorder/issues/detail?id=46">#46</a></d>
+          <td>Sort search results in web interface</td>
+        </tr>
+
         <tr>
           <td><a href="http://code.google.com/p/disorder/issues/detail?id=48">#48</a></d>
           <td>build-time dependency on <tt>oggdec</tt> removed</td>
index 30614c1a26d2fecca465457e52e053169d88d466..29835bbc849c196fcea60124fc55b10969cf6bde 100644 (file)
@@ -859,24 +859,36 @@ static int exp__files_dirs(int nargs,
   /* Get the list */
   if(fn(dcgi_client, dir, re, &tracks, &ntracks))
     return 0;
-  /* Sort it.  NB trackname_transform() does not go to the server. */
-  tsd = tracksort_init(ntracks, tracks, type);
-  /* Expand the subsiduary templates.  We chuck in @sort and @display because
-   * it is particularly easy to do so. */
-  for(n = 0; n < ntracks; ++n)
-    if((rc = mx_expand(mx_rewritel(m,
-                                   "index", make_index(n),
-                                   "parity", n % 2 ? "odd" : "even",
-                                   "track", tsd[n].track,
-                                   "first", n == 0 ? "true" : "false",
-                                   "last", n + 1 == ntracks ? "false" : "true",
-                                   "sort", tsd[n].sort,
-                                   "display", tsd[n].display,
-                                   (char *)0),
-                       output, u)))
-      return rc;
+  if(type) {
+    /* Sort it.  NB trackname_transform() does not go to the server. */
+    tsd = tracksort_init(ntracks, tracks, type);
+    /* Expand the subsiduary templates.  We chuck in @sort and @display because
+     * it is particularly easy to do so. */
+    for(n = 0; n < ntracks; ++n)
+      if((rc = mx_expand(mx_rewritel(m,
+                                     "index", make_index(n),
+                                     "parity", n % 2 ? "odd" : "even",
+                                     "track", tsd[n].track,
+                                     "first", n == 0 ? "true" : "false",
+                                     "last", n + 1 == ntracks ? "false" : "true",
+                                     "sort", tsd[n].sort,
+                                     "display", tsd[n].display,
+                                     (char *)0),
+                         output, u)))
+        return rc;
+  } else {
+    for(n = 0; n < ntracks; ++n)
+      if((rc = mx_expand(mx_rewritel(m,
+                                     "index", make_index(n),
+                                     "parity", n % 2 ? "odd" : "even",
+                                     "track", tracks[n],
+                                     "first", n == 0 ? "true" : "false",
+                                     "last", n + 1 == ntracks ? "false" : "true",
+                                     (char *)0),
+                         output, u)))
+        return rc;
+  }
   return 0;
-
 }
 
 /*$ @tracks{DIR}{RE}{TEMPLATE}
@@ -936,14 +948,12 @@ static int exp__search_shim(disorder_client *c, const char *terms,
  * - @parity: "even" or "odd" alternately
  * - @first: "true" on the first directory and "false" otherwise
  * - @last: "true" on the last directory and "false" otherwise
- * - @sort: the sort key for this track
- * - @display: the UNQUOTED display string for this track
  */
 static int exp_search(int nargs,
                       const struct mx_node **args,
                       struct sink *output,
                       void *u) {
-  return exp__files_dirs(nargs, args, output, u, "track", exp__search_shim);
+  return exp__files_dirs(nargs, args, output, u, NULL, exp__search_shim);
 }
 
 /*$ @label{NAME}
index 63b881bb836c523ad962b81f26118e4d47129c9f..56f933ee95682d21911e856f2d3255b7018585b7 100644 (file)
@@ -51,7 +51,14 @@ int compare_path_raw(const unsigned char *ap, size_t an,
 /* Comparison function for path names that groups all entries in a directory
  * together */
 
-/* Convenient wrapper for compare_path_raw */
+/** @brief Compare two paths
+ * @param ap First path
+ * @param bp Second path
+ * @return -ve, 0 or +ve for ap <, = or > bp
+ *
+ * Sorts files within a directory together.
+ * A wrapper around compare_path_raw().
+ */
 static inline int compare_path(const char *ap, const char *bp) {
   return compare_path_raw((const unsigned char *)ap, strlen(ap),
                          (const unsigned char *)bp, strlen(bp));
index d0ae4486f597927de06222858fa65863ce959a0d..94d2bd5e9cde7dece533e64728a8cc83c5f8fbad 100644 (file)
 #include "log.h"
 #include "unicode.h"
 
+/** @brief Compare two tracks
+ * @param sa First sort key
+ * @param sb Second sort key
+ * @param da First display string
+ * @param db Second display string
+ * @param ta First raw track
+ * @param tb Second raw track
+ * @return -ve, 0 or +ve for a <, = or > b
+ *
+ * Tries the following comparisons until a difference is found:
+ * - case-independent comparison of sort keys
+ * - case-dependent comparison of sort keys
+ * - case-independent comparison of display strings
+ * - case-dependent comparison of display strings
+ * - case-dependent comparison of paths (see compare_path())
+ */
 int compare_tracks(const char *sa, const char *sb,
                   const char *da, const char *db,
                   const char *ta, const char *tb) {
@@ -43,6 +59,17 @@ int compare_tracks(const char *sa, const char *sb,
   return compare_path(ta, tb);
 }
 
+/** @brief Compare two paths
+ * @param ap First path
+ * @param an Length of @p ap
+ * @param bp Second path
+ * @param bn Length @p bp
+ * @return -ve, 0 or +ve for ap <, = or > bp
+ *
+ * Sorts files within a directory together.
+ *
+ * See also compare_path().
+ */
 int compare_path_raw(const unsigned char *ap, size_t an,
                     const unsigned char *bp, size_t bn) {
   /* Don't change this function!  The database sort order depends on it */
index 2f81739098583802ff2f382ebfa6e57470c64531..b1fcc3af87d01f0134613e4fa2b19455d7a2cac9 100644 (file)
@@ -32,6 +32,16 @@ static int tracksort_compare(const void *a, const void *b) {
                        ea->track, eb->track);
 }
 
+/** @brief Sort tracks
+ * @param ntracks Number of tracks to sort
+ * @param tracks List of tracks
+ * @param type Comparison type
+ * @return Sorted track data
+ *
+ * Tracks are compared using compare_tracks(), with the sort key and display
+ * string set according to @p type, which should be "track" if the tracks are
+ * really tracks and "dir" if they are directories.
+ */
 struct tracksort_data *tracksort_init(int ntracks,
                                       char **tracks,
                                       const char *type) {