From: Sebastian Hammer Date: Tue, 9 Jan 2007 22:06:49 +0000 (+0000) Subject: Added a full record view (not implemented in the test UI yet) X-Git-Tag: before.append.child~8 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=7c0b91839755ff1090d9ae90f846de9c66f04f6a;p=pazpar2-moved-to-github.git Added a full record view (not implemented in the test UI yet) --- diff --git a/PROTOCOL b/PROTOCOL index 0999252..2608c38 100644 --- a/PROTOCOL +++ b/PROTOCOL @@ -111,15 +111,38 @@ Output: How to program a computer, by Jack Collins 2 + 6 Computer processing of dynamic images from an Anger scintillation camera : the proceedings of a workshop / + 2 +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: + + + + The Puget Sound Region : a portfolio of thematic computer maps / + + 1974 + Mairs, John W. + Cartography + + termlist Retrieves term list(s) @@ -166,3 +189,4 @@ returned in place of 'name'. This may or may not change later. Client_Idle 0 + diff --git a/src/http_command.c b/src/http_command.c index 8f4b9b8..edd6425 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1,5 +1,5 @@ /* - * $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 @@ -270,6 +270,69 @@ static void cmd_bytarget(struct http_channel *c) 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, "", 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, "", 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, "\n"); + write_metadata(c->wrbuf, service, rec->metadata, 1); + wrbuf_puts(c->wrbuf, "\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; @@ -314,40 +377,14 @@ static void show_records(struct http_channel *c, int active) struct record *p; struct record_cluster *rec = rl[i]; struct conf_service *service = global_parameters.server->service; - int imeta; wrbuf_puts(c->wrbuf, "\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, "", 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, "", 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, "%d\n", ccount); + wrbuf_printf(c->wrbuf, "%d\n", rec->recid); wrbuf_puts(c->wrbuf, "\n"); } @@ -473,6 +510,7 @@ struct { { "termlist", cmd_termlist }, { "exit", cmd_exit }, { "ping", cmd_ping }, + { "record", cmd_record }, {0,0} }; diff --git a/src/pazpar2.c b/src/pazpar2.c index 8ee4ea9..b5a0ee7 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -1,4 +1,4 @@ -/* $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 #include @@ -478,18 +478,15 @@ static struct record *ingest_record(struct client *cl, Z_External *rec) 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 */ @@ -1215,7 +1212,7 @@ char *search(struct session *se, char *query) 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 @@ -1304,6 +1301,17 @@ void report_nmem_stats(void) } #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) { diff --git a/src/pazpar2.h b/src/pazpar2.h index 4d8a16d..b075232 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -33,11 +33,8 @@ struct record_metadata { 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 @@ -46,6 +43,7 @@ struct record_cluster char *merge_key; int relevance; int *term_frequency_vec; + int recid; // Set-specific ID for this record struct record *records; }; @@ -144,6 +142,7 @@ struct session { int expected_maxrecs; int total_hits; int total_records; + int total_merged; }; struct statistics { @@ -195,6 +194,7 @@ void statistics(struct session *s, struct statistics *stat); 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); diff --git a/src/reclists.c b/src/reclists.c index 1f0350b..27a48f4 100644 --- a/src/reclists.c +++ b/src/reclists.c @@ -1,5 +1,5 @@ /* - * $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 @@ -75,7 +75,7 @@ struct reclist *reclist_create(NMEM nmem, int numrecs) // 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; @@ -109,6 +109,7 @@ struct record_cluster *reclist_insert(struct reclist *l, struct record *record, 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); diff --git a/src/reclists.h b/src/reclists.h index cca3e42..6a03d77 100644 --- a/src/reclists.h +++ b/src/reclists.h @@ -17,7 +17,7 @@ struct reclist 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);