log_search.py
changeset 74 1ab95857d584
parent 68 8157c41b3236
child 87 39915772f090
equal deleted inserted replaced
73:5a7188bf2894 74:1ab95857d584
     5 import datetime, calendar, pytz
     5 import datetime, calendar, pytz
     6 
     6 
     7 import HyperEstraier as hype
     7 import HyperEstraier as hype
     8 
     8 
     9 import log_line
     9 import log_line
       
    10 
       
    11 class LogSearchError (Exception) :
       
    12     """
       
    13         General search error
       
    14     """
       
    15 
       
    16     pass
       
    17 
       
    18 class NoResultsFound (LogSearchError) :
       
    19     """
       
    20         No results found
       
    21     """
       
    22 
       
    23     pass
    10 
    24 
    11 class LogSearchIndex (object) :
    25 class LogSearchIndex (object) :
    12     """
    26     """
    13         An index on the logs for a group of channels.
    27         An index on the logs for a group of channels.
    14 
    28 
   109         # return
   123         # return
   110         return count
   124         return count
   111 
   125 
   112     def search_cond (self, cond) :
   126     def search_cond (self, cond) :
   113         """
   127         """
   114             Search using a raw hype.Condition
   128             Search using a raw hype.Condition. Raises NoResultsFound if there aren't any results
   115         """
   129         """
   116 
   130 
   117         # execute search, unused 'flags' arg stays zero
   131         # execute search, unused 'flags' arg stays zero
   118         results = self.db.search(cond, 0)
   132         results = self.db.search(cond, 0)
       
   133 
       
   134         # no results?
       
   135         if not results :
       
   136             raise NoResultsFound()
   119 
   137 
   120         # iterate over the document IDs
   138         # iterate over the document IDs
   121         for doc_id in results :
   139         for doc_id in results :
   122             # load document, this throws an exception...
   140             # load document, this throws an exception...
   123             # option constants are hype.Database.GDNOATTR/GDNOTEXT
   141             # option constants are hype.Database.GDNOATTR/GDNOTEXT