if (ccount > 1)
wrbuf_printf(c->wrbuf, "<count>%d</count>\n", ccount);
if (strstr(sort, "relevance"))
- wrbuf_printf(c->wrbuf, "<relevance>%d</relevance>\n", rec->relevance);
+ wrbuf_printf(c->wrbuf, "<relevance>%d</relevance>\n",
+ rec->relevance_score);
wrbuf_puts(c->wrbuf, "<recid>");
wrbuf_xmlputs(c->wrbuf, rec->recid);
wrbuf_puts(c->wrbuf, "</recid>\n");
for (sdb = s->databases; sdb; sdb = sdb->next)
session_database_destroy(sdb);
normalize_cache_destroy(s->normalize_cache);
+ reclist_destroy(s->reclist);
nmem_destroy(s->nmem);
service_destroy(s->service);
wrbuf_destroy(s->wrbuf);
{
struct record_cluster *r;
- reclist_rewind(s->reclist);
+ reclist_enter(s->reclist);
*prev_r = 0;
*next_r = 0;
while ((r = reclist_read_record(s->reclist)))
if (!strcmp(r->recid, id))
{
*next_r = reclist_read_record(s->reclist);
- return r;
+ break;
}
*prev_r = r;
}
- return 0;
+ reclist_leave(s->reclist);
+ return r;
}
struct record_cluster **show(struct session *s, struct reclist_sortparms *sp,
}
reclist_sort(s->reclist, sp);
+ reclist_enter(s->reclist);
*total = reclist_get_num_records(s->reclist);
*sumhits = s->total_hits;
}
recs[i] = r;
}
+ reclist_leave(s->reclist);
}
#if USE_TIMING
yaz_timing_stop(t);
struct reclist_bucket *sorted_ptr;
struct reclist_bucket **last;
NMEM nmem;
+ YAZ_MUTEX mutex;
};
static struct reclist_sortparms *qsort_sortparms = 0; /* thread pr */
switch (s->type)
{
case Metadata_sortkey_relevance:
- res = r2->relevance - r1->relevance;
+ res = r2->relevance_score - r1->relevance_score;
break;
case Metadata_sortkey_string:
s1 = ut1 ? ut1->text.sort : "";
void reclist_sort(struct reclist *l, struct reclist_sortparms *parms)
{
+
struct reclist_bucket **flatlist = xmalloc(sizeof(*flatlist) * l->num_records);
- struct reclist_bucket *ptr = l->sorted_list;
- struct reclist_bucket **prev = &l->sorted_list;
+ struct reclist_bucket *ptr;
+ struct reclist_bucket **prev;
int i = 0;
+
+ reclist_enter(l);
+
+ ptr = l->sorted_list;
+ prev = &l->sorted_list;
while (ptr)
{
flatlist[i] = ptr;
xfree(flatlist);
- reclist_rewind(l);
+ reclist_leave(l);
}
struct record_cluster *reclist_read_record(struct reclist *l)
return 0;
}
-void reclist_rewind(struct reclist *l)
+void reclist_enter(struct reclist *l)
+{
+ yaz_mutex_enter(l->mutex);
+ if (l)
+ l->sorted_ptr = l->sorted_list;
+}
+
+
+void reclist_leave(struct reclist *l)
{
+ yaz_mutex_leave(l->mutex);
if (l)
l->sorted_ptr = l->sorted_list;
}
+
struct reclist *reclist_create(NMEM nmem)
{
struct reclist *res = nmem_malloc(nmem, sizeof(struct reclist));
res->last = &res->sorted_list;
res->num_records = 0;
+ res->mutex = 0;
+ yaz_mutex_create(&res->mutex);
return res;
}
+void reclist_destroy(struct reclist *l)
+{
+ yaz_mutex_destroy(&l->mutex);
+}
+
int reclist_get_num_records(struct reclist *l)
{
if (l)
bucket = jenkins_hash((unsigned char*) merge_key) % l->hash_size;
+ yaz_mutex_enter(l->mutex);
for (p = &l->hashtable[bucket]; *p; p = &(*p)->hnext)
{
// We found a matching record. Merge them
new->hnext = 0;
cluster->records = record;
cluster->merge_key = merge_key;
- cluster->relevance = 0;
+ cluster->relevance_score = 0;
cluster->term_frequency_vec = 0;
cluster->recid = merge_key;
(*total)++;
l->num_records++;
}
+ yaz_mutex_leave(l->mutex);
return cluster;
}
-
/*
* Local variables:
* c-basic-offset: 4
};
struct reclist *reclist_create(NMEM);
+void reclist_destroy(struct reclist *l);
struct record_cluster *reclist_insert( struct reclist *tl,
struct conf_service *service,
struct record *record,
char *merge_key, int *total);
void reclist_sort(struct reclist *l, struct reclist_sortparms *parms);
struct record_cluster *reclist_read_record(struct reclist *l);
-void reclist_rewind(struct reclist *l);
+void reclist_enter(struct reclist *l);
+void reclist_leave(struct reclist *l);
struct reclist_sortparms *reclist_parse_sortparms(NMEM nmem, const char *parms,
struct conf_service *service);
struct record_metadata **metadata;
union data_types **sortkeys;
char *merge_key;
- int relevance;
+ int relevance_score;
int *term_frequency_vec;
int *term_frequency_vec_tmp;
float *term_frequency_vecf;
int i;
float *idfvec = xmalloc(rel->vec_len * sizeof(float));
- reclist_rewind(reclist);
+ reclist_enter(reclist);
// Calculate document frequency vector for each term.
for (i = 1; i < rel->vec_len; i++)
{
#endif
relevance += 100000 * (termfreq * idfvec[t] + 0.0000005);
}
- rec->relevance = relevance;
+ rec->relevance_score = relevance;
}
- reclist_rewind(reclist);
+ reclist_leave(reclist);
xfree(idfvec);
}