From 6a3be08c0fb5c7ad1f14168435b3de51028945d2 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 4 Nov 2009 12:48:12 +0100 Subject: [PATCH] Deal with empty fields for ranking Avoid division by length=0 in relevance_countwords. --- src/relevance.c | 3 ++- test/test_http_18.res | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/relevance.c b/src/relevance.c index 072a894..c88676e 100644 --- a/src/relevance.c +++ b/src/relevance.c @@ -114,7 +114,8 @@ void relevance_countwords(struct relevance *r, struct record_cluster *cluster, for (i = 1; i < r->vec_len; i++) { - cluster->term_frequency_vecf[i] += (double) mult[i] / length; + if (length > 0) /* only add if non-empty */ + cluster->term_frequency_vecf[i] += (double) mult[i] / length; cluster->term_frequency_vec[i] += mult[i]; } diff --git a/test/test_http_18.res b/test/test_http_18.res index eb81bff..77b4469 100644 --- a/test/test_http_18.res +++ b/test/test_http_18.res @@ -8,15 +8,15 @@ 3 -OIL/GAS DRILLING -This database contains information on oil and gas drilling such as well name, operator, driller, location, depth, copies of logs run, permits, samples (cuttings, core), completion records -OIL/GAS DRILLING -This database contains information on oil and gas drilling such as well name, operator, driller, location, depth, copies of logs run, permits, samples (cuttings, core), completion records -1907-PRESENT +BIBLIOGRAPHY OF MAINE GEOLOGY +This data base is a computer based bibliography of marine geology. It allows searching by topic and geographic location, similar to GEOREF. It is currently under development to replace the printed Bibliography of Marine Geology +BIBLIOGRAPHY OF MAINE GEOLOGY +This data base is a computer based bibliography of marine geology. It allows searching by topic and geographic location, similar to GEOREF. It is currently under development to replace the printed Bibliography of Marine Geology +1692-PRESENT test-usersetting-2 data: -0 -title oil gas drilling author medium book +9416 +title bibliography of maine geology author medium book @@ -27,19 +27,19 @@ 1972-1978 test-usersetting-2 data: --2147483648 +0 title groundwater resource maps county series author medium book -BIBLIOGRAPHY OF MAINE GEOLOGY -This data base is a computer based bibliography of marine geology. It allows searching by topic and geographic location, similar to GEOREF. It is currently under development to replace the printed Bibliography of Marine Geology -BIBLIOGRAPHY OF MAINE GEOLOGY -This data base is a computer based bibliography of marine geology. It allows searching by topic and geographic location, similar to GEOREF. It is currently under development to replace the printed Bibliography of Marine Geology -1692-PRESENT +OIL/GAS DRILLING +This database contains information on oil and gas drilling such as well name, operator, driller, location, depth, copies of logs run, permits, samples (cuttings, core), completion records +OIL/GAS DRILLING +This database contains information on oil and gas drilling such as well name, operator, driller, location, depth, copies of logs run, permits, samples (cuttings, core), completion records +1907-PRESENT test-usersetting-2 data: -9416 -title bibliography of maine geology author medium book +0 +title oil gas drilling author medium book -- 1.7.10.4