X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fcharsets.c;h=f71f4c85faa12ba277c74c8586abe901eecc5718;hb=babdf4ba693f4a79037d8cf8cecc109e9355ec0d;hp=d2c79bd0adb8de3c1fbafaf095794ad73f5e0948;hpb=e8680d3e8a8900797c7bac415e20b127a7a077b9;p=pazpar2-moved-to-github.git diff --git a/src/charsets.c b/src/charsets.c index d2c79bd..f71f4c8 100644 --- a/src/charsets.c +++ b/src/charsets.c @@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #include "charsets.h" #include "normalize7bit.h" @@ -42,7 +43,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA /* charset handle */ struct pp2_charset_s { const char *(*token_next_handler)(pp2_relevance_token_t prt); - const char *(*get_sort_handler)(pp2_relevance_token_t prt, int skip); + const char *(*get_sort_handler)(pp2_relevance_token_t prt); int ref_count; #if YAZ_HAVE_ICU struct icu_chain * icu_chn; @@ -51,11 +52,11 @@ struct pp2_charset_s { }; static const char *pp2_relevance_token_a_to_z(pp2_relevance_token_t prt); -static const char *pp2_get_sort_ascii(pp2_relevance_token_t prt, int skip_article); +static const char *pp2_get_sort_ascii(pp2_relevance_token_t prt); #if YAZ_HAVE_ICU static const char *pp2_relevance_token_icu(pp2_relevance_token_t prt); -static const char *pp2_get_sort_icu(pp2_relevance_token_t prt, int skip_article); +static const char *pp2_get_sort_icu(pp2_relevance_token_t prt); #endif /* tokenzier handle */ @@ -132,17 +133,40 @@ void pp2_charset_destroy(pp2_charset_t pct) assert(pct->ref_count >= 1); --(pct->ref_count); if (pct->ref_count == 0) + { +#if YAZ_HAVE_ICU + icu_chain_destroy(pct->icu_chn); +#endif xfree(pct); + } } } pp2_relevance_token_t pp2_relevance_tokenize(pp2_charset_t pct, - const char *buf) + const char *buf, + int skip_article) { pp2_relevance_token_t prt = xmalloc(sizeof(*prt)); assert(pct); + if (skip_article) + { + const char *p = buf; + char firstword[64]; + char *pout = firstword; + char articles[] = "the den der die des an a "; // must end in space + + while (*p && !isalnum(*(unsigned char *)p)) + p++; + for (; *p && *p != ' ' && pout - firstword < (sizeof(firstword)-2); p++) + *pout++ = tolower(*(unsigned char *)p); + *pout++ = ' '; + *pout++ = '\0'; + if (strstr(articles, firstword)) + buf = p; + } + prt->norm_str = wrbuf_alloc(); prt->sort_str = wrbuf_alloc(); prt->cp = buf; @@ -179,9 +203,9 @@ const char *pp2_relevance_token_next(pp2_relevance_token_t prt) return (prt->pct->token_next_handler)(prt); } -const char *pp2_get_sort(pp2_relevance_token_t prt, int skip) +const char *pp2_get_sort(pp2_relevance_token_t prt) { - return prt->pct->get_sort_handler(prt, skip); + return prt->pct->get_sort_handler(prt); } #define raw_char(c) (((c) >= 'a' && (c) <= 'z') ? (c) : -1) @@ -215,8 +239,7 @@ static const char *pp2_relevance_token_a_to_z(pp2_relevance_token_t prt) return wrbuf_cstr(prt->norm_str); } -static const char *pp2_get_sort_ascii(pp2_relevance_token_t prt, - int skip_article) +static const char *pp2_get_sort_ascii(pp2_relevance_token_t prt) { if (prt->last_cp == 0) return 0; @@ -224,7 +247,7 @@ static const char *pp2_get_sort_ascii(pp2_relevance_token_t prt, { char *tmp = xstrdup(prt->last_cp); char *result = 0; - result = normalize7bit_mergekey(tmp, skip_article); + result = normalize7bit_mergekey(tmp); wrbuf_rewind(prt->sort_str); wrbuf_puts(prt->sort_str, result); @@ -248,8 +271,7 @@ static const char *pp2_relevance_token_icu(pp2_relevance_token_t prt) return 0; } -static const char *pp2_get_sort_icu(pp2_relevance_token_t prt, - int skip_article) +static const char *pp2_get_sort_icu(pp2_relevance_token_t prt) { return icu_chain_token_sortkey(prt->pct->icu_chn); }