cb8df1ea85ca9db9dd310a83aec170753d7cae0e
[pazpar2-moved-to-github.git] / src / record.h
1 /* This file is part of Pazpar2.
2    Copyright (C) Index Data
3
4 Pazpar2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 */
19
20 #ifndef RECORD_H
21 #define RECORD_H
22
23
24 struct client;
25 struct conf_service;
26
27 union data_types {
28     struct {
29         const char *disp;
30         const char *sort;
31         const char *snippet;
32     } text;
33     struct {
34         int min;
35         int max;
36     } number;
37     double fnumber;
38 };
39
40
41 struct record_metadata_attr {
42     char *name;
43     char *value;
44     struct record_metadata_attr *next;
45 };
46
47 struct record_metadata {
48     union data_types data;
49     // next item of this name
50     struct record_metadata *next;
51     struct record_metadata_attr *attributes;
52 };
53
54 union data_types * data_types_assign(NMEM nmem,
55                                      union data_types ** data1,
56                                      union data_types data2);
57
58
59 struct record {
60     struct client *client;
61     // Array mirrors list of metadata fields in config
62     struct record_metadata **metadata;
63     // Array mirrors list of sortkey fields in config
64     union data_types **sortkeys;
65     // Next in cluster of merged records
66     struct record *next;
67     // client result set position;
68     int position;
69     // score for ranking, either native or our TF/IDF, or other
70     double score;
71     // checksum
72     unsigned checksum;
73 };
74
75
76 struct record * record_create(NMEM nmem, int num_metadata, int num_sortkeys,
77                               struct client *client, int position);
78
79 struct record_metadata * record_metadata_create(NMEM nmem);
80
81 int record_compare(struct record *r1, struct record *r2, struct conf_service *service);
82
83 struct record_cluster
84 {
85     // Array mirrors list of metadata fields in config
86     struct record_metadata **metadata;
87     union data_types **sortkeys;
88     // char *merge_key;
89     struct record_metadata_attr *merge_keys;
90
91     int relevance_score;
92     int *term_frequency_vec;
93     float *term_frequency_vecf;
94     // Set-specific ID for this record
95     char *recid;
96     WRBUF relevance_explain1;
97     WRBUF relevance_explain2;
98     struct record *records;
99     struct record_cluster *sorted_next;
100     struct reclist_sortparms *sort_parms;
101 };
102
103 #endif // RECORD_H
104
105 /*
106  * Local variables:
107  * c-basic-offset: 4
108  * c-file-style: "Stroustrup"
109  * indent-tabs-mode: nil
110  * End:
111  * vim: shiftwidth=4 tabstop=8 expandtab
112  */
113