Allow facet size to be specified.
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 5 Dec 2007 09:55:10 +0000 (09:55 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 5 Dec 2007 09:55:10 +0000 (09:55 +0000)
A facet size may be specified by appending colon and number
after index type, e.g. zebra::facet::title:w:10 .

index/retrieve.c
test/api/safari1.c

index ea16718..ff3bced 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: retrieve.c,v 1.81 2007-12-05 09:29:52 adam Exp $
+/* $Id: retrieve.c,v 1.82 2007-12-05 09:55:57 adam Exp $
    Copyright (C) 1995-2007
    Index Data ApS
 
    Copyright (C) 1995-2007
    Index Data ApS
 
@@ -80,6 +80,7 @@ static int zebra_create_record_stream(ZebraHandle zh,
 struct index_spec {
     const char *index_name;
     const char *index_type;
 struct index_spec {
     const char *index_name;
     const char *index_type;
+    const char *extra;
     struct index_spec *next;
 };
 
     struct index_spec *next;
 };
 
@@ -103,6 +104,7 @@ struct index_spec *parse_index_spec(const char *elem, NMEM nmem,
             struct index_spec *spec = nmem_malloc(nmem, sizeof(*spec));
             spec->index_type = 0;
             spec->next = 0;
             struct index_spec *spec = nmem_malloc(nmem, sizeof(*spec));
             spec->index_type = 0;
             spec->next = 0;
+            spec->extra = 0;
 
             if (!first)
                 first = spec;
 
             if (!first)
                 first = spec;
@@ -119,10 +121,19 @@ struct index_spec *parse_index_spec(const char *elem, NMEM nmem,
                 cp++;
                 cp0 = cp;
                 
                 cp++;
                 cp0 = cp;
                 
-                while (*cp != '\0' && *cp != ',')
+                while (*cp != '\0' && *cp != ',' && *cp != ':')
                     cp++;
                 spec->index_type = nmem_strdupn(nmem, cp0, cp - cp0);
             }
                     cp++;
                 spec->index_type = nmem_strdupn(nmem, cp0, cp - cp0);
             }
+            if (*cp == ':') /* extra arguments */
+            {
+                cp++;
+                cp0 = cp;
+                
+                while (*cp != '\0' && *cp != ',' && *cp != ':')
+                    cp++;
+                spec->extra = nmem_strdupn(nmem, cp0, cp - cp0);
+            }
             if (*cp != ',')
                 break;
         }
             if (*cp != ',')
                 break;
         }
@@ -710,7 +721,6 @@ static ZEBRA_RES facet_fetch(ZebraHandle zh, const char *setname,
     zint *pos_array;
     int i;
     int num_recs = 10; /* number of records to analyze */
     zint *pos_array;
     int i;
     int num_recs = 10; /* number of records to analyze */
-    int no_collect_terms = 20; /* number of term candidates */
     ZebraMetaRecord *poset;
     ZEBRA_RES ret = ZEBRA_OK;
     int *ord_array;
     ZebraMetaRecord *poset;
     ZEBRA_RES ret = ZEBRA_OK;
     int *ord_array;
@@ -843,9 +853,14 @@ static ZEBRA_RES facet_fetch(ZebraHandle zh, const char *setname,
         {
             int j;
             NMEM nmem = nmem_create();
         {
             int j;
             NMEM nmem = nmem_create();
-            struct term_collect *col = term_collect_create(map_array[i], 
-                                                           no_collect_terms,
-                                                           nmem);
+            struct term_collect *col;
+            int no_collect_terms = 20;
+
+            if (spec->extra)
+                no_collect_terms = atoi(spec->extra);
+            if (no_collect_terms < 1)
+                no_collect_terms = 1;
+            col = term_collect_create(map_array[i], no_collect_terms, nmem);
             term_collect_freq(zh, col, no_collect_terms, ord_array[i],
                               resultSetRef(zh, setname));
             
             term_collect_freq(zh, col, no_collect_terms, ord_array[i],
                               resultSetRef(zh, setname));
             
index 4d2337b..3ae9231 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: safari1.c,v 1.22 2007-12-05 09:29:53 adam Exp $
+/* $Id: safari1.c,v 1.23 2007-12-05 09:55:10 adam Exp $
    Copyright (C) 1995-2007
    Index Data ApS
 
    Copyright (C) 1995-2007
    Index Data ApS
 
@@ -96,15 +96,12 @@ static void tst(int argc, char **argv)
     ids[2] = 24340;
     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 3, ids));
 
     ids[2] = 24340;
     YAZ_CHECK(tl_meta_query(zh, "@attr 4=3 @attr 1=any mand", 3, ids));
 
-#if 1
     YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "R", yaz_oid_recsyn_sutrs,
                                   myrec[0]), ZEBRA_OK);
     YAZ_CHECK_EQ(tl_fetch_compare(zh, 2, "R", yaz_oid_recsyn_sutrs,
                                   myrec[2]), ZEBRA_OK);
     YAZ_CHECK_EQ(tl_fetch_compare(zh, 3, "R", yaz_oid_recsyn_sutrs,
                                   myrec[4]), ZEBRA_OK);
     YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "R", yaz_oid_recsyn_sutrs,
                                   myrec[0]), ZEBRA_OK);
     YAZ_CHECK_EQ(tl_fetch_compare(zh, 2, "R", yaz_oid_recsyn_sutrs,
                                   myrec[2]), ZEBRA_OK);
     YAZ_CHECK_EQ(tl_fetch_compare(zh, 3, "R", yaz_oid_recsyn_sutrs,
                                   myrec[4]), ZEBRA_OK);
-#endif
-#if 1
     YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::any:0", 
                                   yaz_oid_recsyn_xml,
                                   "<facets>\n"
     YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::any:0", 
                                   yaz_oid_recsyn_xml,
                                   "<facets>\n"
@@ -116,7 +113,15 @@ static void tst(int argc, char **argv)
                                   "    <term coccur=\"1\" occur=\"1\">old</term>\n"
                                   "  </facet>\n"
                                   "</facets>\n"), ZEBRA_OK);
                                   "    <term coccur=\"1\" occur=\"1\">old</term>\n"
                                   "  </facet>\n"
                                   "</facets>\n"), ZEBRA_OK);
-#endif
+    YAZ_CHECK_EQ(tl_fetch_compare(zh, 1, "zebra::facet::any:0:2", 
+                                  yaz_oid_recsyn_xml,
+                                  "<facets>\n"
+                                  "  <facet type=\"0\" index=\"any\">\n"
+                                  "    <term coccur=\"4\" occur=\"3\">mand</term>\n"
+                                  "    <term coccur=\"4\" occur=\"3\">the</term>\n"
+                                  "  </facet>\n"
+                                  "</facets>\n"), ZEBRA_OK);
+
     /* limit to 125061 */
     limits[0] = 125061;
     limits[1] = 0;
     /* limit to 125061 */
     limits[0] = 125061;
     limits[1] = 0;