author | Tero Marttila <terom@fixme.fi> |
Wed, 11 Feb 2009 00:33:21 +0200 | |
changeset 89 | 2dc6de43f317 |
parent 87 | 39915772f090 |
child 93 | 48fca00689e3 |
permissions | -rw-r--r-- |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
1 |
""" |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
2 |
Full-text searching of logs |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
3 |
""" |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
4 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
5 |
import datetime, calendar, pytz |
87
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
6 |
import os.path |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
7 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
8 |
import HyperEstraier as hype |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
9 |
|
89
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
10 |
import log_line, utils |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
11 |
|
74
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
12 |
class LogSearchError (Exception) : |
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
13 |
""" |
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
14 |
General search error |
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
15 |
""" |
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
16 |
|
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
17 |
pass |
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
18 |
|
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
19 |
class NoResultsFound (LogSearchError) : |
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
20 |
""" |
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
21 |
No results found |
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
22 |
""" |
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
23 |
|
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
24 |
pass |
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
25 |
|
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
26 |
class LogSearchIndex (object) : |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
27 |
""" |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
28 |
An index on the logs for a group of channels. |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
29 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
30 |
This uses Hyper Estraier to handle searching, whereby each log line is a document (yes, I have a powerful server). |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
31 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
32 |
These log documents have the following attributes: |
89
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
33 |
@uri - channel/date/line |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
34 |
channel - channel code |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
35 |
type - the LogType id |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
36 |
timestamp - UTC timestamp |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
37 |
source_nickname - source nickname |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
38 |
source_username - source username |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
39 |
source_hostname - source hostname |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
40 |
source_chanflags - source channel flags |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
41 |
target_nickname - target nickname |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
42 |
|
89
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
43 |
Each document then has a single line of data, which is the log data message |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
44 |
""" |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
45 |
|
87
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
46 |
def __init__ (self, channels, path, mode='r') : |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
47 |
""" |
87
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
48 |
Open the database at the given path, with the given mode: |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
49 |
r - read-only |
87
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
50 |
w - write, create if not exists |
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
51 |
a - write, error if not exists |
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
52 |
c - write, create, error if exists |
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
53 |
* - write, create, truncate if exists |
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
54 |
|
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
55 |
Channels is the ChannelList. |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
56 |
""" |
87
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
57 |
|
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
58 |
# store |
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
59 |
self.channels = channels |
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
60 |
self.path = path |
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
61 |
self.mode = mode |
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
62 |
|
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
63 |
# check it does not already exist? |
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
64 |
if mode in 'c' and os.path.exists(path) : |
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
65 |
raise LogSearchError("Index already exists: %s" % (path, )) |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
66 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
67 |
# mapping of { mode -> flags } |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
68 |
mode_to_flag = { |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
69 |
'r': hype.Database.DBREADER, |
67
13975aa16b4c
fix LogSearchIndex open permissions
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
70 |
'w': hype.Database.DBWRITER | hype.Database.DBCREAT, |
13975aa16b4c
fix LogSearchIndex open permissions
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
71 |
'a': hype.Database.DBWRITER, |
87
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
72 |
'c': hype.Database.DBWRITER | hype.Database.DBCREAT, |
67
13975aa16b4c
fix LogSearchIndex open permissions
Tero Marttila <terom@fixme.fi>
parents:
66
diff
changeset
|
73 |
'*': hype.Database.DBWRITER | hype.Database.DBCREAT | hype.Database.DBTRUNC, |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
74 |
} |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
75 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
76 |
# look up flags |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
77 |
flags = mode_to_flag[mode] |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
78 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
79 |
# make instance |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
80 |
self.db = hype.Database() |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
81 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
82 |
# open |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
83 |
if not self.db.open(path, flags) : |
65 | 84 |
raise Exception("Index open failed: %s, mode=%s, flags=%#06x: %s" % (path, mode, flags, self.db.err_msg(self.db.error()))) |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
85 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
86 |
def insert (self, channel, lines) : |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
87 |
""" |
68 | 88 |
Adds a sequence of LogLines from the given LogChannel to the index, and return the number of added items |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
89 |
""" |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
90 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
91 |
# validate the LogChannel |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
92 |
assert channel.name |
68 | 93 |
|
94 |
count = 0 |
|
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
95 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
96 |
# iterate |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
97 |
for line in lines : |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
98 |
# validate the LogLine |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
99 |
assert line.offset |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
100 |
assert line.timestamp |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
101 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
102 |
# create new document |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
103 |
doc = hype.Document() |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
104 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
105 |
# line date |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
106 |
date = line.timestamp.date() |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
107 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
108 |
# ensure that it's not 1900 |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
109 |
assert date.year != 1900 |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
110 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
111 |
# add URI |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
112 |
doc.add_attr('@uri', "%s/%s/%d" % (channel.id, date.strftime('%Y-%m-%d'), line.offset)) |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
113 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
114 |
# add channel id |
87
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
115 |
doc.add_attr('channel', channel.id) |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
116 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
117 |
# add type |
87
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
118 |
doc.add_attr('type', str(line.type)) |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
119 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
120 |
# add UTC timestamp |
89
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
121 |
doc.add_attr('timestamp', str(utils.to_utc_timestamp(line.timestamp))) |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
122 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
123 |
# add source attribute? |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
124 |
if line.source : |
87
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
125 |
source_nickname, source_username, source_hostname, source_chanflags = line.source |
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
126 |
|
89
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
127 |
if source_nickname : |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
128 |
doc.add_attr('source_nickname', source_nickname.encode('utf8')) |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
129 |
|
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
130 |
if source_username : |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
131 |
doc.add_attr('source_username', source_username.encode('utf8')) |
87
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
132 |
|
89
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
133 |
if source_hostname : |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
134 |
doc.add_attr('source_hostname', source_hostname.encode('utf8')) |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
135 |
|
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
136 |
if source_chanflags : |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
137 |
doc.add_attr('source_chanflags', source_chanflags.encode('utf8')) |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
138 |
|
89
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
139 |
# add target attributes? |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
140 |
if line.target : |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
141 |
target_nickname = line.target |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
142 |
|
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
143 |
if target_nickname : |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
144 |
doc.add_attr('target_nickname', target_nickname.encode('utf8')) |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
145 |
|
87
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
146 |
# add data |
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
147 |
if line.data : |
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
148 |
doc.add_text(line.data.encode('utf8')) |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
149 |
|
87
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
150 |
# put, "clean up dispensable regions of the overwritten document" |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
151 |
if not self.db.put_doc(doc, hype.Database.PDCLEAN) : |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
152 |
raise Exeception("Index put_doc failed") |
68 | 153 |
|
154 |
# count |
|
155 |
count += 1 |
|
156 |
||
157 |
# return |
|
158 |
return count |
|
159 |
||
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
160 |
def search_cond (self, cond) : |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
161 |
""" |
74
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
162 |
Search using a raw hype.Condition. Raises NoResultsFound if there aren't any results |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
163 |
""" |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
164 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
165 |
# execute search, unused 'flags' arg stays zero |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
166 |
results = self.db.search(cond, 0) |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
167 |
|
74
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
168 |
# no results? |
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
169 |
if not results : |
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
170 |
raise NoResultsFound() |
1ab95857d584
handle the 'no search results' case
Tero Marttila <terom@fixme.fi>
parents:
68
diff
changeset
|
171 |
|
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
172 |
# iterate over the document IDs |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
173 |
for doc_id in results : |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
174 |
# load document, this throws an exception... |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
175 |
# option constants are hype.Database.GDNOATTR/GDNOTEXT |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
176 |
doc = self.db.get_doc(doc_id, 0) |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
177 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
178 |
# load the attributes/text |
87
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
179 |
channel = self.channels.lookup(doc.attr('channel')) |
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
180 |
type = int(doc.attr('type')) |
89
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
181 |
timestamp = utils.from_utc_timestamp(int(doc.attr('timestamp'))) |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
182 |
|
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
183 |
# source |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
184 |
source = (doc.attr('source_nickname'), doc.attr('source_username'), doc.attr('source_hostname'), doc.attr('source_chanflags')) |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
185 |
|
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
186 |
# target |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
187 |
target = doc.attr('target_nickname') |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
188 |
|
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
189 |
# message text |
87
39915772f090
update LogSearchIndex to use new LogLine fields
Tero Marttila <terom@fixme.fi>
parents:
74
diff
changeset
|
190 |
message = doc.cat_texts().decode('utf8') |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
191 |
|
66
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
192 |
# build+yield to as LogLine |
89
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
193 |
yield log_line.LogLine(channel, None, type, timestamp, source, target, message) |
66
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
194 |
|
89
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
195 |
def search (self, options=None, channel=None, attrs=None, phrase=None, order=None, max=None, skip=None) : |
66
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
196 |
""" |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
197 |
Search with flexible parameters |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
198 |
|
66
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
199 |
options - bitmask of hype.Condition.* |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
200 |
channel - LogChannel object |
89
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
201 |
attrs - raw attribute expressions |
66
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
202 |
phrase - the search query phrase |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
203 |
order - order attribute expression |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
204 |
max - number of results to return |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
205 |
skip - number of results to skip |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
206 |
""" |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
207 |
|
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
208 |
# build condition |
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
209 |
cond = hype.Condition() |
66
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
210 |
|
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
211 |
if options : |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
212 |
# set options |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
213 |
cond.set_options(options) |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
214 |
|
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
215 |
if channel : |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
216 |
# add channel attribute |
89
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
217 |
cond.add_attr("channel STREQ %s" % (channel.id, )) |
66
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
218 |
|
89
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
219 |
if attrs : |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
220 |
# add attributes |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
221 |
for attr in attrs : |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
222 |
cond.add_attr(attr) |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
223 |
|
66
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
224 |
if phrase : |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
225 |
# add phrase |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
226 |
cond.set_phrase(phrase) |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
227 |
|
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
228 |
if order : |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
229 |
# set order |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
230 |
cond.set_order(order) |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
231 |
|
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
232 |
if max : |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
233 |
# set max |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
234 |
cond.set_max(max) |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
235 |
|
66
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
236 |
if skip : |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
237 |
# set skip |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
238 |
cond.set_skip(skip) |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
239 |
|
66
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
240 |
# execute |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
241 |
return self.search_cond(cond) |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
242 |
|
66
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
243 |
def search_simple (self, channel, query, count=None, offset=None) : |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
244 |
""" |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
245 |
Search for lines from the given channel for the given simple query |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
246 |
""" |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
247 |
|
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
248 |
# use search(), backwards |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
249 |
results = list(self.search( |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
250 |
# simplified phrase |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
251 |
options = hype.Condition.SIMPLE, |
64
cdb6403c2498
beginnings of a LogSearchIndex class
Tero Marttila <terom@fixme.fi>
parents:
diff
changeset
|
252 |
|
66
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
253 |
# specific channel |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
254 |
channel = channel, |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
255 |
|
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
256 |
# given phrase |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
257 |
phrase = query, |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
258 |
|
89
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
259 |
# order by timestamp, descending (backwards) |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
260 |
order = "timestamp NUMD", |
66
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
261 |
|
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
262 |
# count/offset |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
263 |
max = count, |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
264 |
skip = offset, |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
265 |
)) |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
266 |
|
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
267 |
# reverse |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
268 |
return reversed(results) |
090ed78ec8fa
add count/skip to search results, requires modifications to the swig bindings for HyperEstraier...
Tero Marttila <terom@fixme.fi>
parents:
65
diff
changeset
|
269 |
|
89
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
270 |
def list (self, channel, date, count=None, skip=None) : |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
271 |
""" |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
272 |
List all indexed log items for the given UTC date |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
273 |
""" |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
274 |
|
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
275 |
# start/end dates |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
276 |
dt_start = datetime.datetime(date.year, date.month, date.day, 0, 0, 0, 0) |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
277 |
dt_end = datetime.datetime(date.year, date.month, date.day, 23, 23, 59, 999999) |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
278 |
|
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
279 |
# search |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
280 |
return self.search( |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
281 |
# specific channel |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
282 |
channel = channel, |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
283 |
|
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
284 |
# specific date range |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
285 |
attrs = [ |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
286 |
"timestamp NUMBT %d %d" % (utils.to_utc_timestamp(dt_start), utils.to_utc_timestamp(dt_end)) |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
287 |
], |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
288 |
|
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
289 |
# order correctly |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
290 |
order = "timestamp NUMA", |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
291 |
|
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
292 |
# max count/offset |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
293 |
max = count, |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
294 |
skip = skip |
2dc6de43f317
add utils.to/from_utc_timestamp functions, fix LogSearchIndex to store all LogLine attributes, add list() method to get LogLines for a given date, and improve scripts/search-index
Tero Marttila <terom@fixme.fi>
parents:
87
diff
changeset
|
295 |
) |