X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fzsets.c;h=225876c72a63050eee47be89617c75b7d4ef001d;hb=b81eb4e30e5febe06da7118cd9a84a63604cb1e0;hp=a9067052d7f3d3a7a025739699dd10572331cabe;hpb=0ef68e6e54cfd7a91a28ee3b1f305924ac34e787;p=idzebra-moved-to-github.git diff --git a/index/zsets.c b/index/zsets.c index a906705..225876c 100644 --- a/index/zsets.c +++ b/index/zsets.c @@ -576,10 +576,40 @@ 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, w)) + { + 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) + { + memcpy(this_entry_buf, wrbuf_buf(w)+off, l); + this_entry_buf[l] = '\0'; + } + else if (criteria[i].relation == 'A') + { + if (strcmp(wrbuf_buf(w)+off, this_entry_buf) < 0) + { + memcpy(this_entry_buf, wrbuf_buf(w)+off, l); + this_entry_buf[l] = '\0'; + } + } + else if (criteria[i].relation == 'D') + { + if (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 {