]> mj.ucw.cz Git - libucw.git/commitdiff
Added support for indexing/searching by custom attributes.
authorMartin Mares <mj@ucw.cz>
Sat, 20 Apr 2002 14:37:39 +0000 (14:37 +0000)
committerMartin Mares <mj@ucw.cz>
Sat, 20 Apr 2002 14:37:39 +0000 (14:37 +0000)
See the CUSTOM_ATTRS macro in lib/custom.h for an explanation.

lib/Makefile
lib/config.h
lib/custom.c [new file with mode: 0644]
lib/custom.h
lib/index.h

index 2c93e1cfdf770c3f1c6011c9129fc9f97bb0be28..6c8ec22083e006ad5a23f7df60f30afc26da2328 100644 (file)
@@ -8,7 +8,7 @@ SHLIB_OBJS=alloc.o alloc_str.o ctmatch.o db.o fastbuf.o fb-file.o fb-mem.o lists
        prime.o random.o realloc.o regex.o timer.o url.o wildmatch.o \
        wordsplit.o str_ctype.o str_upper.o bucket.o conf.o object.o sorter.o \
        finger.o proctitle.o ipaccess.o profile.o bitsig.o randomkey.o \
-       hash-string.o hash-istring.o
+       hash-string.o hash-istring.o custom.o
 
 obj/lib/libsh.a: $(addprefix obj/lib/,$(SHLIB_OBJS))
 
index 66cc25a020295224912d5924a45e91a2786f631d..0cee3ffe02f54693aa16e25e9c30c0349400ec72 100644 (file)
@@ -7,10 +7,9 @@
 #ifndef _SHERLOCK_CONFIG_H
 #define _SHERLOCK_CONFIG_H
 
-/* Custom configuration */
+/* Configuration switches */
 
 #include "lib/autoconf.h"
-#include "lib/custom.h"
 
 /* Version */
 
@@ -42,6 +41,10 @@ typedef unsigned int sh_time_t;              /* Timestamp */
 
 typedef u32 oid_t;                     /* Object ID */
 
+/* Custom stuff */
+
+#include "lib/custom.h"
+
 /* Data types and functions for accessing file positions */
 
 #ifdef SHERLOCK_CONFIG_LARGE_DB
diff --git a/lib/custom.c b/lib/custom.c
new file mode 100644 (file)
index 0000000..cba8412
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ *     Sherlock: Custom Parts of Configuration
+ *
+ *     (c) 2001--2002 Martin Mares <mj@ucw.cz>
+ */
+
+#include "lib/lib.h"
+#include "lib/index.h"
+
+#include <stdlib.h>
+
+#if 0          /* Example */
+
+void
+custom_get_lm(struct card_attr *ca, byte *attr)
+{
+  if (attr)
+    ca->lm = atol(attr);
+  else
+    ca->lm = 0;
+}
+
+byte *
+custom_parse_lm(u32 *dest, byte *value, uns intval)
+{
+  if (value)
+    return "LM is an integer, not a string";
+  *dest = intval;
+  return NULL;
+}
+
+#endif
index 2244dd848a5c532cfc4b6429752472a7db086fac..f4a57115aae467872ce9fd6d65507fba28f0fe1a 100644 (file)
@@ -1,19 +1,13 @@
 /*
  *     Sherlock: Custom Parts of Configuration
  *
- *     (c) 2001 Martin Mares <mj@ucw.cz>
+ *     (c) 2001--2002 Martin Mares <mj@ucw.cz>
  */
 
 /* Name of this customization (version suffix) */
 
 #define SHER_SUFFIX ""
 
-/* Features */
-
-#define  SHERLOCK_CONFIG_LARGE_DB      /* Support for DB files >4GB */
-#define  SHERLOCK_CONFIG_LFS           /* Large files on 32-bit systems */
-#define  SHERLOCK_CONFIG_LFS_LIBC      /* LFS supported directly by libc */
-
 /* Word types */
 
 enum word_type {
@@ -84,3 +78,38 @@ enum string_type {
 #define STRING_TYPES_URL ((1 << ST_URL) | (1 << ST_REF) | (1 << ST_BACKREF))
 /* These must be indexed in lowercase form */
 #define STRING_TYPES_CASE_INSENSITIVE ((1 << ST_HOST) | (1 << ST_DOMAIN))
+
+/*
+ *  Definitions of custom attributes:
+ *
+ *  INT_ATTR(type, id, oattr, keyword, get_func, parse_func)
+ *
+ *  type       data type used to hold the value
+ *  id         C identifier of the attribute
+ *  oattr      object attribute we get the value from
+ *  keywd      search server keyword for the attribute
+ *  void get_func(struct card_attr *ca, byte *attr)
+ *             parse object attribute (may be NULL)
+ *  byte *parse_func(u32 *dest, byte *value, uns intval)
+ *             parse value in query (returns error message or NULL)
+ *             for KEYWD = "string", it gets value="string", intval=0
+ *             for KEYWD = num, it gets value=NULL, intval=num.
+ *
+ *  A good place for definitions of the functions is lib/custom.c.
+ *
+ *  Please order the attributes by decreasing size to get optimum padding.
+ */
+
+#if 0          /* Example */
+
+#define CUSTOM_ATTRS INT_ATTR(u32, lm, 'L', LM, custom_get_lm, custom_parse_lm)
+
+struct card_attr;
+void custom_get_lm(struct card_attr *ca, byte *attr);
+byte *custom_parse_lm(u32 *dest, byte *value, uns intval);
+
+#else
+
+#define CUSTOM_ATTRS
+
+#endif
index 0bd9a63583a1b26df843c02394ced78b28efbf5c..dc8dab1a8a331007ecc1bb54072870c4c28e130b 100644 (file)
 struct card_attr {
   u32 card;                            /* Reference to card description (either oid or filepos) */
   u32 site_id;
+#define INT_ATTR(t,i,o,k,g,p) t i;
+  CUSTOM_ATTRS                         /* Include all custom attributes */
+#undef INT_ATTR
   byte weight;
   byte flags;
-  byte rfu[2];
+  // byte rfu[2];                      /* If no custom attributes are defined */
 };
 
 enum card_flag {