X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fzsets.c;h=8a3f66a5959e5db77c3ba7b1ac8f50095f69941e;hb=7598c76f1a4989a91003bd4fbd90f30a7c7255ef;hp=a9067052d7f3d3a7a025739699dd10572331cabe;hpb=0ef68e6e54cfd7a91a28ee3b1f305924ac34e787;p=idzebra-moved-to-github.git diff --git a/index/zsets.c b/index/zsets.c index a906705..8a3f66a 100644 --- a/index/zsets.c +++ b/index/zsets.c @@ -576,10 +576,32 @@ void resultSetInsertSort(ZebraHandle zh, ZebraSet sset, criteria[i].ord[database_no]); zebra_sort_type(zh->reg->sort_index, criteria[i].ord[database_no]); wrbuf_rewind(w); - zebra_sort_read(zh->reg->sort_index, w); - memcpy(this_entry_buf, wrbuf_buf(w), - (wrbuf_len(w) >= SORT_IDX_ENTRYSIZE) ? - SORT_IDX_ENTRYSIZE : wrbuf_len(w)); + if (zebra_sort_read(zh->reg->sort_index, 0, w)) + { + /* consider each sort entry and take lowest/highest one + of the one as sorting key depending on whether sort is + ascending/descending */ + int off = 0; + while (off != wrbuf_len(w)) + { + size_t l = strlen(wrbuf_buf(w)+off); + assert(off < wrbuf_len(w)); + + if (l >= SORT_IDX_ENTRYSIZE) + l = SORT_IDX_ENTRYSIZE-1; + if ( (off == 0) + || (criteria[i].relation == 'A' + && strcmp(wrbuf_buf(w)+off, this_entry_buf) < 0) + || (criteria[i].relation == 'D' + && strcmp(wrbuf_buf(w)+off, this_entry_buf) > 0) + ) + { + memcpy(this_entry_buf, wrbuf_buf(w)+off, l); + this_entry_buf[l] = '\0'; + } + off += 1 + strlen(wrbuf_buf(w)+off); + } + } } else { @@ -601,12 +623,6 @@ void resultSetInsertSort(ZebraHandle zh, ZebraSet sset, char this_entry_org[1024]; char other_entry_org[1024]; double diff; - /* when searching multiple databases, we use the index - type of the first one. So if they differ between - databases, we have a problem here we could store the - index_type for each database, but if we didn't find the - record in any sort index, then we still don't know to - which database it belongs. */ const char *index_type = criteria[j].index_type; zebra_term_untrans(zh, index_type, this_entry_org, this_entry_buf);