From 9dbf16ff99472e07182dab1c7cf8796a4d357b0c Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 25 Apr 2007 09:38:21 +0000 Subject: [PATCH] Allow safari filter to specify index type. --- index/safari.c | 16 ++++++++++------ test/api/safari1.c | 5 ++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/index/safari.c b/index/safari.c index 4af73f8..c4398dc 100644 --- a/index/safari.c +++ b/index/safari.c @@ -1,4 +1,4 @@ -/* $Id: safari.c,v 1.8 2007-04-25 08:18:01 adam Exp $ +/* $Id: safari.c,v 1.9 2007-04-25 09:38:21 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -130,18 +130,22 @@ static int filter_extract(void *clientData, struct recExtractCtrl *p) return RECCTRL_EXTRACT_EOF; sscanf(line, "%255s", p->match_criteria); - recWord.index_type = '0'; while (fi_gets(fi, line, sizeof(line)-1)) { int nor = 0; char field[40]; - char *cp; + const char *cp = line; #if 0 yaz_log(YLOG_LOG, "safari line: %s", line); #endif + if (*cp >= '0' && *cp <= '9') + recWord.index_type = '0'; /* the default is 0 (raw) */ + else + recWord.index_type = *cp++; /* type given */ + if (tinfo->segments) { - if (sscanf(line, ZINT_FORMAT " " ZINT_FORMAT " " ZINT_FORMAT + if (sscanf(cp, ZINT_FORMAT " " ZINT_FORMAT " " ZINT_FORMAT ZINT_FORMAT " %39s %n", &recWord.record_id, &recWord.section_id, &recWord.segment, @@ -154,7 +158,7 @@ static int filter_extract(void *clientData, struct recExtractCtrl *p) } else { - if (sscanf(line, ZINT_FORMAT " " ZINT_FORMAT " " ZINT_FORMAT " %39s %n", + if (sscanf(cp, ZINT_FORMAT " " ZINT_FORMAT " " ZINT_FORMAT " %39s %n", &recWord.record_id, &recWord.section_id, &recWord.seqno, field, &nor) < 4) { @@ -162,7 +166,7 @@ static int filter_extract(void *clientData, struct recExtractCtrl *p) return RECCTRL_EXTRACT_ERROR_GENERIC; } } - for (cp = line + nor; *cp == ' '; cp++) + for (cp = cp + nor; *cp == ' '; cp++) ; recWord.index_name = field; recWord.term_buf = cp; diff --git a/test/api/safari1.c b/test/api/safari1.c index c30ad57..8f811eb 100644 --- a/test/api/safari1.c +++ b/test/api/safari1.c @@ -1,4 +1,4 @@ -/* $Id: safari1.c,v 1.15 2007-01-15 15:10:19 adam Exp $ +/* $Id: safari1.c,v 1.16 2007-04-25 09:38:21 adam Exp $ Copyright (C) 1995-2007 Index Data ApS @@ -46,6 +46,7 @@ const char *myrec[] = "00024339 125061 0 1 any the\n" "00024339 125061 0 2 any gamle\n" "00024339 125061 0 3 any mand\n" + "w 00024339 125661 0 4 any Hello\n" , "1001\n" /* separate record */ "00024340 125062 0 1 any the\n" @@ -86,6 +87,8 @@ static void tst(int argc, char **argv) YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and the gamle", 1)); YAZ_CHECK(tl_query(zh, "@attr 4=3 @attr 1=any @and the of", 0)); + YAZ_CHECK(tl_query(zh, "@attr 1=any hello", 1)); + /* verify that we get these records exactly */ ids[0] = 24338; ids[1] = 24339; -- 1.7.10.4