Definitions in zebramap.h are private. ZebraMaps no longer used in
[idzebra-moved-to-github.git] / index / extract.c
index 1a5eada..4b76e03 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: extract.c,v 1.222 2006-06-22 09:48:08 adam Exp $
+/* $Id: extract.c,v 1.226 2006-08-15 14:28:33 adam Exp $
    Copyright (C) 1995-2006
    Index Data ApS
 
@@ -15,9 +15,9 @@ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
-along with Zebra; see the file LICENSE.zebra.  If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
 */
 
 #include <stdio.h>
@@ -106,13 +106,14 @@ static void logRecord (ZebraHandle zh)
     }
 }
 
-static void extract_add_index_string (RecWord *p, const char *str, int length);
+static void extract_add_index_string (RecWord *p, 
+                                      zinfo_index_category_t cat,
+                                      const char *str, int length);
 
 static void extract_set_store_data_prepare(struct recExtractCtrl *p);
 
 static void extract_init (struct recExtractCtrl *p, RecWord *w)
 {
-    w->zebra_maps = p->zebra_maps;
     w->seqno = 1;
     w->index_name = "any";
     w->index_type = 'w';
@@ -128,16 +129,17 @@ static void searchRecordKey(ZebraHandle zh,
 {
     int i;
     int ch = -1;
+    zinfo_index_category_t cat = zinfo_index_category_index;
 
     for (i = 0; i<ws_length; i++)
         ws[i] = NULL;
 
     if (ch < 0)
-        ch = zebraExplain_lookup_attr_str(zh->reg->zei, '0', index_name);
+        ch = zebraExplain_lookup_attr_str(zh->reg->zei, cat, '0', index_name);
     if (ch < 0)
-        ch = zebraExplain_lookup_attr_str(zh->reg->zei, 'p', index_name);
+        ch = zebraExplain_lookup_attr_str(zh->reg->zei, cat, 'p', index_name);
     if (ch < 0)
-        ch = zebraExplain_lookup_attr_str(zh->reg->zei, 'w', index_name);
+        ch = zebraExplain_lookup_attr_str(zh->reg->zei, cat, 'w', index_name);
 
     if (ch < 0)
        return ;
@@ -392,7 +394,6 @@ static void init_extractCtrl(ZebraHandle zh, struct recExtractCtrl *ctrl)
        else
            ctrl->seqno[i] = 0;
     }
-    ctrl->zebra_maps = zh->reg->zebra_maps;
     ctrl->flagShowRecords = !zh->m_flag_rw;
 }
 
@@ -400,10 +401,11 @@ static void all_matches_add(struct recExtractCtrl *ctrl)
 {
     RecWord word;
     extract_init(ctrl, &word);
-    word.index_name = "allrecords";
+    word.index_name = "_ALLRECORDS";
     word.index_type = 'w';
     word.seqno = 1;
-    extract_add_index_string (&word, "", 0);
+    extract_add_index_string (&word, zinfo_index_category_alwaysmatches,
+                              "", 0);
 }
 
 static ZEBRA_RES file_extract_record(ZebraHandle zh,
@@ -1622,10 +1624,10 @@ void print_rec_keys(ZebraHandle zh, zebra_rec_keys_t reckeys)
     }
 }
 
