~gz/ubuntu/wily/steam/new_rel_udev_rules

« back to all changes in this revision

Viewing changes to server/modules/keyword_index.pike

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2013-10-29 19:51:18 UTC
  • mfrom: (1.1.4) (0.1.4 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131029195118-b9bxciz5hwx5z459
Tags: 1:1.0.0.39-2ubuntu1
Add an epoch to the version number as there was an unrelated steam package
in the archive with a higher version number.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2004  Thomas Bopp, Thorsten Hampel, Ludger Merkens
2
 
 *
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.
7
 
 *
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.
12
 
 *
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
16
 
 * 
17
 
 * $Id: keyword_index.pike,v 1.4 2006/08/24 06:16:05 dbuese Exp $
18
 
 */
19
 
 
20
 
constant cvs_version="$Id: keyword_index.pike,v 1.4 2006/08/24 06:16:05 dbuese Exp $";
21
 
 
22
 
inherit "/kernel/secure_n_n";
23
 
 
24
 
#include <macros.h>
25
 
#include <attributes.h>
26
 
#include <exception.h>
27
 
#include <types.h>
28
 
#include <classes.h>
29
 
#include <events.h>
30
 
 
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.
35
 
 
36
 
/**
37
 
 * Initialize the module.
38
 
 *  
39
 
 */
40
 
void init_module()
41
 
{
42
 
    set_attribute(OBJ_DESC,"This module handles the keywords for each object");
43
 
}
44
 
 
45
 
/**
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.
49
 
 *  
50
 
 * @param  none
51
 
 * @return nothing
52
 
 * @author Ludger Merkens (balduin@upb.de)
53
 
 * @see    set_attribute
54
 
 * @see    query_attribute
55
 
 */
56
 
void install_module()
57
 
{
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,
63
 
                             ({ }), this(), 
64
 
                             CONTROL_ATTR_USER,
65
 
                             0,
66
 
                             EVENT_ATTRIBUTES_CHANGE));
67
 
}
68
 
 
69
 
/**
70
 
 * This function associates the CALLER with the keywords set within the
71
 
 * database, search ability is improved by creating an reverse index.
72
 
 *  
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
79
 
 */
80
 
mixed set_attribute(string|int key, mixed val)
81
 
{
82
 
    array(string)      keywords;
83
 
    object obj = CALLER->this();
84
 
    mixed values, valold;
85
 
    string v;
86
 
 
87
 
 
88
 
    if ( objectp(obj) && functionp(obj->query_attribute) &&
89
 
         obj->query_attribute(OBJ_VERSIONOF) ) {
90
 
      register( ({ }), obj); // delete entries for version
91
 
      return val; 
92
 
    }
93
 
    
94
 
    if ( key == OBJ_KEYWORDS ) {
95
 
        if (!arrayp(val))
96
 
            val = ({val});
97
 
        return register(val, obj);
98
 
    }
99
 
    else {
100
 
        return ::set_attribute(key, val);
101
 
    }
102
 
}
103
 
    
104
 
/**
105
 
 * This function retreives the keywords stored in the database for CALLER
106
 
 *  
107
 
 * @param    key - checked for OBJ_KEYWORDS
108
 
 * @return   keywords from the database
109
 
 * @author   Ludger Merkens (balduin@upb.de) 
110
 
 * @see      set_attribute
111
 
 * @see      /kernel/secure_mapping.lookup
112
 
 */
113
 
mixed query_attribute(string|int key)
114
 
{
115
 
    mixed res;
116
 
    
117
 
    if ( key == OBJ_KEYWORDS ) {
118
 
        object obj = CALLER->this();
119
 
        res = ::get_key(obj);
120
 
        return res;
121
 
    }
122
 
    return ::query_attribute(key);
123
 
}
124
 
 
125
 
/**
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 
132
 
 */
133
 
array(object) search_objects(string searchterm)
134
 
{
135
 
    //    LOG("keyword_index.pike search for "+searchterm);
136
 
    searchterm = replace(searchterm, "*", "%");
137
 
    mixed result = lookup(searchterm);
138
 
    if ( objectp(result) )
139
 
        return ({ result });
140
 
    else if ( !arrayp(result) )
141
 
        return ({ });
142
 
    return result;
143
 
}
144
 
 
145
 
/**
146
 
 * Get the identifier of this module. 
147
 
 *
148
 
 * @return  "index:keywords"
149
 
 * @author Ludger Merkens 
150
 
 */
151
 
string get_identifier() { return "index:keywords"; }
152
 
string get_table_name() { return "keyword_index"; }