--- cdli/cdli_files.py 2007/11/02 15:37:46 1.80.2.6 +++ cdli/cdli_files.py 2007/11/27 10:27:39 1.80.2.9 @@ -2127,6 +2127,10 @@ class CDLIRoot(Folder): def searchText(self, query, index='graphemes'): """searches query in the fulltext index and returns a list of file ids/P-numbers""" # see also: http://www.plope.com/Books/2_7Edition/SearchingZCatalog.stx#2-13 + logging.debug("searchtext for '%s' in index %s"%(query,index)) + #import Products.ZCTextIndex.QueryParser + #qp = QueryParser.QueryParser() + #logging.debug() idxQuery = {index:{'query':query}} idx = getattr(self, self.file_catalog) # do search @@ -2163,6 +2167,7 @@ class CDLIRoot(Folder): def showWordInFile(self,fileId,word,indexName='graphemes',regExp=False,): """get lines with word from FileId""" + logging.debug("showwordinfile word='%s' index=%s file=%s"%(word,indexName,fileId)) file = formatAtfFullLineNum(self.getFile(fileId)) ret=[] @@ -2171,7 +2176,7 @@ class CDLIRoot(Folder): bounds = self.splitter[indexName].bounds splitexp = "(%s|\s)(%%s)(%s|\s|\Z)"%(bounds,bounds) # compile into regexp objects - wordlist = [re.compile(splitexp%w,re.IGNORECASE) for w in word.split(' ')] + wordlist = [re.compile(splitexp%w) for w in word.split(' ')] for line in file.split("\n"): for word in wordlist: @@ -2182,10 +2187,21 @@ class CDLIRoot(Folder): break return ret + + + def showWordInFiles(self,fileIds,word,indexName='graphemes',regExp=False): + """ + get lines with word from all ids in list FileIds. + returns dict with id:lines pairs. + """ + logging.debug("showwordinfiles word='%s' index=%s file=%s"%(word,indexName,fileIds)) + + return dict([(id,self.showWordInFile(id, word, indexName, regExp)) for id in fileIds]) def tagWordInFile(self,fileId,word,indexName='graphemes',regExp=False): """get text with word highlighted from FileId""" + logging.debug("tagwordinfile word='%s' index=%s file=%s"%(word,indexName,fileId)) file=self.getFile(fileId) tagStart=u'' @@ -2232,6 +2248,16 @@ class CDLIRoot(Folder): ret.append(line) return u'
\n'.join(ret) + + + + def tagWordInFiles(self,fileIds,word,indexName='graphemes',regExp=False): + """ + get texts with highlighted word from all ids in list FileIds. + returns dict with id:text pairs. + """ + logging.debug("tagwordinfiles word='%s' index=%s file=%s"%(word,indexName,fileIds)) + return dict([(id,self.tagWordInFile(id, word, indexName, regExp)) for id in fileIds]) def URLquote(self,str):