forked from pacew/apply
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkindex
executable file
·77 lines (58 loc) · 1.97 KB
/
mkindex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /usr/bin/php
<?php
require_once ("cli.php");
$dbparams['dbtype'] = "mysql";
$dbparams['host'] = 'neffaprog.neffa.dreamhosters.com';
$dbparams['user'] = 'pace_willisson';
$dbparams['password'] = trim (file_get_contents (".neffadb_passwd"));
function make_index ($db) {
global $index;
$index = (object)NULL;
$perfs = array ();
$by_soundex = array ();
$groups = array ();
$q = query_db ($db,
"select p.number, p.performerName, p.isGroup"
." from performers p"
." order by p.number");
while (($r = fetch ($q)) != NULL) {
$p = (object)NULL;
$p->id = intval ($r->number);
$perfs[$p->id] = $p;
$p->name = $r->performerName;
if ($r->isGroup == "Y")
$p->group = 1;
$words = preg_split ('/[\s,]+/', strtolower ($p->name));
sort ($words);
$p->norm = implode (" ", $words);
foreach ($words as $word) {
$s = soundex ($word);
if (! isset ($by_soundex[$s]))
$by_soundex[$s] = array ();
$by_soundex[$s][] = $p->id;
}
}
$q = query_db ($db,
"select groupNumber, memberNumber, type"
." from members");
while (($r = fetch ($q)) != NULL) {
$group_number = intval ($r->groupNumber);
$member_number = intval ($r->memberNumber);
$contact_flag = $r->type;
if ($contact_flag == "C")
$member_number = - $member_number;
if (! isset ($groups[$group_number])) {
$groups[$group_number] = array ();
}
$groups[$group_number][] = $member_number;
}
$index = (object)NULL;
$index->perfs = $perfs;
$index->by_soundex = $by_soundex;
$index->groups = $groups;
}
$db = get_db ("neffa_pdb", $dbparams);
make_index ($db);
$output = "/tmp/neffa_idx.json";
file_put_contents ($output, json_encode ($index, JSON_PRETTY_PRINT));
printf ("output in %s\n", $output);