log_search.py
changeset 68 8157c41b3236
parent 67 13975aa16b4c
child 74 1ab95857d584
equal deleted inserted replaced
67:13975aa16b4c 68:8157c41b3236
    51         if not self.db.open(path, flags) :
    51         if not self.db.open(path, flags) :
    52             raise Exception("Index open failed: %s, mode=%s, flags=%#06x: %s" % (path, mode, flags, self.db.err_msg(self.db.error())))
    52             raise Exception("Index open failed: %s, mode=%s, flags=%#06x: %s" % (path, mode, flags, self.db.err_msg(self.db.error())))
    53 
    53 
    54     def insert (self, channel, lines) :
    54     def insert (self, channel, lines) :
    55         """
    55         """
    56             Adds a sequence of LogLines from the given LogChannel to the index
    56             Adds a sequence of LogLines from the given LogChannel to the index, and return the number of added items
    57         """
    57         """
    58         
    58         
    59         # validate the LogChannel
    59         # validate the LogChannel
    60         assert channel.name
    60         assert channel.name
       
    61 
       
    62         count = 0
    61         
    63         
    62         # iterate
    64         # iterate
    63         for line in lines :
    65         for line in lines :
    64             # validate the LogLine
    66             # validate the LogLine
    65             assert line.offset
    67             assert line.offset
    98 
   100 
    99             # put
   101             # put
   100             # XXX: what does this flag mean?
   102             # XXX: what does this flag mean?
   101             if not self.db.put_doc(doc, hype.Database.PDCLEAN) :
   103             if not self.db.put_doc(doc, hype.Database.PDCLEAN) :
   102                 raise Exeception("Index put_doc failed")
   104                 raise Exeception("Index put_doc failed")
   103     
   105             
       
   106             # count
       
   107             count += 1
       
   108         
       
   109         # return
       
   110         return count
       
   111 
   104     def search_cond (self, cond) :
   112     def search_cond (self, cond) :
   105         """
   113         """
   106             Search using a raw hype.Condition
   114             Search using a raw hype.Condition
   107         """
   115         """
   108 
   116