def search(self,text, is_fuzzy=0, pos=-1, direction=1 ,limit=10000): if pos!=self.search_pos or text!=self.search_text: self.search_pos=pos; pos-=1 else: self.search_pos=pos self.search_text=text self.search_is_fuzzy=is_fuzzy if is_fuzzy: s='''fuzzy_normalize(book.nass) LIKE ? ESCAPE "|"''' text=fuzzy.normalize(text) else: s='''book.nass LIKE ? ESCAPE "|"''' self.search_tokens=fuzzy.tokenize_search(text) l=map(lambda s: '%'+s.replace('|','||').replace('%','|%')+'%',self.search_tokens) if len(l)<1: return [] condition=' AND '.join([s]*len(l)) if direction<0: order="ORDER BY book.rowid DESC"; op="<" else: order=""; op=">" if pos>=0: condition='book.id %s %d AND %s' % (op,pos,condition) self.__c.execute("""SELECT book.id FROM b%d AS book WHERE %s %s LIMIT %d """ % (self.__book_id, condition, order, limit), l) #c.execute("""SELECT book.id, toc.tit FROM b2023 AS book left JOIN t2023 AS toc USING ( id ) where %s group by book.id limit %d,%d;""" % (condition,limit*page,limit)) a=self.__c.fetchall() r=[] for i in a: j=i[0] k=bisect.bisect(self.__toc_ids,j)-1 if k<0: k=0 try: h=self.__toc_uniq[k] except: h = [1,1,'......'] r.append((j, h[2])) self.search_pos=j return r
def sh_cr_nass_sup(self,text, is_fuzzy=0, pos=-1, direction=1 ,limit=10000): if is_fuzzy: s = '''fuzzy_normalize(book.nass) LIKE ? ESCAPE "|"''' text=fuzzy.normalize(text) else: s = '''book.nass LIKE ? ESCAPE "|"''' self.search_tokens=fuzzy.tokenize_search(text) l = map(lambda s: '%'+s.replace('|','||').replace('%','|%')+'%',self.search_tokens) if len(l) < 1: return [] condition = ' AND '.join([s]*len(l)) if direction < 0: orde = "ORDER BY book.rowid DESC" op = "<" else: order = "" op = ">" if pos >= 0: condition = 'book.id %s %d AND %s' % (op,pos,condition) self.cr.execute("""SELECT book.id FROM pages AS book WHERE %s %s LIMIT %d """ % (condition, order, limit), l) a = self.cr.fetchall() r = [] for i in a: j = i[0] k = bisect.bisect(self.toc_ids,j)-1 if k < 0: k = 0 try: h = self.toc_uniq[k] except: h = [1,1,'......'] r.append((j, h[2])) self.search_pos = j return r
def tafsir(self,nass): text = '"'+nass+'"' j = 0 __cn = sqlite3.connect('data/quran.db', isolation_level=None) __c=__cn.cursor() _c=__cn.cursor() __cn.create_function('fuzzy_normalize',1,fuzzy.normalize) s='''fuzzy_normalize(imlai) LIKE ? ESCAPE "|"''' text=fuzz(fuzzy.normalize(text)) self.search_tokens=fuzzy.tokenize_search(text) l=map(lambda s: '%'+s.replace('|','||').replace('%','|%')+'%',self.search_tokens) if len(l)<1: return [] self.condition=' AND '.join([s]*len(l)) __c.execute("""SELECT id FROM Quran WHERE %s""" % (self.condition), l) a = __c.fetchall() if len(a) == 0 : dlg('لاتوجد نتائج');return for s in range(len(a)): while (gtk.events_pending()): gtk.main_iteration() gt = a[s][0] isr = (gt/512)+1 iya = gt-((isr-1)*512) g1= self.page_quran(isr , iya+1) j = j+1 _c.execute("""SELECT sura_name FROM suranames""") b = _c.fetchall() g2 = str(b[isr-1][0]) self.store.append([g1,g2,None,None,None,None,None,None]) self.modtf(self.store[0][0])
def display(self,text,index): ss_tag = [] self.buff.set_text(text) for tag1 in self.n_tag: self.buff.remove_tag(tag1, self.buff.get_start_iter(), self.buff.get_end_iter()) n_tags=itertools.cycle(self.n_tag) for txt1 in [ "الاسم : ","المولد : ","الوفاة : ","الطبقة : " ,"الرواة عنه : ","الرتبة عند الحافظ : ","الرتبة عند الذهبي : "]: tag1=n_tags.next() i1=self.buff.get_start_iter() r=i1.forward_search(txt1, 0) if r: i1,i2=r while (r): self.buff.apply_tag(tag1,i1,i2) r=i2.forward_search(txt1, 0) if r: i1,i2=r self.n_tag[-1].set_property('font',"KacstOne Bold 17") self.n_tag[-1].set_property('foreground',"#660000") oi = self.buff.get_text(self.buff.get_start_iter(),self.buff.get_end_iter(),True).split() for er in range(len(oi)): rr = oi[er] if fuzzy.normalize(index) in fuzzy.normalize(rr): ss_tag.append(rr) for tag2 in self.s_tag: self.buff.remove_tag(tag2, self.buff.get_start_iter(), self.buff.get_end_iter()) i_min,is0=None,None s_tags=itertools.cycle(self.s_tag) for txt2 in ss_tag: tag2=s_tags.next() is1=self.buff.get_start_iter() rs=is1.forward_search(txt2, 0) if rs: is1,is2=rs; is0=is1 while (rs): self.buff.apply_tag(tag2,is1,is2) rs=is2.forward_search(txt2, 0) if rs: is1,is2=rs if is0 and (not i_min or i_min.compare(is0)>0): i_min=is0 self.sw2.get_vadjustment().set_value(0) if i_min: while (gtk.events_pending()): gtk.main_iteration(); self.buff.place_cursor(i_min) m=self.buff.get_insert() self.view.scroll_to_mark(m, 0.0,True) self.s_tag[-1].set_property('background','#FFFF80') self.buff.insert_with_tags(self.buff.get_start_iter(), self.q, self.qr_tag)
def sh_cr_nass(self,text, is_fuzzy=0): if is_fuzzy: s = '''fuzzy_normalize(book.nass) LIKE ? ESCAPE "|"''' text=fuzzy.normalize(text) else: s = '''book.nass LIKE ? ESCAPE "|"''' self.search_tokens=fuzzy.tokenize_search(text) l = map(lambda s: '%'+s.replace('|','||').replace('%','|%')+'%',self.search_tokens) if len(l) < 1: return [] condition = ' AND '.join([s]*len(l)) self.cr.execute("""SELECT book.id FROM pages AS book WHERE %s""" % (condition), l) a = self.cr.fetchall() r = [] for i in a: j = i[0] try: h = self.sh_get_title(j) except: h = '......' r.append((j, h)) return r
def tardjma(self,nass): cn_r = sqlite3.connect('data/rewat',isolation_level=None) cn_r.create_function('fuzzy_normalize',1,fuzzy.normalize) cr_r = cn_r.cursor() text = '"'+nass+'"' s='''fuzzy_normalize(name) LIKE ? ESCAPE "|"''' text=fuzzy.normalize(text) self.search_tokens=fuzzy.tokenize_search(text) l=map(lambda s: '%'+s.replace('|','||').replace('%','|%')+'%',self.search_tokens) if len(l)<1: return [] condition=' AND '.join([s]*len(l)) cr_r.execute("""SELECT * FROM rewat WHERE %s""" % (condition), l) trj = cr_r.fetchall() if len(trj) == 0 : dlg('لاتوجد نتائج');return self.store.clear() self.modtr(trj[0]) for a in range(len(trj)): self.store.append([a,trj[a][1],trj[a][2],trj[a][3],trj[a][4],trj[a][5],trj[a][6],trj[a][7]])
def mefrada(self,nass): cn_r = sqlite3.connect('data/me3djam',isolation_level=None) cn_r.create_function('fuzzy_normalize',1,fuzzy.normalize) cr_r = cn_r.cursor() text = u''+nass s='''fuzzy_normalize(tit) LIKE ? ESCAPE "|"''' text = fuzz(fuzzy.normalize(text)) self.search_tokens = fuzzy.tokenize_search(text) l = map(lambda s: '%'+s.replace('|','||').replace('%','|%')+'%',self.search_tokens) if len(l) < 1: return [] condition = ' OR '.join([s]*len(l)) cr_r.execute("""SELECT * FROM titles WHERE %s""" % (condition), l) mef = cr_r.fetchall() if len(mef) == 0 : dlg('لاتوجد نتائج');return self.store.clear() self.modmf(mef[0][0],mef[0][1]) for a in range(len(mef)): while (gtk.events_pending()): gtk.main_iteration() self.store.append([a,mef[a][1],mef[a][0],None,None,None,None,None])