Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/yaz
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 15 Jun 2015 13:00:15 +0000 (15:00 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 15 Jun 2015 13:00:15 +0000 (15:00 +0200)
IDMETA
NEWS
src/cclfind.c
src/log.c
src/record_conv.c
test/test_ccl.c
util/bib1

diff --git a/IDMETA b/IDMETA
index 483dd60..da63ff7 100755 (executable)
--- a/IDMETA
+++ b/IDMETA
@@ -1,4 +1,4 @@
 DEBIAN_DIST="jessie wheezy squeeze"
 UBUNTU_DIST="vivid utopic trusty precise"
 CENTOS_DIST="centos5 centos6"
-VERSION=5.13.0
+VERSION=5.14.1
diff --git a/NEWS b/NEWS
index 431b56d..18e1789 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,20 @@
+--- 5.14.1 2015/06/11
+
+Make yaz_log_reopen async-signal YAZ-845
+Fixes potential dead-lock issue with YAZ_DAEMON_LOG_REOPEN flags for
+daemon API.
+
+--- 5.14.0 2015/06/08
+
+CCL: new feature s=spl (split-list) that splits terms in a search into
+sub-phrases of all sizes (from 1 up to the number of terms) with order
+preserved. For 3 terms the CCL search
+ a b c
+is turned into PQF:
+ @or @or @or @and @and a b c @and "a b" c @and a "b c" "a b c"
+
+Solr: don't set defType=lucene in URLs if extraArgs already defines it.
+
 --- 5.13.0 2015/05/29
 
 Add lock/unlock for YAZ log writes YAZ-843
index beec793..0ef140b 100644 (file)
@@ -113,6 +113,23 @@ struct ccl_rpn_node *ccl_rpn_node_create(enum ccl_rpn_kind kind)
     return p;
 }
 
