<hit>
<md-title>How to program a computer, by Jack Collins</md-title>
<count>2</count> <!-- Number of merged records -->
+ <recid>6</recid>
</hit>
<hit>
<md-title>
Computer processing of dynamic images from an Anger scintillation camera :
the proceedings of a workshop /
</md-title>
+ <recid>2</recid>
</hit>
</show>
+record
+
+Retrieves a detailed record.
+
+Parameters: id -- record ID as provided by the show command
+
+Example:
+
+search.pz2?session=605047297&command=record&id=3
+
+Example output:
+
+<record>
+ <md-title>
+ The Puget Sound Region : a portfolio of thematic computer maps /
+ </md-title>
+ <md-date>1974</md-date>
+ <md-author>Mairs, John W.</md-author>
+ <md-subject>Cartography</md-subject>
+</record>
+
termlist
Retrieves term list(s)
<state>Client_Idle</state>
<diagnostic>0</diagnostic>
</term>
+
/*
- * $Id: http_command.c,v 1.13 2007-01-09 18:06:28 quinn Exp $
+ * $Id: http_command.c,v 1.14 2007-01-09 22:06:49 quinn Exp $
*/
#include <stdio.h>
http_send_response(c);
}
+static void write_metadata(WRBUF w, struct conf_service *service,
+ struct record_metadata **ml, int full)
+{
+ int imeta;
+
+ for (imeta = 0; imeta < service->num_metadata; imeta++)
+ {
+ struct conf_metadata *cmd = &service->metadata[imeta];
+ struct record_metadata *md;
+ if (!cmd->brief && !full)
+ continue;
+ for (md = ml[imeta]; md; md = md->next)
+ {
+ wrbuf_printf(w, "<md-%s>", cmd->name);
+ switch (cmd->type)
+ {
+ case Metadata_type_generic:
+ wrbuf_puts(w, md->data.text);
+ break;
+ case Metadata_type_year:
+ wrbuf_printf(w, "%d", md->data.year.year1);
+ if (md->data.year.year1 != md->data.year.year2)
+ wrbuf_printf(w, "-%d", md->data.year.year2);
+ break;
+ default:
+ wrbuf_puts(w, "[can't represent]");
+ }
+ wrbuf_printf(w, "</md-%s>", cmd->name);
+ }
+ }
+}
+
+static void cmd_record(struct http_channel *c)
+{
+ struct http_response *rs = c->response;
+ struct http_request *rq = c->request;
+ struct http_session *s = locate_session(rq, rs);
+ struct record_cluster *rec;
+ struct conf_service *service = global_parameters.server->service;
+ char *idstr = http_argbyname(rq, "id");
+ int id;
+
+ if (!s)
+ return;
+ if (!idstr)
+ {
+ error(rs, "417", "Must supply id", 0);
+ return;
+ }
+ wrbuf_rewind(c->wrbuf);
+ id = atoi(idstr);
+ if (!(rec = show_single(s->psession, id)))
+ {
+ error(rs, "500", "Record missing", 0);
+ return;
+ }
+ wrbuf_puts(c->wrbuf, "<record>\n");
+ write_metadata(c->wrbuf, service, rec->metadata, 1);
+ wrbuf_puts(c->wrbuf, "</record>\n");
+ rs->payload = nmem_strdup(c->nmem, wrbuf_buf(c->wrbuf));
+ http_send_response(c);
+}
+
static void show_records(struct http_channel *c, int active)
{
struct http_request *rq = c->request;
struct record *p;
struct record_cluster *rec = rl[i];
struct conf_service *service = global_parameters.server->service;
- int imeta;
wrbuf_puts(c->wrbuf, "<hit>\n");
- for (imeta = 0; imeta < service->num_metadata; imeta++)
- {
- struct conf_metadata *cmd = &service->metadata[imeta];
- struct record_metadata *md;
- if (!rec->metadata[imeta])
- continue;
- if (!cmd->brief)
- continue;
- for (md = rec->metadata[imeta]; md; md = md->next)
- {
- wrbuf_printf(c->wrbuf, "<md-%s>", cmd->name);
- switch (cmd->type)
- {
- case Metadata_type_generic:
- wrbuf_puts(c->wrbuf, md->data.text);
- break;
- case Metadata_type_year:
- wrbuf_printf(c->wrbuf, "%d", md->data.year.year1);
- if (md->data.year.year1 != md->data.year.year2)
- wrbuf_printf(c->wrbuf, "-%d", md->data.year.year2);
- break;
- default:
- wrbuf_puts(c->wrbuf, "[Can't represent]");
- }
- wrbuf_printf(c->wrbuf, "</md-%s>", cmd->name);
- }
- }
+ write_metadata(c->wrbuf, service, rec->metadata, 0);
for (ccount = 0, p = rl[i]->records; p; p = p->next, ccount++)
;
if (ccount > 1)
wrbuf_printf(c->wrbuf, "<count>%d</count>\n", ccount);
+ wrbuf_printf(c->wrbuf, "<recid>%d</recid>\n", rec->recid);
wrbuf_puts(c->wrbuf, "</hit>\n");
}
{ "termlist", cmd_termlist },
{ "exit", cmd_exit },
{ "ping", cmd_ping },
+ { "record", cmd_record },
{0,0}
};
-/* $Id: pazpar2.c,v 1.21 2007-01-09 18:06:28 quinn Exp $ */;
+/* $Id: pazpar2.c,v 1.22 2007-01-09 22:06:49 quinn Exp $ */;
#include <stdlib.h>
#include <stdio.h>
res = nmem_malloc(se->nmem, sizeof(struct record));
res->next = 0;
- res->target_offset = -1;
- res->term_frequency_vec = 0;
res->metadata = nmem_malloc(se->nmem,
sizeof(struct record_metadata*) * service->num_metadata);
bzero(res->metadata, sizeof(struct record_metadata*) * service->num_metadata);
- res->relevance = 0;
mergekey_norm = nmem_strdup(se->nmem, (char*) mergekey);
xmlFree(mergekey);
normalize_mergekey(mergekey_norm);
- cluster = reclist_insert(se->reclist, res, mergekey_norm);
+ cluster = reclist_insert(se->reclist, res, mergekey_norm, &se->total_merged);
if (!cluster)
{
/* no room for record */
se->reclist = reclist_create(se->nmem, maxrecs);
extract_terms(se->nmem, query, p);
se->relevance = relevance_create(se->nmem, (const char **) p, maxrecs);
- se->total_records = se->total_hits = 0;
+ se->total_records = se->total_hits = se->total_merged = 0;
se->expected_maxrecs = maxrecs;
}
else
}
#endif
+struct record_cluster *show_single(struct session *s, int id)
+{
+ struct record_cluster *r;
+
+ reclist_rewind(s->reclist);
+ while ((r = reclist_read_record(s->reclist)))
+ if (r->recid == id)
+ return r;
+ return 0;
+}
+
struct record_cluster **show(struct session *s, int start, int *num, int *total,
int *sumhits, NMEM nmem_show)
{
struct record {
struct client *client;
- int target_offset;
struct record_metadata **metadata; // Array mirrors list of metadata fields in config
- int relevance;
- int *term_frequency_vec;
- struct record *next;
+ struct record *next; // Next in cluster of merged records
};
struct record_cluster
char *merge_key;
int relevance;
int *term_frequency_vec;
+ int recid; // Set-specific ID for this record
struct record *records;
};
int expected_maxrecs;
int total_hits;
int total_records;
+ int total_merged;
};
struct statistics {
char *search(struct session *s, char *query);
struct record_cluster **show(struct session *s, int start, int *num, int *total,
int *sumhits, NMEM nmem_show);
+struct record_cluster *show_single(struct session *s, int id);
struct termlist_score **termlist(struct session *s, const char *name, int *num);
void session_set_watch(struct session *s, int what, session_watchfun fun, void *data);
int session_active_clients(struct session *s);
/*
- * $Id: reclists.c,v 1.4 2007-01-08 18:32:35 quinn Exp $
+ * $Id: reclists.c,v 1.5 2007-01-09 22:06:49 quinn Exp $
*/
#include <assert.h>
// Insert a record. Return record cluster (newly formed or pre-existing)
struct record_cluster *reclist_insert(struct reclist *l, struct record *record,
- char *merge_key)
+ char *merge_key, int *total)
{
unsigned int bucket;
struct reclist_bucket **p;
newc->merge_key = merge_key;
newc->relevance = 0;
newc->term_frequency_vec = 0;
+ newc->recid = (*total)++;
newc->metadata = 0;
newc->metadata = nmem_malloc(l->nmem,
sizeof(struct record_metadata*) * service->num_metadata);
struct reclist *reclist_create(NMEM, int numrecs);
struct record_cluster *reclist_insert(struct reclist *tl, struct record *record,
- char *merg_key);
+ char *merge_key, int *total);
struct record_cluster *reclist_read_record(struct reclist *l);
void reclist_rewind(struct reclist *l);