1
/* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License as published by
5
* the Free Software Foundation; either version 2 of the License, or
6
* (at your option) any later version.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
* $Id: keyword_index.pike,v 1.4 2006/08/24 06:16:05 dbuese Exp $
20
constant cvs_version="$Id: keyword_index.pike,v 1.4 2006/08/24 06:16:05 dbuese Exp $";
22
inherit "/kernel/secure_n_n";
25
#include <attributes.h>
26
#include <exception.h>
31
//! This module stores keywords inside the database to allow the
32
//! search of objects by keywords. Thus the module maps keyword:object
33
//! in a database table. The function search_objects() searches
34
//! a given keyword inside the table.
37
* Initialize the module.
42
set_attribute(OBJ_DESC,"This module handles the keywords for each object");
46
* Called on installation of module, registers the keywords attribute
47
* of all classes to this module, to store the values in an indexed
48
* database table for fast lookup.
52
* @author Ludger Merkens (balduin@upb.de)
54
* @see query_attribute
58
LOG("install_module() inside keyword_index.pike !");
59
object factory = _Server->get_factory(CLASS_OBJECT);
60
array reg = factory->describe_attribute(OBJ_KEYWORDS);
61
factory->register_attribute(
62
Attributes.Attribute(OBJ_KEYWORDS, "keywords", CMD_TYPE_ARRAY,
66
EVENT_ATTRIBUTES_CHANGE));
70
* This function associates the CALLER with the keywords set within the
71
* database, search ability is improved by creating an reverse index.
73
* @param key - checked for OBJ_KEYWORDS
74
* @param mixed - the list of keywords to store for the caller
75
* @return (true|false)
76
* @author Ludger Merkens (balduin@upb.de)
77
* @see query_attribute
78
* @see /kernel/secure_mapping.register
80
mixed set_attribute(string|int key, mixed val)
82
array(string) keywords;
83
object obj = CALLER->this();
88
if ( objectp(obj) && functionp(obj->query_attribute) &&
89
obj->query_attribute(OBJ_VERSIONOF) ) {
90
register( ({ }), obj); // delete entries for version
94
if ( key == OBJ_KEYWORDS ) {
97
return register(val, obj);
100
return ::set_attribute(key, val);
105
* This function retreives the keywords stored in the database for CALLER
107
* @param key - checked for OBJ_KEYWORDS
108
* @return keywords from the database
109
* @author Ludger Merkens (balduin@upb.de)
111
* @see /kernel/secure_mapping.lookup
113
mixed query_attribute(string|int key)
117
if ( key == OBJ_KEYWORDS ) {
118
object obj = CALLER->this();
119
res = ::get_key(obj);
122
return ::query_attribute(key);
126
* executes a query in the database according to a search term
127
* 25.09.2001 replace * probably meant as wild card, with %
128
* to regard SQL Syntax
129
* @param string - search-term
130
* @return a list of objects
131
* @author Ludger Merkens
133
array(object) search_objects(string searchterm)
135
// LOG("keyword_index.pike search for "+searchterm);
136
searchterm = replace(searchterm, "*", "%");
137
mixed result = lookup(searchterm);
138
if ( objectp(result) )
140
else if ( !arrayp(result) )
146
* Get the identifier of this module.
148
* @return "index:keywords"
149
* @author Ludger Merkens
151
string get_identifier() { return "index:keywords"; }
152
string get_table_name() { return "keyword_index"; }