GPLv2. Added appendix with full license. Added refernece to that from
[pazpar2-moved-to-github.git] / src / relevance.c
index 75800a2..5e1fd76 100644 (file)
@@ -1,5 +1,22 @@
-/*
- * $Id: relevance.c,v 1.4 2007-01-08 12:43:41 adam Exp $
+/* $Id: relevance.c,v 1.9 2007-04-10 08:48:56 adam Exp $
+   Copyright (c) 2006-2007, Index Data.
+
+This file is part of Pazpar2.
+
+Pazpar2 is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Pazpar2; see the file LICENSE.  If not, write to the
+Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
  */
 
 #include <ctype.h>
@@ -121,25 +138,25 @@ struct relevance *relevance_create(NMEM nmem, const char **terms, int numrecs)
         ;
     res->vec_len = ++i;
     res->doc_frequency_vec = nmem_malloc(nmem, res->vec_len * sizeof(int));
-    bzero(res->doc_frequency_vec, res->vec_len * sizeof(int));
+    memset(res->doc_frequency_vec, 0, res->vec_len * sizeof(int));
     res->nmem = nmem;
     res->wt = build_word_trie(nmem, terms);
     return res;
 }
 
-void relevance_newrec(struct relevance *r, struct record *rec)
+void relevance_newrec(struct relevance *r, struct record_cluster *rec)
 {
     if (!rec->term_frequency_vec)
     {
         rec->term_frequency_vec = nmem_malloc(r->nmem, r->vec_len * sizeof(int));
-        bzero(rec->term_frequency_vec, r->vec_len * sizeof(int));
+        memset(rec->term_frequency_vec, 0, r->vec_len * sizeof(int));
     }
 }
 
 
 // FIXME. The definition of a word is crude here.. should support
 // some form of localization mechanism?
-void relevance_countwords(struct relevance *r, struct record *head,
+void relevance_countwords(struct relevance *r, struct record_cluster *cluster,
         const char *words, int multiplier)
 {
     while (*words)
@@ -155,28 +172,29 @@ void relevance_countwords(struct relevance *r, struct record *head,
         if ((res = word_trie_match(r->wt, words, &skipped)))
         {
             words += skipped;
-            head->term_frequency_vec[res] += multiplier;
+            cluster->term_frequency_vec[res] += multiplier;
         }
         else
         {
             while (*words && (c = raw_char(tolower(*words))) >= 0)
                 words++;
         }
-        head->term_frequency_vec[0]++;
+        cluster->term_frequency_vec[0]++;
     }
 }
 
-void relevance_donerecord(struct relevance *r, struct record *head)
+void relevance_donerecord(struct relevance *r, struct record_cluster *cluster)
 {
     int i;
 
     for (i = 1; i < r->vec_len; i++)
-        if (head->term_frequency_vec[i] > 0)
+        if (cluster->term_frequency_vec[i] > 0)
             r->doc_frequency_vec[i]++;
 
     r->doc_frequency_vec[0]++;
 }
 
+#ifdef GAGA
 #ifdef FLOAT_REL
 static int comp(const void *p1, const void *p2)
 {
@@ -194,13 +212,14 @@ static int comp(const void *p1, const void *p2)
 #else
 static int comp(const void *p1, const void *p2)
 {
-    struct record **r1 = (struct record **) p1;
-    struct record **r2 = (struct record **) p2;
+    struct record_cluster **r1 = (struct record_cluster **) p1;
+    struct record_cluster **r2 = (struct record_cluster **) p2;
     return (*r2)->relevance - (*r1)->relevance;
 }
 #endif
+#endif
 
-// Prepare for a relevance-sorted read of up to num entries
+// Prepare for a relevance-sorted read
 void relevance_prepare_read(struct relevance *rel, struct reclist *reclist)
 {
     int i;
@@ -218,7 +237,7 @@ void relevance_prepare_read(struct relevance *rel, struct reclist *reclist)
     for (i = 0; i < reclist->num_records; i++)
     {
         int t;
-        struct record *rec = reclist->flatlist[i];
+        struct record_cluster *rec = reclist->flatlist[i];
         float relevance;
         relevance = 0;
         for (t = 1; t < rel->vec_len; t++)
@@ -231,7 +250,9 @@ void relevance_prepare_read(struct relevance *rel, struct reclist *reclist)
         }
         rec->relevance = (int) (relevance * 100000);
     }
+#ifdef GAGA
     qsort(reclist->flatlist, reclist->num_records, sizeof(struct record*), comp);
+#endif
     reclist->pointer = 0;
     xfree(idfvec);
 }