-static void extract_add_index_string(RecWord *p, const char *str, int length)
+static void extract_add_index_string(RecWord *p, zinfo_index_category_t cat,
+                                     const char *str, int length)
 {
     struct it_key key;
-
     ZebraHandle zh = p->extractCtrl->handle;
     ZebraExplainInfo zei = zh->reg->zei;
     int ch;
@@ -1633,9 +1635,9 @@ static void extract_add_index_string(RecWord *p, const char *str, int length)
     if (!p->index_name)
         return;
 
-    ch = zebraExplain_lookup_attr_str(zei, p->index_type, p->index_name);
+    ch = zebraExplain_lookup_attr_str(zei, cat, p->index_type, p->index_name);
     if (ch < 0)
-        ch = zebraExplain_add_attr_str(zei, p->index_type, p->index_name);
+        ch = zebraExplain_add_attr_str(zei, cat, p->index_type, p->index_name);
 
     key.len = 4;
     key.mem[0] = ch;
@@ -1666,17 +1668,18 @@ static void extract_add_index_string(RecWord *p, const char *str, int length)
 static void extract_add_sort_string(RecWord *p, const char *str, int length)
 {
     struct it_key key;
-
     ZebraHandle zh = p->extractCtrl->handle;
     ZebraExplainInfo zei = zh->reg->zei;
     int ch;
+    zinfo_index_category_t cat = zinfo_index_category_sort;
 
     if (!p->index_name)
         return;
 
-    ch = zebraExplain_lookup_attr_str(zei, p->index_type, p->index_name);
+    ch = zebraExplain_lookup_attr_str(zei, cat, p->index_type, p->index_name);
     if (ch < 0)
-        ch = zebraExplain_add_attr_str(zei, p->index_type, p->index_name);
+        ch = zebraExplain_add_attr_str(zei, cat, p->index_type, p->index_name);
     key.len = 4;
     key.mem[0] = ch;
     key.mem[1] = p->record_id;
@@ -1704,31 +1707,35 @@ static void extract_add_sort_string(RecWord *p, const char *str, int length)
 
 static void extract_add_string (RecWord *p, const char *string, int length)
 {
+    ZebraHandle zh = p->extractCtrl->handle;
     assert (length > 0);
-    if (zebra_maps_is_sort (p->zebra_maps, p->index_type))
+    if (zebra_maps_is_sort (zh->reg->zebra_maps, p->index_type))
        extract_add_sort_string (p, string, length);
     else
     {
-       extract_add_index_string(p, string, length);
-        if (zebra_maps_is_alwaysmatches(p->zebra_maps, p->index_type))
+       extract_add_index_string(p, zinfo_index_category_index,
+                                 string, length);
+        if (zebra_maps_is_alwaysmatches(zh->reg->zebra_maps, p->index_type))
         {
             RecWord word;
             memcpy(&word, p, sizeof(word));
 
             word.seqno = 1;
-            extract_add_index_string (&word, "", 0);
+            extract_add_index_string(
+                &word, zinfo_index_category_alwaysmatches, "", 0);
         }
     }
 }
 
 static void extract_add_incomplete_field (RecWord *p)
 {
+    ZebraHandle zh = p->extractCtrl->handle;
     const char *b = p->term_buf;
     int remain = p->term_len;
     const char **map = 0;
     
     if (remain > 0)
-       map = zebra_maps_input(p->zebra_maps, p->index_type, &b, remain, 0);
+       map = zebra_maps_input(zh->reg->zebra_maps, p->index_type, &b, remain, 0);
 
     while (map)
     {
@@ -1740,7 +1747,7 @@ static void extract_add_incomplete_field (RecWord *p)
        {
            remain = p->term_len - (b - p->term_buf);
            if (remain > 0)
-               map = zebra_maps_input(p->zebra_maps, p->index_type, &b,
+               map = zebra_maps_input(zh->reg->zebra_maps, p->index_type, &b,
                                       remain, 0);
            else
                map = 0;
@@ -1756,7 +1763,7 @@ static void extract_add_incomplete_field (RecWord *p)
                buf[i++] = *(cp++);
            remain = p->term_len - (b - p->term_buf);
            if (remain > 0)
-               map = zebra_maps_input(p->zebra_maps, p->index_type, &b, remain, 0);
+               map = zebra_maps_input(zh->reg->zebra_maps, p->index_type, &b, remain, 0);
            else
                map = 0;
        }
@@ -1769,13 +1776,14 @@ static void extract_add_incomplete_field (RecWord *p)
 
 static void extract_add_complete_field (RecWord *p)
 {
+    ZebraHandle zh = p->extractCtrl->handle;
     const char *b = p->term_buf;
     char buf[IT_MAX_WORD+1];
     const char **map = 0;
     int i = 0, remain = p->term_len;
 
     if (remain > 0)
-       map = zebra_maps_input (p->zebra_maps, p->index_type, &b, remain, 1);
+       map = zebra_maps_input (zh->reg->zebra_maps, p->index_type, &b, remain, 1);
 
     while (remain > 0 && i < IT_MAX_WORD)
     {
@@ -1786,7 +1794,7 @@ static void extract_add_complete_field (RecWord *p)
            if (remain > 0)
            {
                int first = i ? 0 : 1;  /* first position */
-               map = zebra_maps_input(p->zebra_maps, p->index_type, &b, remain, first);
+               map = zebra_maps_input(zh->reg->zebra_maps, p->index_type, &b, remain, first);
            }
            else
                map = 0;
@@ -1814,7 +1822,7 @@ static void extract_add_complete_field (RecWord *p)
            remain = p->term_len  - (b - p->term_buf);
            if (remain > 0)
            {
-               map = zebra_maps_input (p->zebra_maps, p->index_type, &b,
+               map = zebra_maps_input (zh->reg->zebra_maps, p->index_type, &b,
                                        remain, 0);
            }
            else
@@ -1828,19 +1836,20 @@ static void extract_add_complete_field (RecWord *p)
 
 static void extract_token_add(RecWord *p)
 {
+    ZebraHandle zh = p->extractCtrl->handle;
     WRBUF wrbuf;
     if (log_level)
         yaz_log(log_level, "extract_token_add "
                 "type=%c index=%s seqno=" ZINT_FORMAT " s=%.*s",
                 p->index_type, p->index_name, 
                 p->seqno, p->term_len, p->term_buf);
-    if ((wrbuf = zebra_replace(p->zebra_maps, p->index_type, 0,
+    if ((wrbuf = zebra_replace(zh->reg->zebra_maps, p->index_type, 0,
                               p->term_buf, p->term_len)))
     {
        p->term_buf = wrbuf_buf(wrbuf);
        p->term_len = wrbuf_len(wrbuf);
     }
-    if (zebra_maps_is_complete (p->zebra_maps, p->index_type))
+    if (zebra_maps_is_complete (zh->reg->zebra_maps, p->index_type))
        extract_add_complete_field (p);
     else
        extract_add_incomplete_field(p);