-/* $Id: zsets.c,v 1.109 2006-08-07 10:14:59 adam Exp $
- Copyright (C) 1995-2006
+/* $Id: zsets.c,v 1.120 2007-03-20 22:07:35 adam Exp $
+ Copyright (C) 1995-2007
Index Data ApS
This file is part of the Zebra server.
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
+
*/
int term_entries_max;
struct zebra_set *next;
int locked;
+ int estimated_hit_count;
zint cache_position; /* last position */
RSFD cache_rfd; /* rfd (NULL if not existing) */
static int log_level_searchterms=0;
static int log_level_resultsets=0;
-static void loglevels()
+static void loglevels(void)
{
if (log_level_set)
return;
log_level_set = 1;
}
-ZEBRA_RES resultSetSearch(ZebraHandle zh, NMEM nmem, NMEM rset_nmem,
- Z_RPNQuery *rpn, ZebraSet sset)
+
+static ZEBRA_RES resultSetSearch(ZebraHandle zh, NMEM nmem, NMEM rset_nmem,
+ Z_RPNQuery *rpn, ZebraSet sset)
{
RSET rset = 0;
oident *attrset;
int sort_status, i;
ZEBRA_RES res = ZEBRA_OK;
- zh->hits = 0;
-
sort_sequence = (Z_SortKeySpecList *)
nmem_malloc(nmem, sizeof(*sort_sequence));
sort_sequence->num_specs = 10; /* FIXME - Hard-coded number */
sort_sequence->specs[i] = 0;
attrset = oid_getentbyoid (rpn->attributeSetId);
+
+ rpn_get_top_approx_limit(zh, rpn->RPNStructure, &sset->approx_limit);
+
res = rpn_search_top(zh, rpn->RPNStructure, attrset->value,
nmem, rset_nmem,
sort_sequence,
}
-ZEBRA_RES resultSetAddRPN (ZebraHandle zh, NMEM m, Z_RPNQuery *rpn,
- int num_bases, char **basenames,
- const char *setname)
+ZEBRA_RES resultSetAddRPN(ZebraHandle zh, NMEM m, Z_RPNQuery *rpn,
+ int num_bases, char **basenames,
+ const char *setname,
+ zint *hits, int *estimated_hit_count)
{
ZebraSet zebraSet;
int i;
ZEBRA_RES res;
- zh->hits = 0;
+ *hits = 0;
+ *estimated_hit_count = 0;
zebraSet = resultSetAdd(zh, setname, 1);
if (!zebraSet)
res = resultSetSearch(zh, zebraSet->nmem, zebraSet->rset_nmem,
rpn, zebraSet);
- zh->hits = zebraSet->hits;
+ *hits = zebraSet->hits;
+ if (zebraSet->estimated_hit_count)
+ *estimated_hit_count = 1;
+
if (zebraSet->rset)
zebraSet->rpn = rpn;
zebraSet->locked = 0;
s->cache_position = 0;
s->cache_rfd = 0;
s->approx_limit = zh->approx_limit;
+ s->estimated_hit_count = 0;
return s;
}
struct sortKeyInfo {
int relation;
-#if 0
- int attrUse;
-#else
int ord;
-#endif
int numerical;
+ int index_type;
};
void resultSetInsertSort(ZebraHandle zh, ZebraSet sset,
struct zset_sort_info *sort_info = sset->sort_info;
int i, j;
- sortIdx_sysno (zh->reg->sortIdx, sysno);
+ zebra_sort_sysno(zh->reg->sort_index, sysno);
for (i = 0; i<num_criteria; i++)
{
char *this_entry_buf = tmp_cmp_buf[i];
memset(this_entry_buf, '\0', SORT_IDX_ENTRYSIZE);
if (criteria[i].ord != -1)
{
- sortIdx_type(zh->reg->sortIdx, criteria[i].ord);
- sortIdx_read(zh->reg->sortIdx, this_entry_buf);
+ zebra_sort_type(zh->reg->sort_index, criteria[i].ord);
+ zebra_sort_read(zh->reg->sort_index, this_entry_buf);
}
}
i = sort_info->num_entries;
cmp_buf[j] + i * SORT_IDX_ENTRYSIZE;
if (criteria[j].numerical)
{
- double diff = atof(this_entry_buf) - atof(other_entry_buf);
- 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
{
sort_criteria[i].ord =
zebraExplain_lookup_attr_str(zh->reg->zei,
zinfo_index_category_sort,
- 's',
- sk->u.sortField);
+ -1, sk->u.sortField);
if (sks->which != Z_SortKeySpec_null
&& sort_criteria[i].ord == -1)
{
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; i<num_criteria; i++)
kno++;
if (this_sys != psysno)
{
+ if ((sset->hits & 255) == 0 && zh->break_handler_func)
+ {
+ if (zh->break_handler_func(zh->break_handler_data))
+ {
+ rset_set_hits_limit(rset, 0);
+ break;
+ }
+ }
(sset->hits)++;
psysno = this_sys;
resultSetInsertSort(zh, sset,
sort_info = zebraSet->sort_info;
sort_info->num_entries = 0;
zebraSet->hits = 0;
+ zebraSet->estimated_hit_count = 0;
rset_getterms(rset, 0, 0, &n);
terms = (TERMID *) nmem_malloc(nmem, sizeof(*terms)*n);
rset_getterms(rset, terms, n, &numTerms);
-
rank_class = zebraRankLookup(zh, rank_handler_name);
if (!rank_class)
{
struct rank_control *rc = rank_class->control;
int score;
zint count = 0;
-
- void *handle =
- (*rc->begin) (zh->reg, rank_class->class_handle, rset, nmem,
- terms, numTerms);
+ void *handle = (*rc->begin) (zh->reg, rank_class->class_handle, rset,
+ nmem, terms, numTerms);
zint psysno = 0; /* previous doc id / sys no */
zint pstaticrank = 0; /* previous static rank */
int stop_flag = 0;
key_logdump_txt(log_level_searchhits, &key, termid->name);
if (this_sys != psysno)
{ /* new record .. */
+ if (!(rfd->counted_items & 255) && zh->break_handler_func)
+ {
+ if (zh->break_handler_func(zh->break_handler_data))
+ {
+ yaz_log(YLOG_LOG, "Aborted search");
+ stop_flag = 1;
+ }
+ }
if (rfd->counted_items > rset->hits_limit)
- break;
+ stop_flag = 1;
if (psysno)
{ /* only if we did have a previous record */
score = (*rc->calc) (handle, psysno, pstaticrank,
/* insert the hit. A=Ascending */
resultSetInsertRank (zh, sort_info, psysno, score, 'A');
count++;
- if (stop_flag)
- break;
}
+ if (stop_flag)
+ {
+ zebraSet->estimated_hit_count = 1;
+ rset_set_hits_limit(rset, 0);
+ break;
+ }
psysno = this_sys;
if (zh->m_staticrank)
pstaticrank = key.mem[0];
if (ret == (size_t)(-1))
*termlen = 0;
else
+ {
+ yaz_iconv(zh->iconv_from_utf8, 0, 0,
+ &outbuf, &outleft);
*termlen = outbuf - termbuf;
+ }
}
else
{