Logo Search packages:      
Sourcecode: zim version File versions  Download package

def zim::index::Index::lookup_path (   self,
  path,
  parent = None 
)

Returns an IndexPath for path. This method is mostly intended
for internal use only, but can be used by other modules in
some cases to optimize repeated index lookups. If a parent IndexPath
is known this can be given to speed up the lookup.
If path is not indexed this method returns None.

Definition at line 829 of file index.py.

00829                                               :
            '''Returns an IndexPath for path. This method is mostly intended
            for internal use only, but can be used by other modules in
            some cases to optimize repeated index lookups. If a parent IndexPath
            is known this can be given to speed up the lookup.
            If path is not indexed this method returns None.
            '''
            # Constructs the indexpath downward
            if isinstance(path, IndexPath):
                  if not path.hasdata:
                        return self.lookup_data(path)
                  else:
                        return path
            elif path.isroot:
                  cursor = self.db.cursor()
                  cursor.execute('select * from pages where id==?', (ROOT_ID,))
                  row = cursor.fetchone()
                  return IndexPath(':', (ROOT_ID,), row)

            if parent: indexpath = list(parent._indexpath)
            else:      indexpath = [ROOT_ID]

            names = path.name.split(':')
            names = names[len(indexpath)-1:] # shift X items
            parentid = indexpath[-1]

            cursor = self.db.cursor()
            if not names: # len(indexpath) was len(names)
                  cursor.execute('select * from pages where id==?', (indexpath[-1],))
                  row = cursor.fetchone()
            else:
                  for name in names:
                        cursor.execute(
                              'select * from pages where basename==? and parent==?',
                              (name, parentid) )
                        row = cursor.fetchone()
                        if row is None:
                              return None # path is not indexed
                        indexpath.append(row['id'])
                        parentid = row['id']

            return IndexPath(path.name, indexpath, row)

      def lookup_data(self, path):


Generated by  Doxygen 1.6.0   Back to index