Changeset 2096

Show
Ignore:
Timestamp:
03/21/08 14:27:54 (2 months ago)
Author:
karpet
Message:

add prop and meta id auto-init; fix debug scheme to use bitwise comparison

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libswish3/trunk/libswish3-config.in

    r1923 r2096  
    6868 
    6969    --cflags) 
    70         echo @CFLAGS@ -I${includedir} @Z_CFLAGS@ 
     70        echo @CFLAGS@ -I${includedir} 
    7171        ;; 
    7272 
     
    7676 
    7777    --libs) 
    78         echo -L${libdir} -lswish3 @Z_LIBS@ @LIBS@ 
     78        echo -L${libdir} -lswish3 @LIBS@ 
    7979        ;; 
    8080 
  • libswish3/trunk/src/libswish3/analyzer.c

    r2041 r2096  
    6969        SWISH_WARN("analyzer ref_cnt != 0: %d\n", a->ref_cnt); 
    7070    } 
    71     if (SWISH_DEBUG >= SWISH_DEBUG_MEMORY) { 
     71    if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) { 
    7272        SWISH_DEBUG_MSG("free analyzer"); 
    7373    } 
  • libswish3/trunk/src/libswish3/config.c

    r2046 r2096  
    2424 */ 
    2525 
    26 #include <libxml/xmlstring.h> 
    2726#include <sys/param.h> 
    2827#include <stdio.h> 
     
    4645free_string(xmlChar *payload, xmlChar * key) 
    4746{ 
    48     if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
     47    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) 
    4948        SWISH_DEBUG_MSG("   freeing config %s => %s", key, payload); 
    5049 
     
    5554free_props(swish_Property *prop, xmlChar *propname) 
    5655{ 
    57     if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) { 
     56    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
    5857        SWISH_DEBUG_MSG("   freeing config->prop %s", propname); 
    5958        swish_debug_property((swish_Property*)prop); 
     
    6867free_metas(swish_MetaName *meta, xmlChar *metaname) 
    6968{ 
    70     if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) { 
     69    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
    7170        SWISH_DEBUG_MSG("   freeing config->meta %s", metaname); 
    7271        swish_debug_metaname((swish_MetaName*)meta); 
     
    8180swish_free_config(swish_Config * config) 
    8281{ 
    83     if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
     82    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) 
    8483    { 
    8584        SWISH_DEBUG_MSG("freeing config"); 
     
    139138    swish_MetaName *tmpmeta; 
    140139 
    141     if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
     140    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) 
    142141        SWISH_DEBUG_MSG("setting default config"); 
    143142         
     
    159158            ); 
    160159             
    161     /* increm ref counts after they've been stashed. a little awkward, but saves var names... */ 
     160    /* alter swish_MetaName objects after they've been stashed.  
     161       a little awkward, but saves var names.  
     162    */ 
    162163    tmpmeta = xmlHashLookup(config->metanames, (xmlChar*)SWISH_DEFAULT_METANAME); 
    163164    tmpmeta->ref_cnt++; 
     165    tmpmeta->id = SWISH_META_DEFAULT_ID; 
    164166    tmpmeta = xmlHashLookup(config->metanames, (xmlChar*)SWISH_TITLE_METANAME); 
    165167    tmpmeta->ref_cnt++; 
     168    tmpmeta->id = SWISH_META_TITLE_ID; 
    166169     
    167170 
     
    215218    tmpprop = xmlHashLookup(config->properties, (xmlChar*)SWISH_PROP_DESCRIPTION); 
    216219    tmpprop->ref_cnt++; 
     220    tmpprop->id = SWISH_PROP_DESCRIPTION_ID; 
    217221    tmpprop = xmlHashLookup(config->properties, (xmlChar*)SWISH_PROP_TITLE); 
    218222    tmpprop->ref_cnt++; 
     223    tmpprop->id = SWISH_PROP_TITLE_ID; 
    219224     
    220225 
     
    233238    config->flags->tokenize = 1; 
    234239     
    235     if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) { 
     240    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) { 
    236241        SWISH_DEBUG_MSG("config_set_default done"); 
    237242        swish_debug_config(config); 
     
    245250 
    246251    config = swish_parse_config(conf, config); 
    247     if (SWISH_DEBUG >= SWISH_DEBUG_CONFIG) 
     252    if (SWISH_DEBUG & SWISH_DEBUG_CONFIG) 
    248253        swish_debug_config(config); 
    249254 
  • libswish3/trunk/src/libswish3/hash.c

    r2090 r2096  
    2121/* wrappers to common functions in libxml2 hash */ 
    2222 
    23 #include <libxml/hash.h> 
    2423#include <stdlib.h> 
    2524 
  • libswish3/trunk/src/libswish3/header.c

    r2046 r2096  
    2020/* read/write the swish.xml header file */ 
    2121 
    22 #include <libxml/xmlstring.h> 
    2322#include <libxml/xmlreader.h> 
    2423#include "libswish3.h" 
     
    3736    swish_Config    *config; 
    3837    boolean         is_valid; 
     38    unsigned int    prop_id; 
     39    unsigned int    meta_id; 
    3940} headmaker; 
    4041 
     
    9293                newmeta = swish_init_metaname( newname ); 
    9394                newmeta->ref_cnt++; 
     95                newmeta->id = h->meta_id++; 
    9496                swish_hash_add( h->config->metanames, newmeta->name, newmeta ); 
    9597            } 
     
    123125        meta->bias = (boolean)strtol((char*)attr_val, (char**)NULL, 10); 
    124126    } 
     127    else if (xmlStrEqual(attr, (xmlChar*)"id")) { 
     128        meta->id   = (int)strtol((char*)attr_val, (char**)NULL, 10); 
     129    } 
    125130    else if (xmlStrEqual(attr, (xmlChar*)"alias")) { 
    126131        do_metaname_aliases( (xmlChar*)attr_val, h, meta ); 
     
    167172                ); 
    168173        } 
    169      
    170     } 
     174             
     175    } 
     176     
     177    // must have an id 
     178    if (!meta->id) { 
     179        meta->id = h->meta_id++; 
     180    } 
     181 
    171182         
    172183    if (!swish_hash_exists( h->config->metanames, meta->name )) { 
     
    210221            newprop->ref_cnt++; 
    211222            newprop->alias_for = swish_xstrdup( prop->name ); 
     223            newprop->id = h->prop_id++; 
    212224            swish_hash_add( h->config->properties, newprop->name, newprop ); 
    213225            //swish_debug_property(newprop); 
     
    245257    else if (xmlStrEqual(attr, (xmlChar*)"sort")) { 
    246258        prop->sort = (boolean)strtol((char*)attr_val, (char**)NULL, 10); 
     259    } 
     260    else if (xmlStrEqual(attr, (xmlChar*)"id")) { 
     261        prop->id = (boolean)strtol((char*)attr_val, (char**)NULL, 10); 
    247262    } 
    248263    else if (xmlStrEqual(attr, (xmlChar*)"type")) { 
     
    303318        } 
    304319     
     320    } 
     321     
     322    if (!prop->id) { 
     323        prop->id = h->prop_id++; 
    305324    } 
    306325         
     
    524543    h->ismetas  = 0; 
    525544    h->parent_name = NULL; 
     545    h->prop_id  = SWISH_PROP_THIS_MUST_COME_LAST_ID; 
     546    h->meta_id  = SWISH_META_THIS_MUST_COME_LAST_ID; 
    526547    return h; 
    527548} 
  • libswish3/trunk/src/libswish3/libswish3.h

    r2090 r2096  
    2727#include <libxml/parser.h> 
    2828#include <libxml/hash.h> 
    29  
     29#include <libxml/xmlstring.h> 
    3030 
    3131#define SWISH_LIB_VERSION         "0.1.0" 
     
    102102#define SWISH_META_CONNECTOR       "\3" 
    103103 
     104/* built-in id values */ 
     105typedef enum { 
     106    SWISH_META_DEFAULT_ID = 0, 
     107    SWISH_META_TITLE_ID, 
     108    SWISH_META_THIS_MUST_COME_LAST_ID 
     109} SWISH_META_ID; 
     110 
     111typedef enum { 
     112    SWISH_PROP_DOCID_ID = 0, 
     113    SWISH_PROP_DOCPATH_ID, 
     114    SWISH_PROP_DBFILE_ID, 
     115    SWISH_PROP_TITLE_ID, 
     116    SWISH_PROP_SIZE_ID, 
     117    SWISH_PROP_MTIME_ID, 
     118    SWISH_PROP_DESCRIPTION_ID, 
     119    SWISH_PROP_NWORDS_ID, 
     120    SWISH_PROP_MIME_ID, 
     121    SWISH_PROP_PARSER_ID, 
     122    SWISH_PROP_THIS_MUST_COME_LAST_ID 
     123} SWISH_PROP_ID; 
     124 
     125/* xapian (maybe others) need string prefixes for metanames */ 
     126#define SWISH_PREFIX_URL            "U" 
     127#define SWISH_PREFIX_MTIME          "T" 
     128 
     129 
    104130/* utils */ 
    105131#define SWISH_MAX_WORD_LEN        256 
     
    122148 
    123149/* debugging levels */ 
    124 #define SWISH_DEBUG_DOCINFO     1 
    125 #define SWISH_DEBUG_TOKENIZER   2 
    126 #define SWISH_DEBUG_WORDLIST    4 
    127 #define SWISH_DEBUG_PARSER      8 
    128 #define SWISH_DEBUG_CONFIG      16 
    129 #define SWISH_DEBUG_MEMORY      32 
    130 #define SWISH_DEBUG_NAMEDBUFFER 64 
     150typedef enum { 
     151    SWISH_DEBUG_DOCINFO     = 1, 
     152    SWISH_DEBUG_TOKENIZER   = 2, 
     153    SWISH_DEBUG_WORDLIST    = 4, 
     154    SWISH_DEBUG_PARSER      = 8, 
     155    SWISH_DEBUG_CONFIG      = 16, 
     156    SWISH_DEBUG_MEMORY      = 32, 
     157    SWISH_DEBUG_NAMEDBUFFER = 64 
     158} SWISH_DEBUG_LEVELS; 
    131159 
    132160#define SWISH_DEBUG_MSG(args...)                                    \ 
     
    578606                                         int autovivify); 
    579607void                swish_append_buffer( xmlBufferPtr buf, xmlChar * txt, int len ); 
     608xmlChar*            swish_nb_get_value( swish_NamedBuffer* nb, xmlChar* key ); 
    580609/* 
    581610=cut 
  • libswish3/trunk/src/libswish3/namedbuffer.c

    r2041 r2096  
    2323 
    2424 
    25 #include <libxml/hash.h> 
    26 #include <libxml/xmlstring.h> 
    2725#include <stdio.h> 
    2826#include <stdlib.h> 
     
    5856free_name_from_hash(void *buffer, xmlChar * name) 
    5957{ 
    60     if (SWISH_DEBUG >= SWISH_DEBUG_NAMEDBUFFER) 
     58    if (SWISH_DEBUG & SWISH_DEBUG_NAMEDBUFFER) 
    6159        SWISH_DEBUG_MSG(" freeing NamedBuffer %s\n", name); 
    6260 
     
    195193} 
    196194 
     195xmlChar* 
     196swish_nb_get_value( swish_NamedBuffer *nb, xmlChar *key ) 
     197{ 
     198    xmlBufferPtr buf; 
     199    buf = xmlHashLookup(nb->hash, key); 
     200    return (xmlChar*)xmlBufferContent(buf); 
     201} 
  • libswish3/trunk/src/libswish3/parser.c

    r2041 r2096  
    248248        if (metaname != NULL && metacontent != NULL) 
    249249        { 
    250             if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 
     250            if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
    251251                SWISH_DEBUG_MSG("found HTML meta: %s => %s", metaname, metacontent); 
    252252                 
     
    274274 
    275275 
    276     if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 
     276    if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
    277277    { 
    278278        fprintf(stderr, " >>> build_tag (%s (%s) ", tag, parser_data->tag); 
     
    311311    swish_TagStack *s = parser_data->metastack; 
    312312     
    313     if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 
     313    if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
    314314        SWISH_DEBUG_MSG("buffer is >>%s<< before flush, word_pos = %d",  
    315315            xmlBufferContent(parser_data->meta_buf), parser_data->word_pos); 
     
    442442 
    443443 
    444     if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 
     444    if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
    445445        SWISH_DEBUG_MSG("checking config for '%s' in watched tags", parser_data->tag); 
    446446 
     
    449449    if (swish_hash_exists(parser_data->s3->config->properties, parser_data->tag)) 
    450450    { 
    451         if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 
     451        if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
    452452            SWISH_DEBUG_MSG(" %s = new property", parser_data->tag); 
    453453 
     
    457457        parser_data->propstack = push_tag_stack(parser_data->propstack, parser_data->tag); 
    458458 
    459         if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 
     459        if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
    460460            SWISH_DEBUG_MSG("%s pushed ok unto propstack", parser_data->tag); 
    461461    } 
     
    464464    if (swish_hash_exists(parser_data->s3->config->metanames, parser_data->tag)) 
    465465    { 
    466         if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 
     466        if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
    467467            SWISH_DEBUG_MSG(" %s = new metaname", parser_data->tag); 
    468468                                
     
    472472    } 
    473473     
    474     if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 
     474    if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
    475475        SWISH_DEBUG_MSG("config check for '%s' done", parser_data->tag); 
    476476 
     
    16711671                                            (xmlChar*)SWISH_DEFAULT_METANAME); 
    16721672 
    1673     if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 
     1673    if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
    16741674        SWISH_DEBUG_MSG("stack pushed for %s", parser_data->metastack->flat); 
    16751675 
     
    16791679    if (out != NULL) 
    16801680    { 
    1681         if (SWISH_DEBUG >= SWISH_DEBUG_PARSER) 
     1681        if (SWISH_DEBUG & SWISH_DEBUG_PARSER) 
    16821682            SWISH_DEBUG_MSG("tmp text buffer being freed"); 
    16831683             
  • libswish3/trunk/src/libswish3/string.c

    r2090 r2096  
    2424 
    2525#include <assert.h> 
    26 #include <libxml/hash.h> 
    2726#include <wchar.h> 
    2827#include <ctype.h> 
  • libswish3/trunk/src/libswish3/swish.c

    r2046 r2096  
    8181     
    8282    /* global debug flag */ 
    83     setenv("SWISH_DEBUG", "0", 0); 
    84     setenv("SWISH_DEBUG_MEMORY", "0", 0); 
    85     setenv("SWISH_DEBUG_CONFIG", "0", 0); 
    86     setenv("SWISH_DEBUG_DOCINFO", "0", 0); 
    87     setenv("SWISH_DEBUG_WORDLIST", "0", 0); 
     83    setenv("SWISH_DEBUG",           "0", 0); 
     84    setenv("SWISH_DEBUG_MEMORY",    "0", 0); 
     85    setenv("SWISH_DEBUG_CONFIG",    "0", 0); 
     86    setenv("SWISH_DEBUG_DOCINFO",   "0", 0); 
     87    setenv("SWISH_DEBUG_WORDLIST", "0", 0); 
    8888    setenv("SWISH_DEBUG_TOKENIZER", "0", 0); 
    89     setenv("SWISH_DEBUG_PARSER", "0", 0); 
     89    setenv("SWISH_DEBUG_PARSER",    "0", 0); 
    9090    setenv("SWISH_DEBUG_NAMEDBUFFER", "0", 0); 
    9191    if (!SWISH_DEBUG) { 
     92         
    9293        SWISH_DEBUG += (int)strtol(getenv("SWISH_DEBUG"), (char**)NULL, 10); 
     94         
     95        /* additional env vars just increase the global var value */ 
     96         
    9397        if ((int)strtol(getenv("SWISH_DEBUG_MEMORY"), (char**)NULL, 10)) { 
    9498            SWISH_DEBUG += SWISH_DEBUG_MEMORY; 
    9599        } 
    96         SWISH_DEBUG += (int)strtol(getenv("SWISH_DEBUG_CONFIG"), (char**)NULL, 10); 
    97         SWISH_DEBUG += (int)strtol(getenv("SWISH_DEBUG_DOCINFO"), (char**)NULL, 10); 
    98         SWISH_DEBUG += (int)strtol(getenv("SWISH_DEBUG_WORDLIST"), (char**)NULL, 10); 
    99         SWISH_DEBUG += (int)strtol(getenv("SWISH_DEBUG_PARSER"), (char**)NULL, 10); 
    100         SWISH_DEBUG += (int)strtol(getenv("SWISH_DEBUG_NAMEDBUFFER"), (char**)NULL, 10); 
     100        if ((int)strtol(getenv("SWISH_DEBUG_CONFIG"), (char**)NULL, 10)) { 
     101            SWISH_DEBUG += SWISH_DEBUG_CONFIG; 
     102        } 
     103        if ((int)strtol(getenv("SWISH_DEBUG_DOCINFO"), (char**)NULL, 10)) { 
     104            SWISH_DEBUG += SWISH_DEBUG_DOCINFO; 
     105        } 
     106        if ((int)strtol(getenv("SWISH_DEBUG_WORDLIST"), (char**)NULL, 10)) { 
     107            SWISH_DEBUG += SWISH_DEBUG_WORDLIST; 
     108        } 
     109        if ((int)strtol(getenv("SWISH_DEBUG_PARSER"), (char**)NULL, 10)) { 
     110            SWISH_DEBUG += SWISH_DEBUG_PARSER; 
     111        } 
     112        if ((int)strtol(getenv("SWISH_DEBUG_NAMEDBUFFER"), (char**)NULL, 10)) { 
     113            SWISH_DEBUG += SWISH_DEBUG_NAMEDBUFFER; 
     114        } 
    101115    } 
    102116         
  • libswish3/trunk/src/libswish3/words.c

    r2030 r2096  
    8484    swish_Word    *t; 
    8585 
    86     if (SWISH_DEBUG >= SWISH_DEBUG_MEMORY) 
     86    if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) 
    8787        SWISH_DEBUG_MSG("freeing swish_WordList"); 
    8888 
     
    9191    while (list->current != NULL) 
    9292    { 
    93         if (SWISH_DEBUG >= SWISH_DEBUG_MEMORY) 
     93        if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) 
    9494            SWISH_DEBUG_MSG("free metaname: %s", list->current->metaname); 
    9595             
    9696        swish_xfree(list->current->metaname); 
    9797         
    98         if (SWISH_DEBUG >= SWISH_DEBUG_MEMORY) 
     98        if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) 
    9999            SWISH_DEBUG_MSG("free context: %s", list->current->context); 
    100100             
    101101        swish_xfree(list->current->context); 
    102102         
    103         if (SWISH_DEBUG >= SWISH_DEBUG_MEMORY) 
     103        if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) 
    104104            SWISH_DEBUG_MSG("free word: %s", list->current->word); 
    105105             
    106106        swish_xfree(list->current->word); 
    107107                 
    108         if (SWISH_DEBUG >= SWISH_DEBUG_MEMORY) 
     108        if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) 
    109109            SWISH_DEBUG_MSG("free Word struct"); 
    110110             
     
    114114    } 
    115115     
    116     if (SWISH_DEBUG >= SWISH_DEBUG_MEMORY) 
     116    if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) 
    117117        SWISH_DEBUG_MSG("reset nwords"); 
    118118         
    119119    list->nwords = 0; 
    120120     
    121     if (SWISH_DEBUG >= SWISH_DEBUG_MEMORY) 
     121    if (SWISH_DEBUG & SWISH_DEBUG_MEMORY) 
    122122        SWISH_DEBUG_MSG("free list"); 
    123123 
     
    263263    } 
    264264     
    265     if( SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER ) 
     265    if( SWISH_DEBUG & SWISH_DEBUG_TOKENIZER ) 
    266266        SWISH_DEBUG_MSG(" %lc is %d bytes long", ch, len); 
    267267         
     
    304304    in_word = 0; 
    305305 
    306     if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     306    if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    307307        SWISH_DEBUG_MSG("parsing string: '%ls' into words", wide); 
    308308 
     
    313313        byte_count += bytes_in_chr((wint_t)c); 
    314314 
    315         if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     315        if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    316316            SWISH_DEBUG_MSG(" wchar: %lc lower: %lc  int: %d %#x\n    orig: %lc %ld %#lx (next is %lc)", 
    317317                   (wint_t) wide[i], 
     
    337337            if (in_word) 
    338338            { 
    339                 if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     339                if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    340340                    SWISH_DEBUG_MSG("found end of token: '%lc'", (wint_t)c); 
    341341 
     
    359359                else 
    360360                { 
    361                     if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     361                    if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    362362                        SWISH_DEBUG_MSG("skipping token '%s' -- too short: %d", utf8_str, wl); 
    363363                } 
     
    370370            else 
    371371            { 
    372                 if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     372                if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    373373                    SWISH_DEBUG_MSG("ignoring char '%lc'", (wint_t)c); 
    374374                     
     
    383383            { 
    384384             
    385                 if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     385                if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    386386                    SWISH_DEBUG_MSG("adding to token: '%lc'", (wint_t)c); 
    387387 
     
    392392                { 
    393393 
    394                     if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     394                    if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    395395                        SWISH_DEBUG_MSG("forcing end of token: '%lc'", (wint_t)c); 
    396396 
     
    414414                    else 
    415415                    { 
    416                         if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     416                        if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    417417                            SWISH_DEBUG_MSG("skipping token '%ls' -- too short: %d", word, wl); 
    418418                    } 
     
    428428            { 
    429429 
    430                 if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     430                if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    431431                    SWISH_DEBUG_MSG("start a token with '%lc'", (wint_t)c); 
    432432 
     
    522522    in_word     = 0; 
    523523 
    524     if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     524    if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    525525        SWISH_DEBUG_MSG("tokenizing string: '%s'", str); 
    526526 
     
    532532        byte_count++; 
    533533 
    534         if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     534        if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    535535            SWISH_DEBUG_MSG(" char: %c lower: %c  int: %d %#x (next is %c)", 
    536536                   str[i], 
     
    553553            if (in_word) 
    554554            { 
    555                 if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     555                if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    556556                    SWISH_DEBUG_MSG("found end of token: '%c' at %d", c, byte_count); 
    557557 
     
    574574                else 
    575575                { 
    576                     if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     576                    if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    577577                        SWISH_DEBUG_MSG("skipping token '%s' -- too short: %d", word, wl); 
    578578                } 
     
    583583            else 
    584584            { 
    585                 if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     585                if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    586586                    SWISH_DEBUG_MSG("ignoring char '%c'", c); 
    587587                     
     
    596596            { 
    597597             
    598                 if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     598                if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    599599                    SWISH_DEBUG_MSG("adding to token: '%c' %d", c, byte_count); 
    600600 
     
    605605                { 
    606606 
    607                     if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     607                    if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    608608                        SWISH_DEBUG_MSG("forcing end of token: '%c' %d", c, byte_count); 
    609609 
     
    626626                    else 
    627627                    { 
    628                         if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     628                        if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    629629                            SWISH_DEBUG_MSG("skipping token '%s' -- too short: %d", word, wl); 
    630630                    } 
     
    638638            { 
    639639 
    640                 if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     640                if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    641641                    SWISH_DEBUG_MSG("start a token with '%c' %d", c, byte_count); 
    642642 
     
    713713    end = 0; 
    714714 
    715     if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     715    if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    716716        SWISH_DEBUG_MSG("Before: %ls", word); 
    717717 
     
    764764    } 
    765765 
    766     if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     766    if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    767767        SWISH_DEBUG_MSG("After: %ls (stripped %d start chars, %d end chars)", word, start, end); 
    768768 
     
    778778    end = 0; 
    779779 
    780     if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     780    if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    781781        SWISH_DEBUG_MSG("Before: %s", word); 
    782782 
     
    829829    } 
    830830 
    831     if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     831    if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    832832        SWISH_DEBUG_MSG("After: %s (stripped %d start chars, %d end chars)", word, start, end); 
    833833 
     
    853853    swish_Word  *thisword = (swish_Word *) swish_xmalloc(sizeof(swish_Word)); 
    854854     
    855     if (SWISH_DEBUG >= SWISH_DEBUG_TOKENIZER) 
     855    if (SWISH_DEBUG & SWISH_DEBUG_TOKENIZER) 
    856856    { 
    857857        SWISH_DEBUG_MSG(" >>>>>>>>swish_Word<<<<<<<<:  %s", word); 
  • libswish3/trunk/src/swish_lint.c

    r2027 r2096  
    2727#include <wctype.h> 
    2828#include <ctype.h> 
    29 #include <libxml/hash.h> 
    3029#include <getopt.h> 
    3130 
  • libswish3/trunk/src/xapian/swish_xapian.cpp

    r2090 r2096  
    1818 */ 
    1919 
    20 /* example Swish3 program using Xapian IR backend */ 
     20/*  example Swish3 program using Xapian IR backend. 
     21    many of the string conversion functions and the index_document() code 
     22    come nearly verbatim from the xapian-omega distribution. 
     23 
     24*/ 
    2125 
    2226//#include <config.h> 
     
    8488}; 
    8589 
    86  
    87 #define SWISH_PREFIX_URL    "U" 
    88 #define SWISH_PREFIX_MTIME  "T" 
    89 #define SWISH_PROP_LAST_MOD 0 
    9090 
    9191// This ought to be enough for any of the conversions below. 
     
    195195    swish_Property* prop; 
    196196    prop = (swish_Property*)swish_hash_fetch(s3->config->properties, name); 
     197    SWISH_DEBUG_MSG("adding property %s [%d]: %s", name, prop->id, xmlBufferContent(buffer)); 
    197198    doc.add_value(prop->id, (const char*)xmlBufferContent(buffer)); 
    198199} 
     
    216217    // Put the data in the document 
    217218    Xapian::Document newdocument; 
     219    xmlChar* title = (xmlChar*)swish_nb_get_value(parser_data->properties, (xmlChar*)SWISH_PROP_TITLE); 
     220    printf("title = %s", (char*)title); 
    218221    string unique_id = SWISH_PREFIX_URL + string((const char*)parser_data->docinfo->uri); 
    219222    string record = "url=" + string( (const char*)parser_data->docinfo->uri ); 
    220         record += "\ntitle=" + string((const char*) 
    221         swish_hash_fetch(parser_data->properties->hash, (xmlChar*)SWISH_PROP_TITLE)); 
     223        record += "\ntitle=" + string((const char*)title); 
    222224    record += "\ntype=" + string( (const char*)parser_data->docinfo->mime ); 
    223225        record += "\nmodtime=" + long_to_string(parser_data->docinfo->mtime); 
     
    228230    indexer.set_document(newdocument); 
    229231        indexer.increase_termpos(100); 
    230     newdocument.add_term(SWISH_PREFIX_MTIME + string((const char*)parser_data->docinfo->mime)); 
     232    newdocument.add_term(SWISH_PREFIX_MTIME + long_to_string(parser_data->docinfo->mtime)); 
    231233    newdocument.add_term(unique_id); 
    232234 
     
    241243    newdocument.add_term(date_term); // Year (YYYY) 
    242244 
    243     // Add last_mod as a value to allow "sort by date". 
    244     newdocument.add_value(SWISH_PROP_LAST_MOD,  
    245         int_to_binary_string((uint32_t)parser_data->docinfo->mtime)); 
     245    // add all docinfo values as properties 
     246    newdocument.add_value(SWISH_PROP_MTIME_ID, long_to_string(parser_data->docinfo->mtime)); 
     247    newdocument.add_value(SWISH_PROP_DOCPATH_ID, string((const char*)parser_data->docinfo->uri)); 
     248    newdocument.add_value(SWISH_PROP_SIZE_ID, long_to_string(parser_data->docinfo->size)); 
     249    newdocument.add_value(SWISH_PROP_MIME_ID, string((const char*)parser_data->docinfo->mime)); 
     250    newdocument.add_value(SWISH_PROP_PARSER_ID, string((const char*)parser_data->docinfo->parser)); 
     251    newdocument.add_value(SWISH_PROP_NWORDS_ID, long_to_string(parser_data->docinfo->nwords)); 
     252         
     253    // title is special value 
     254    newdocument.add_value(SWISH_PROP_TITLE_ID, string((const char*)title)); 
    246255     
    247256    // add all metanames and properties