X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=index%2Fzsets.c;h=643ba2cfeacebfc6310acecda1477bfb0cfb0284;hp=e010d2238b8c8ef76bd7da097903aa70263bc598;hb=c401b3a1421e31b3d6b77bc7bac6ffb934207df1;hpb=9ceac3e96fe083b93b6fd4a676003dd10482e465 diff --git a/index/zsets.c b/index/zsets.c index e010d22..643ba2c 100644 --- a/index/zsets.c +++ b/index/zsets.c @@ -1,4 +1,4 @@ -/* $Id: zsets.c,v 1.105 2006-05-30 21:41:35 adam Exp $ +/* $Id: zsets.c,v 1.112 2006-10-29 17:20:01 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -15,9 +15,9 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with Zebra; see the file LICENSE.zebra. If not, write to the -Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ @@ -34,8 +34,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include -#define SORT_IDX_ENTRYSIZE 64 -#define ZSET_SORT_MAX_LEVEL 3 +#define ZSET_SORT_MAX_LEVEL 10 struct zebra_set_term_entry { int reg_type; @@ -69,7 +68,6 @@ struct zebra_set { struct zset_sort_entry { zint sysno; int score; - char buf[ZSET_SORT_MAX_LEVEL][SORT_IDX_ENTRYSIZE]; }; struct zset_sort_info { @@ -85,7 +83,7 @@ static int log_level_searchhits=0; static int log_level_searchterms=0; static int log_level_resultsets=0; -static void loglevels() +static void loglevels(void) { if (log_level_set) return; @@ -536,19 +534,16 @@ void zebra_meta_records_destroy (ZebraHandle zh, ZebraMetaRecord *records, struct sortKeyInfo { int relation; -#if 0 - int attrUse; -#else int ord; -#endif int numerical; + int index_type; }; -void resultSetInsertSort (ZebraHandle zh, ZebraSet sset, - struct sortKeyInfo *criteria, int num_criteria, - zint sysno) +void resultSetInsertSort(ZebraHandle zh, ZebraSet sset, + struct sortKeyInfo *criteria, int num_criteria, + zint sysno, + char *cmp_buf[], char *tmp_cmp_buf[]) { - struct zset_sort_entry this_entry; struct zset_sort_entry *new_entry = NULL; struct zset_sort_info *sort_info = sset->sort_info; int i, j; @@ -556,11 +551,12 @@ void resultSetInsertSort (ZebraHandle zh, ZebraSet sset, sortIdx_sysno (zh->reg->sortIdx, sysno); for (i = 0; ireg->sortIdx, criteria[i].ord); - sortIdx_read (zh->reg->sortIdx, this_entry.buf[i]); + sortIdx_type(zh->reg->sortIdx, criteria[i].ord); + sortIdx_read(zh->reg->sortIdx, this_entry_buf); } } i = sort_info->num_entries; @@ -569,20 +565,32 @@ void resultSetInsertSort (ZebraHandle zh, ZebraSet sset, int rel = 0; for (j = 0; jentries[i]->buf[j]); - rel = 0; + char this_entry_org[1024]; + char other_entry_org[1024]; + double diff; + int index_type = criteria[j].index_type; + zebra_term_untrans(zh, index_type, this_entry_org, + this_entry_buf); + zebra_term_untrans(zh, index_type, other_entry_org, + other_entry_buf); + diff = atof(this_entry_org) - atof(other_entry_org); + if (diff > 0.0) rel = 1; else if (diff < 0.0) rel = -1; + else + rel = 0; } else { - rel = memcmp (this_entry.buf[j], sort_info->entries[i]->buf[j], - SORT_IDX_ENTRYSIZE); + rel = memcmp(this_entry_buf, other_entry_buf, + SORT_IDX_ENTRYSIZE); } if (rel) break; @@ -612,19 +620,30 @@ void resultSetInsertSort (ZebraHandle zh, ZebraSet sset, new_entry = sort_info->entries[j]; while (j != i) { + int k; + for (k = 0; kentries[j] = sort_info->entries[j-1]; --j; } sort_info->entries[i] = new_entry; assert (new_entry); for (i = 0; ibuf[i], this_entry.buf[i], SORT_IDX_ENTRYSIZE); + { + char *new_entry_buf = cmp_buf[i] + j * SORT_IDX_ENTRYSIZE; + char *this_entry_buf = tmp_cmp_buf[i]; + memcpy(new_entry_buf, this_entry_buf, SORT_IDX_ENTRYSIZE); + } new_entry->sysno = sysno; new_entry->score = -1; } -void resultSetInsertRank (ZebraHandle zh, struct zset_sort_info *sort_info, - zint sysno, int score, int relation) +void resultSetInsertRank(ZebraHandle zh, struct zset_sort_info *sort_info, + zint sysno, int score, int relation) { struct zset_sort_entry *new_entry = NULL; int i, j; @@ -793,7 +812,9 @@ ZEBRA_RES resultSetSortSingle(ZebraHandle zh, NMEM nmem, zint kno = 0; zint psysno = 0; struct it_key key; - struct sortKeyInfo sort_criteria[3]; + struct sortKeyInfo sort_criteria[ZSET_SORT_MAX_LEVEL]; + char *cmp_buf[ZSET_SORT_MAX_LEVEL]; + char *tmp_cmp_buf[ZSET_SORT_MAX_LEVEL]; int num_criteria; RSFD rfd; TERMID termid; @@ -813,8 +834,8 @@ ZEBRA_RES resultSetSortSingle(ZebraHandle zh, NMEM nmem, sset->hits = 0; num_criteria = sort_sequence->num_specs; - if (num_criteria > 3) - num_criteria = 3; + if (num_criteria > ZSET_SORT_MAX_LEVEL) + num_criteria = ZSET_SORT_MAX_LEVEL; for (i = 0; i < num_criteria; i++) { Z_SortKeySpec *sks = sort_sequence->specs[i]; @@ -856,8 +877,9 @@ ZEBRA_RES resultSetSortSingle(ZebraHandle zh, NMEM nmem, i+1); sort_criteria[i].numerical = 0; sort_criteria[i].ord = - zebraExplain_lookup_attr_str(zh->reg->zei, 's', - sk->u.sortField); + zebraExplain_lookup_attr_str(zh->reg->zei, + zinfo_index_category_sort, + -1, sk->u.sortField); if (sks->which != Z_SortKeySpec_null && sort_criteria[i].ord == -1) { @@ -874,12 +896,27 @@ ZEBRA_RES resultSetSortSingle(ZebraHandle zh, NMEM nmem, case Z_SortKey_sortAttributes: yaz_log(log_level_sort, "key %d is of type sortAttributes", i+1); res = zebra_sort_get_ord(zh, sk->u.sortAttributes, + &sort_criteria[i].ord, &sort_criteria[i].numerical); if (sks->which != Z_SortKeySpec_null && res != ZEBRA_OK) return ZEBRA_FAIL; break; } + if (zebraExplain_lookup_ord(zh->reg->zei, sort_criteria[i].ord, + &sort_criteria[i].index_type, + 0, 0)) + { + zebra_setError(zh, YAZ_BIB1_CANNOT_SORT_ACCORDING_TO_SEQUENCE, 0); + return ZEBRA_FAIL; + } + } + /* allocate space for each cmpare buf + one extra for tmp comparison */ + for (i = 0; isort_info->max_entries + * SORT_IDX_ENTRYSIZE); + tmp_cmp_buf[i] = xmalloc(SORT_IDX_ENTRYSIZE); } rfd = rset_open (rset, RSETF_READ); while (rset_read (rfd, &key, &termid)) @@ -892,11 +929,19 @@ ZEBRA_RES resultSetSortSingle(ZebraHandle zh, NMEM nmem, { (sset->hits)++; psysno = this_sys; - resultSetInsertSort (zh, sset, - sort_criteria, num_criteria, psysno); + resultSetInsertSort(zh, sset, + sort_criteria, num_criteria, psysno, cmp_buf, + tmp_cmp_buf); } } rset_close (rfd); + + for (i = 0; ihits); for (i = 0; i < numTerms; i++) @@ -954,7 +999,7 @@ ZEBRA_RES resultSetRank(ZebraHandle zh, ZebraSet zebraSet, { RSFD rfd = rset_open(rset, RSETF_READ); struct rank_control *rc = rank_class->control; - double score; + int score; zint count = 0; void *handle = @@ -1172,8 +1217,8 @@ ZEBRA_RES zebra_snippets_hit_vector(ZebraHandle zh, const char *setname, NMEM nmem = nmem_create(); struct it_key key; RSET rsets[2], rset_comb; - RSET rset_temp = rstemp_create(nmem, kc, kc->scope, - res_get (zh->res, "setTmpDir"),0 ); + RSET rset_temp = rset_create_temp(nmem, kc, kc->scope, + res_get (zh->res, "setTmpDir"),0 ); TERMID termid; RSFD rsfd = rset_open(rset_temp, RSETF_WRITE); @@ -1189,7 +1234,7 @@ ZEBRA_RES zebra_snippets_hit_vector(ZebraHandle zh, const char *setname, rsets[0] = rset_temp; rsets[1] = rset_dup(sset->rset); - rset_comb = rsmulti_and_create(nmem, kc, kc->scope, 2, rsets); + rset_comb = rset_create_and(nmem, kc, kc->scope, 2, rsets); rsfd = rset_open(rset_comb, RSETF_READ);