+static struct ccl_rpn_node *ccl_rpn_node_mkbool(struct ccl_rpn_node *l,
+                                                struct ccl_rpn_node *r,
+                                                enum ccl_rpn_kind op)
+{
+    if (l && r)
+    {
+        struct ccl_rpn_node *tmp = ccl_rpn_node_create(op);
+        tmp->u.p[0] = l;
+        tmp->u.p[1] = r;
+        tmp->u.p[2] = 0;
+        return tmp;
+    }
+    else if (r)
+        return r;
+    return l;
+}
+
 static struct ccl_rpn_node *ccl_rpn_dup(struct ccl_rpn_node *rpn)
 {
     struct ccl_rpn_node *n;
@@ -439,7 +456,7 @@ static struct ccl_rpn_node *ccl_term_one_use(CCL_parser cclp,
     {
         struct ccl_rpn_attr *attr;
         for (attr = ccl_qual_get_attr(qa[i]); attr; attr = attr->next)
-            if (attr->type != 1 || attr == attr_use)
+            if (attr->type != 1 || !attr_use || attr == attr_use)
             {
                 switch (attr->kind)
                 {
@@ -582,6 +599,40 @@ static struct ccl_rpn_node *ccl_term_one_use(CCL_parser cclp,
     return p;
 }
 
+static struct ccl_rpn_node *ccl_term_multi_use(CCL_parser cclp,
+                                               struct ccl_token *lookahead0,
+                                               ccl_qualifier_t *qa,
+                                               size_t no,
+                                               int is_phrase,
+                                               int auto_group)
+{
+    struct ccl_rpn_node *p = 0;
+    int i;
+    for (i = 0; qa && qa[i]; i++)
+    {
+        struct ccl_rpn_attr *attr;
+        for (attr = ccl_qual_get_attr(qa[i]); attr; attr = attr->next)
+            if (attr->type == 1 && i == 0)
+            {
+                struct ccl_rpn_node *tmp2;
+                tmp2 = ccl_term_one_use(cclp, lookahead0,
+                                        attr, qa, no,
+                                        is_phrase, auto_group);
+                if (!tmp2)
+                {
+                    ccl_rpn_delete(p);
+                    return 0;
+                }
+                p = ccl_rpn_node_mkbool(p, tmp2, CCL_RPN_OR);
+            }
+    }
+    if (!p)
+        p = ccl_term_one_use(cclp, lookahead0,
+                             0 /* attr: no use */, qa, no,
+                             is_phrase, auto_group);
+    return p;
+}
+
 static struct ccl_rpn_node *split_recur(CCL_parser cclp, ccl_qualifier_t *qa,
                                         struct ccl_rpn_node *parent,
                                         struct ccl_token **ar, size_t sz)
@@ -592,13 +643,15 @@ static struct ccl_rpn_node *split_recur(CCL_parser cclp, ccl_qualifier_t *qa,
     for (l = 1; l <= sz; l++)
     {
         struct ccl_rpn_node *p1;
-        struct ccl_rpn_node *p2 = ccl_term_one_use(cclp, ar[0],
-                                                   /* attr_use */0,
-                                                   qa, l,
-                                                   l > 1,
-                                                   /* auto_group */0);
+        struct ccl_rpn_node *p2 = ccl_term_multi_use(cclp, ar[0],
+                                                     qa, l,
+                                                     l > 1,
+                                                     /* auto_group */0);
         if (!p2)
+        {
+            ccl_rpn_delete(p_top);
             return 0;
+        }
         if (parent)
         {
             struct ccl_rpn_node *tmp = ccl_rpn_node_create(CCL_RPN_AND);
@@ -610,15 +663,13 @@ static struct ccl_rpn_node *split_recur(CCL_parser cclp, ccl_qualifier_t *qa,
             p1 = split_recur(cclp, qa, p2, ar + l, sz - l);
         else
             p1 = p2;
-        if (p_top)
+        if (!p1)
         {
-            struct ccl_rpn_node *tmp = ccl_rpn_node_create(CCL_RPN_OR);
-            tmp->u.p[0] = p_top;
-            tmp->u.p[1] = p1;
-            p_top = tmp;
+            ccl_rpn_delete(p2);
+            ccl_rpn_delete(p_top);
+            return 0;
         }
-        else
-            p_top = p1;
+        p_top = ccl_rpn_node_mkbool(p_top, p1, CCL_RPN_OR);
     }
     assert(p_top);
     return p_top;
@@ -716,63 +767,13 @@ static struct ccl_rpn_node *search_term_x(CCL_parser cclp,
 
         if (no == 0)
             break;      /* no more terms . stop . */
-
-        /* go through all attributes and add them to the attribute list */
-        for (i = 0; qa && qa[i]; i++)
-        {
-            struct ccl_rpn_attr *attr;
-
-            for (attr = ccl_qual_get_attr(qa[i]); attr; attr = attr->next)
-                if (attr->type == 1)
-                {
-                    struct ccl_rpn_node *tmp2;
-                    tmp2 = ccl_term_one_use(cclp, cclp->look_token,
-                                            attr, qa, no,
-                                            is_phrase, auto_group);
-                    if (!tmp2)
-                    {
-                        ccl_rpn_delete(p);
-                        return 0;
-                    }
-                    if (!p)
-                        p = tmp2;
-                    else
-                    {
-                        struct ccl_rpn_node *tmp1;
-                        tmp1 = ccl_rpn_node_create(CCL_RPN_OR);
-                        tmp1->u.p[0] = p;
-                        tmp1->u.p[1] = tmp2;
-                        p = tmp1;
-                    }
-                }
-        }
-        if (!p)
-            p = ccl_term_one_use(cclp, cclp->look_token,
-                                 0 /* attr: no use */, qa, no,
-                                 is_phrase, auto_group);
+        p = ccl_term_multi_use(cclp, cclp->look_token, qa, no,
+                               is_phrase, auto_group);
         for (i = 0; i < no; i++)
             ADVANCE;
         if (!p)
             return 0;
-        /* make the top node point to us.. */
-        if (p_top)
-        {
-            struct ccl_rpn_node *tmp;
-
-            if (or_list)
-                tmp = ccl_rpn_node_create(CCL_RPN_OR);
-            else if (and_list)
-                tmp = ccl_rpn_node_create(CCL_RPN_AND);
-            else
-                tmp = ccl_rpn_node_create(CCL_RPN_AND);
-            tmp->u.p[0] = p_top;
-            tmp->u.p[1] = p;
-
-            p_top = tmp;
-        }
-        else
-            p_top = p;
-
+        p_top = ccl_rpn_node_mkbool(p_top, p, or_list ? CCL_RPN_OR : CCL_RPN_AND);
         if (!multi)
             break;
     }
@@ -1060,16 +1061,7 @@ static struct ccl_rpn_node *qualifier_list(CCL_parser cclp,
                     xfree(ap);
                     return 0;
                 }
-                if (node)
-                {
-                    struct ccl_rpn_node *node_this =
-                        ccl_rpn_node_create(CCL_RPN_OR);
-                    node_this->u.p[0] = node;
-                    node_this->u.p[1] = node_sub;
-                    node = node_this;
-                }
-                else
-                    node = node_sub;
+                node = ccl_rpn_node_mkbool(node, node_sub, CCL_RPN_OR);
                 seq++;
             }
             if (seq == 0)
@@ -1132,16 +1124,7 @@ static struct ccl_rpn_node *qualifier_list(CCL_parser cclp,
                 ccl_rpn_delete(node);
                 break;
             }
-            if (node)
-            {
-                struct ccl_rpn_node *node_this =
-                    ccl_rpn_node_create(CCL_RPN_OR);
-                node_this->u.p[0] = node;
-                node_this->u.p[1] = node_sub;
-                node = node_this;
-            }
-            else
-                node = node_sub;
+            node = ccl_rpn_node_mkbool(node, node_sub, CCL_RPN_OR);
             seq++;
         }
     }
@@ -1274,17 +1257,7 @@ static struct ccl_rpn_node *search_elements(CCL_parser cclp,
                 ccl_rpn_delete(node);
                 return 0;
             }
-            if (node)
-            {
-                struct ccl_rpn_node *node_this =
-                    ccl_rpn_node_create(CCL_RPN_OR);
-                node_this->u.p[0] = node;
-                node_this->u.p[1] = node_sub;
-                node_this->u.p[2] = 0;
-                node = node_this;
-            }
-            else
-                node = node_sub;
+            node = ccl_rpn_node_mkbool(node, node_sub, CCL_RPN_OR);
         }
         if (!node)
             node = search_terms(cclp, 0);
@@ -1300,7 +1273,7 @@ static struct ccl_rpn_node *search_elements(CCL_parser cclp,
  */
 static struct ccl_rpn_node *find_spec(CCL_parser cclp, ccl_qualifier_t *qa)
 {
-    struct ccl_rpn_node *p1, *p2, *pn;
+    struct ccl_rpn_node *p1, *p2;
     if (!(p1 = search_elements(cclp, qa)))
         return NULL;
     while (1)
@@ -1315,11 +1288,7 @@ static struct ccl_rpn_node *find_spec(CCL_parser cclp, ccl_qualifier_t *qa)
                 ccl_rpn_delete(p1);
                 return NULL;
             }
-            pn = ccl_rpn_node_create(CCL_RPN_AND);
-            pn->u.p[0] = p1;
-            pn->u.p[1] = p2;
-            pn->u.p[2] = 0;
-            p1 = pn;
+            p1 = ccl_rpn_node_mkbool(p1, p2, CCL_RPN_AND);
             continue;
         case CCL_TOK_OR:
             ADVANCE;
@@ -1329,11 +1298,7 @@ static struct ccl_rpn_node *find_spec(CCL_parser cclp, ccl_qualifier_t *qa)
                 ccl_rpn_delete(p1);
                 return NULL;
             }
-            pn = ccl_rpn_node_create(CCL_RPN_OR);
-            pn->u.p[0] = p1;
-            pn->u.p[1] = p2;
-            pn->u.p[2] = 0;
-            p1 = pn;
+            p1 = ccl_rpn_node_mkbool(p1, p2, CCL_RPN_OR);
             continue;
         case CCL_TOK_NOT:
             ADVANCE;
@@ -1343,11 +1308,7 @@ static struct ccl_rpn_node *find_spec(CCL_parser cclp, ccl_qualifier_t *qa)
                 ccl_rpn_delete(p1);
                 return NULL;
             }
-            pn = ccl_rpn_node_create(CCL_RPN_NOT);
-            pn->u.p[0] = p1;
-            pn->u.p[1] = p2;
-            pn->u.p[2] = 0;
-            p1 = pn;
+            p1 = ccl_rpn_node_mkbool(p1, p2, CCL_RPN_NOT);
             continue;
         }
         break;
index 8bc5ad0..d005378 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -103,8 +103,12 @@ static struct {
 
 static unsigned int next_log_bit = YLOG_LAST_BIT<<1; /* first dynamic bit */
 
+static int yaz_log_reopen_flag = 0;
+
 static YAZ_MUTEX log_mutex = 0;
 
+static void yaz_log_open(void);
+
 void yaz_log_lock(void)
 {
     yaz_mutex_enter(log_mutex);
@@ -169,7 +173,7 @@ void yaz_log_init_file(const char *fname)
         yaz_log_info.type = use_none;  /* NULL name; use no file at all */
         yaz_log_info.l_fname[0] = '\0';
     }
-    yaz_log_reopen();
+    yaz_log_open();
 }
 
 static void rotate_log(const char *cur_fname)
@@ -216,7 +220,7 @@ void yaz_log_init_level(int level)
     if ( (l_level & YLOG_FLUSH) != (level & YLOG_FLUSH) )
     {
         l_level = level;
-        yaz_log_reopen(); /* make sure we set buffering right */
+        yaz_log_open(); /* make sure we set buffering right */
     }
     else
         l_level = level;
@@ -306,6 +310,11 @@ static void yaz_log_open_check(struct tm *tm, int force, const char *filemode)
     if (yaz_log_info.type != use_file)
         return;
 
+    if (yaz_log_reopen_flag)
+    {
+        force = 1;
+        yaz_log_reopen_flag = 0;
+    }
     if (*yaz_log_info.l_fname)
     {
         strftime(new_filename, sizeof(new_filename)-1, yaz_log_info.l_fname,
@@ -368,9 +377,13 @@ static void yaz_log_do_reopen(const char *filemode)
     yaz_log_unlock();
 }
 
-
 void yaz_log_reopen()
 {
+    yaz_log_reopen_flag = 1;
+}
+
+static void yaz_log_open()
+{
     yaz_log_do_reopen("a");
 }
 
index b117340..02eebb6 100644 (file)
@@ -190,8 +190,7 @@ static void *construct_xslt(const xmlNode *ptr,
         info->xsl_parms[2 * no_parms + 1] = qvalue;
         no_parms++;
     }
-
-    info->xsl_parms[2 * no_parms] = '\0';
+    info->xsl_parms[2 * no_parms] = 0;
 
     if (!stylesheet)
     {
index 853a05a..5fdb954 100644 (file)
@@ -87,7 +87,8 @@ void tst1(int pass)
         ccl_qual_fitem(bibset, "r=o",         "x");
         ccl_qual_fitem(bibset, "dc.title", "title");
         ccl_qual_fitem(bibset, "s=ag", "ag");
-        ccl_qual_fitem(bibset, "s=sl", "splitlist");
+        ccl_qual_fitem(bibset, "s=sl u=2", "splitlist");
+        ccl_qual_fitem(bibset, "s=sl u=2 u=3", "s2");
         break;
     case 1:
         strcpy(tstline, "ti u=4    s=pw t=l,r");
@@ -120,7 +121,10 @@ void tst1(int pass)
         strcpy(tstline, "ag s=ag");
         ccl_qual_line(bibset, tstline);
 
-        strcpy(tstline, "splitlist s=sl");
+        strcpy(tstline, "splitlist s=sl u=2");
+        ccl_qual_line(bibset, tstline);
+
+        strcpy(tstline, "s2 s=sl u=2 u=3");
         ccl_qual_line(bibset, tstline);
         break;
     case 2:
@@ -135,7 +139,8 @@ void tst1(int pass)
                      "title dc.title\n"
                      "comb term dc.title\n"
                      "ag s=ag\n"
-                     "splitlist s=sl\n"
+                     "splitlist s=sl u=2\n"
+                     "s2 s=sl u=2 u=3\n"
             );
         break;
     case 3:
@@ -184,6 +189,12 @@ void tst1(int pass)
                 " </qual>\n"
                 " <qual name=\"splitlist\">\n"
                 "   <attr type=\"s\" value=\"sl\"/>\n"
+                "   <attr type=\"u\" value=\"2\"/>\n"
+                " </qual>\n"
+                " <qual name=\"s2\">\n"
+                "   <attr type=\"s\" value=\"sl\"/>\n"
+                "   <attr type=\"u\" value=\"2\"/>\n"
+                "   <attr type=\"u\" value=\"3\"/>\n"
                 " </qual>\n"
                 "</cclmap>\n";
 
@@ -271,8 +282,7 @@ void tst1(int pass)
                             "@prox 0 1 0 2 k 2 "
                             "@attr 4=2 @attr 1=1016 a "
                             "@or @attr 4=2 @attr 1=1016 b "
-                            "@or @attr 4=2 @attr 1=/my/title c "
-                            "@attr 4=2 @attr 1=1016 c "
+                            "@attr 4=2 @attr 1=/my/title c "
     ));
 
     YAZ_CHECK(tst_ccl_query(bibset, "(a b) % (c)",
@@ -437,14 +447,26 @@ void tst1(int pass)
     YAZ_CHECK(tst_ccl_query(bibset, "ag=\"a b c\" \"d e\"",
                             "@and @attr 4=1 \"a b c\" @attr 4=1 \"d e\" "));
 
-    YAZ_CHECK(tst_ccl_query(bibset, "splitlist=a", "a "));
+    YAZ_CHECK(tst_ccl_query(bibset, "splitlist=a", "@attr 1=2 a "));
     YAZ_CHECK(tst_ccl_query(bibset, "splitlist=a b", "@or "
-                            "@and a b \"a b\" "));
+                            "@and @attr 1=2 a @attr 1=2 b @attr 1=2 \"a b\" "));
     YAZ_CHECK(tst_ccl_query(bibset, "splitlist=a b c", "@or @or @or "
-                            "@and @and a b c "
-                            "@and a \"b c\" "
-                            "@and \"a b\" c "
-                            "\"a b c\" "));
+                            "@and @and @attr 1=2 a @attr 1=2 b @attr 1=2 c "
+                            "@and @attr 1=2 a @attr 1=2 \"b c\" "
+                            "@and @attr 1=2 \"a b\" @attr 1=2 c "
+                            "@attr 1=2 \"a b c\" "));
+
+    YAZ_CHECK(tst_ccl_query(bibset, "s2=a", "@or @attr 1=2 a @attr 1=3 a "));
+
+    YAZ_CHECK(tst_ccl_query(bibset, "s2=a b", "@or "
+                            "@and " "@or @attr 1=2 a @attr 1=3 a "
+                            "@or @attr 1=2 b @attr 1=3 b "
+                            "@or @attr 1=2 \"a b\" @attr 1=3 \"a b\" "));
+
+    YAZ_CHECK(tst_ccl_query(bibset, "s2=a? b", 0));
+    YAZ_CHECK(tst_ccl_query(bibset, "s2=a b?", 0));
+    YAZ_CHECK(tst_ccl_query(bibset, "s2=a b? c", 0));
+
     ccl_qual_rm(&bibset);
 }
 
index 0de6ab8..819cfd2 100644 (file)
--- a/util/bib1
+++ b/util/bib1
@@ -5,4 +5,4 @@ date     1=31 r=r,omiteq
 x        1=x r=o
 title    dc.title
 comb     term dc.title
-splitlist s=sl,pw
+splitlist s=sl u=1016 u=31