1 /* $Id: rankstatic.c,v 1.4 2006-03-30 09:52:15 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
35 static int log_level = 0;
36 static int log_initialized = 0;
38 struct rank_set_info {
43 * create: Creates/Initialises this rank handler. This routine is
44 * called exactly once. The routine returns the class_handle.
46 static void *create (ZebraHandle zh)
50 log_level = yaz_log_module_level("rankstatic");
53 yaz_log(log_level, "rank-static create");
58 * destroy: Destroys this rank handler. This routine is called
59 * when the handler is no longer needed - i.e. when the server
60 * dies. The class_handle was previously returned by create.
62 static void destroy (struct zebra_register *reg, void *class_handle)
64 yaz_log(log_level, "rank-static destroy");
69 * begin: Prepares beginning of "real" ranking. Called once for
70 * each result set. The returned handle is a "set handle" and
71 * will be used in each of the handlers below.
73 static void *begin (struct zebra_register *reg,
74 void *class_handle, RSET rset, NMEM nmem,
75 TERMID *terms, int numterms)
77 struct rank_set_info *si =
78 (struct rank_set_info *) nmem_malloc (nmem, sizeof(*si));
81 yaz_log(log_level, "rank-static begin");
82 /* count how many terms are ranked (2=102 or similar) */
83 si->no_rank_entries = 0;
84 for (i = 0; i < numterms; i++)
86 struct ord_list *ol = terms[i]->ol;
88 yaz_log(log_level, "i=%d flags=%s '%s'", i,
89 terms[i]->flags, terms[i]->name );
91 for (; ol; ol = ol->next)
95 const char *string_index = 0;
99 zebraExplain_lookup_ord(reg->zei,
100 ol->ord, &index_type, &db, &set, &use,
104 yaz_log(log_level, " ord=%d index_type=%c db=%s str-index=%s",
105 ol->ord, index_type, db, string_index);
107 yaz_log(log_level, " ord=%d index_type=%c db=%s set=%d use=%d",
108 ol->ord, index_type, db, set, use);
110 if (!strncmp (terms[i]->flags, "rank,", 5))
111 (si->no_rank_entries)++;
117 * end: Terminates ranking process. Called after a result set
120 static void end (struct zebra_register *reg, void *set_handle)
122 yaz_log(log_level, "rank-static end");
127 * add: Called for each word occurence in a result set. This routine
128 * should be as fast as possible. This routine should "incrementally"
131 static void add (void *set_handle, int seqno, TERMID term)
136 * calc: Called for each document in a result. This handler should
137 * produce a score based on previous call(s) to the add handler. The
138 * score should be between 0 and 1000. If score cannot be obtained
139 * -1 should be returned.
141 static int calc (void *set_handle, zint sysno, zint staticrank,
144 struct rank_set_info *si = (struct rank_set_info *) set_handle;
146 if (!si->no_rank_entries)
147 return -1; /* ranking not enabled for any terms */
149 /* if we set *stop_flag = 1, we stop processing (of result set list) */
150 /* staticrank = 0 is highest, MAXINT lowest */
151 return INT_MAX - staticrank; /* but score is reverse (logical) */
155 * Pseudo-meta code with sequence of calls as they occur in a
156 * server. Handlers are prefixed by --:
172 static struct rank_control rank_control = {
182 struct rank_control *rank_static_class = &rank_control;