1 /* $Id: rankstatic.c,v 1.1 2005-08-19 09:21:34 adam Exp $
2 Copyright (C) 1995-2005
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
34 static int log_level = 0;
35 static int log_initialized = 0;
37 struct rank_set_info {
42 * create: Creates/Initialises this rank handler. This routine is
43 * called exactly once. The routine returns the class_handle.
45 static void *create (ZebraHandle zh)
49 log_level = yaz_log_module_level("rankstatic");
52 yaz_log(log_level, "rank-static create");
57 * destroy: Destroys this rank handler. This routine is called
58 * when the handler is no longer needed - i.e. when the server
59 * dies. The class_handle was previously returned by create.
61 static void destroy (struct zebra_register *reg, void *class_handle)
63 yaz_log(log_level, "rank-static destroy");
68 * begin: Prepares beginning of "real" ranking. Called once for
69 * each result set. The returned handle is a "set handle" and
70 * will be used in each of the handlers below.
72 static void *begin (struct zebra_register *reg,
73 void *class_handle, RSET rset, NMEM nmem,
74 TERMID *terms, int numterms)
76 struct rank_set_info *si =
77 (struct rank_set_info *) nmem_malloc (nmem, sizeof(*si));
80 yaz_log(log_level, "rank-static begin");
81 /* count how many terms are ranked (2=102 or similar) */
82 si->no_rank_entries = 0;
83 for (i = 0; i < numterms; i++)
85 yaz_log(log_level, "i=%d flags=%s '%s'", i,
86 terms[i]->flags, terms[i]->name );
87 if (!strncmp (terms[i]->flags, "rank,", 5))
88 (si->no_rank_entries)++;
94 * end: Terminates ranking process. Called after a result set
97 static void end (struct zebra_register *reg, void *set_handle)
99 yaz_log(log_level, "rank-static end");
104 * add: Called for each word occurence in a result set. This routine
105 * should be as fast as possible. This routine should "incrementally"
108 static void add (void *set_handle, int seqno, TERMID term)
113 * calc: Called for each document in a result. This handler should
114 * produce a score based on previous call(s) to the add handler. The
115 * score should be between 0 and 1000. If score cannot be obtained
116 * -1 should be returned.
118 static int calc (void *set_handle, zint sysno, zint staticrank)
120 struct rank_set_info *si = (struct rank_set_info *) set_handle;
122 if (!si->no_rank_entries)
123 return -1; /* ranking not enabled for any terms */
125 return staticrank+10;
129 * Pseudo-meta code with sequence of calls as they occur in a
130 * server. Handlers are prefixed by --:
146 static struct rank_control rank_control = {
156 struct rank_control *rank_static_class = &rank_control;