Merge branch 'master' into sru_2_0
authorAdam Dickmeiss <adam@indexdata.dk>
Sun, 22 Sep 2013 16:18:28 +0000 (18:18 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Sun, 22 Sep 2013 16:18:28 +0000 (18:18 +0200)
Conflicts:
src/rpn2solr.c

1  2 
src/rpn2solr.c

diff --cc src/rpn2solr.c
@@@ -215,151 -211,68 +211,67 @@@ static Odr_int get_truncation(Z_Attribu
  
  #define SOLR_SPECIAL "+-&|!(){}[]^\"~*?:\\"
  
- static int rpn2solr_simple(solr_transform_t ct,
-                            Z_Operand *q, WRBUF w, struct solr_attr *solr_attr)
+ static int emit_term(solr_transform_t ct, WRBUF w, Z_Term *term, Odr_int trunc)
  {
-     int ret = 0;
-     if (q->which != Z_Operand_APT)
+     size_t lterm = 0;
+     const char *sterm = 0;
+     switch (term->which)
      {
-         ret = -1;
-         solr_transform_set_error(ct, YAZ_BIB1_RESULT_SET_UNSUPP_AS_A_SEARCH_TERM, 0);
+     case Z_Term_general:
+         lterm = term->u.general->len;
+         sterm = (const char *) term->u.general->buf;
+         break;
+     case Z_Term_numeric:
+         wrbuf_printf(w, ODR_INT_PRINTF, *term->u.numeric);
+         break;
+     case Z_Term_characterString:
+         sterm = term->u.characterString;
+         lterm = strlen(sterm);
+         break;
+     default:
+         solr_transform_set_error(ct, YAZ_BIB1_TERM_TYPE_UNSUPP, 0);
+         return -1;
      }
-     else
 -
+     if (sterm)
      {
-         Z_AttributesPlusTerm *apt = q->u.attributesPlusTerm;
-         Z_Term *term = apt->term;
-         const char *sterm = 0;
-         size_t lterm = 0;
-         Odr_int trunc = get_truncation(apt);
-         wrbuf_rewind(w);
-         ret = rpn2solr_attr(ct, apt->attributes, w, solr_attr);
-         if (trunc == 0 || trunc == 1 || trunc == 100 || trunc == 104)
-             ;
-         else
-         {
-             solr_transform_set_error(ct, YAZ_BIB1_UNSUPP_TRUNCATION_ATTRIBUTE, 0);
-             return -1;
-         }
-         switch (term->which)
+         size_t i;
+         int must_quote = 0;
+         for (i = 0 ; i < lterm; i++)
+             if (sterm[i] == ' ')
+                 must_quote = 1;
+         if (must_quote)
+             wrbuf_puts(w, "\"");
+         for (i = 0 ; i < lterm; i++)
          {
-         case Z_Term_general:
-             lterm = term->u.general->len;
-             sterm = (const char *) term->u.general->buf;
-             break;
-         case Z_Term_numeric:
-             wrbuf_printf(w, ODR_INT_PRINTF, *term->u.numeric);
-             break;
-         case Z_Term_characterString:
-             sterm = term->u.characterString;
-             lterm = strlen(sterm);
-             break;
-         default:
-             ret = -1;
-             solr_transform_set_error(ct, YAZ_BIB1_TERM_TYPE_UNSUPP, 0);
-         }
-         if (sterm)
-         {
-             size_t i;
-             int must_quote = 0;
-             for (i = 0 ; i < lterm; i++)
-                 if (sterm[i] == ' ')
-                     must_quote = 1;
-             if (must_quote)
-                 wrbuf_puts(w, "\"");
-             for (i = 0 ; i < lterm; i++)
+             if (sterm[i] == '\\' && i < lterm - 1)
              {
-                 if (sterm[i] == '\\' && i < lterm - 1)
-                 {
-                     i++;
-                     if (strchr(SOLR_SPECIAL, sterm[i]))
-                         wrbuf_putc(w, '\\');
-                     wrbuf_putc(w, sterm[i]);
-                 }
-                 else if (sterm[i] == '?' && trunc == 104)
-                 {
-                     wrbuf_putc(w, '*');
-                 }
-                 else if (sterm[i] == '#' && trunc == 104)
-                 {
-                     wrbuf_putc(w, '?');
-                 }
-                 else if (strchr(SOLR_SPECIAL, sterm[i]))
-                 {
+                 i++;
+                 if (strchr(SOLR_SPECIAL, sterm[i]))
                      wrbuf_putc(w, '\\');
-                     wrbuf_putc(w, sterm[i]);
-                 }
-                 else
-                     wrbuf_putc(w, sterm[i]);
+                 wrbuf_putc(w, sterm[i]);
              }
-             if (trunc == 1)
-                 wrbuf_puts(w, "*");
-             if (must_quote)
-                 wrbuf_puts(w, "\"");
-         }
-         if (ret == 0) { 
-             solr_attr->term = wrbuf_cstr(w);
+             else if (sterm[i] == '?' && trunc == 104)
+             {
+                 wrbuf_putc(w, '*');
+             }
+             else if (sterm[i] == '#' && trunc == 104)
+             {
+                 wrbuf_putc(w, '?');
+             }
+             else if (strchr(SOLR_SPECIAL, sterm[i]))
+             {
+                 wrbuf_putc(w, '\\');
+                 wrbuf_putc(w, sterm[i]);
+             }
+             else
+                 wrbuf_putc(w, sterm[i]);
          }
-         
-     }
-     return ret;
- };
- static int solr_write_range(void (*pr)(const char *buf, void *client_data),
-                             void *client_data,
-                             struct solr_attr *solr_attr_left, 
-                             struct solr_attr *solr_attr_right)
- {
-     pr(solr_attr_left->index, client_data);
-     pr(":", client_data);
-     pr(solr_attr_left->begin, client_data);
-     pr(solr_attr_left->term,  client_data);
-     pr(" TO ", client_data);
-     pr(solr_attr_right->term,  client_data);
-     pr(solr_attr_right->close, client_data);
-     return 0;
- }; 
- static int solr_write_structure(void (*pr)(const char *buf, void *client_data),
-                             void *client_data,
-                             struct solr_attr *solr_attr)
- {
-     if (solr_attr->index) {
-         pr(solr_attr->index, client_data);
-         pr(":", client_data);
-     }
-     if (solr_attr->is_range) {
-         pr(solr_attr->begin, client_data);
-         pr(solr_attr->term,  client_data);
-         pr(solr_attr->close, client_data);
+         if (trunc == 1)
+             wrbuf_puts(w, "*");
+         if (must_quote)
+             wrbuf_puts(w, "\"");
      }
-     else if (solr_attr->term) 
-         pr(solr_attr->term,  client_data);
-     return 0;
- }; 
- static int solr_write_and_or_range(void (*pr)(const char *buf, void *client_data),
-                              void *client_data,
-                              struct solr_attr *solr_attr_left, 
-                              struct solr_attr *solr_attr_right)
- {
-     if (solr_attr_left->is_range && 
-         solr_attr_right->is_range && 
-         !strcmp(solr_attr_left->index, solr_attr_right->index)) 
-     {
-         if (solr_attr_left->is_range > 3 && solr_attr_right->is_range < 3)
-             return solr_write_range(pr, client_data, solr_attr_left, solr_attr_right); 
-         else if (solr_attr_left->is_range < 3 && solr_attr_right->is_range > 3)
-             return solr_write_range(pr, client_data, solr_attr_right, solr_attr_left); 
-     }
-     solr_write_structure(pr, client_data, solr_attr_left);
-     pr(" AND ", client_data);
-     solr_write_structure(pr, client_data, solr_attr_right);
      return 0;
  }