Пример #1
0
 def search_in_book(self, id_book, nm_book, text, dict_perf, dict_field):
     text = asm_araby.fuzzy_plus(text)
     for t in text.split(u' '):
         self.ls_term.append(t)
     self.cursive = dict_perf['cursive']
     text = text.replace('"','')
     text = text.replace("'","")
     ls_term = []
     if dict_field['nass']: 
         field = 'nass'
         table = 'pages'
     else: 
         field = 'tit'
         table = 'titles'
     if dict_perf['with_tachkil'] == True: 
         cond = '{} LIKE ?'.format(field,)
     else:
         cond = 'fuzzy({}) LIKE ?'.format(field,)
     if dict_perf['identical'] == True:  pfx, sfx = '% ', ' %'
     else: pfx, sfx = '%', '%'
     if dict_perf['cursive'] == True:
         condition = 'fuzzy({}) LIKE ?'.format(field,)
         ls_term.append(pfx+text+sfx)
     else: 
         for a in text.split(u' '):
             ls_term.append(pfx+a+sfx)
         if dict_perf['one_term'] == True:
             condition = ' OR '.join([cond]*len(ls_term))
         else :
             condition = ' AND '.join([cond]*len(ls_term))
     book = self.db_list.file_book(id_book)
     con = sqlite3.connect(book)
     con.create_function('fuzzy', 1, asm_araby.fuzzy_plus)
     cur = con.cursor()
     if table == 'pages': len_book = len(cur.execute('SELECT id FROM pages').fetchall())
     else: len_book = len(cur.execute('SELECT id FROM titles').fetchall())
     parts = int(len_book/200)
     remainder = len_book-(200*parts)
     v = 0
     while v in range(parts+1):
         while (Gtk.events_pending()): Gtk.main_iteration()
         p1 = v*200
         p2 = (v+1)*200
         if v < parts:
             cond = 'id BETWEEN {} and {}'.format(p1, p2)
         elif v == parts:
             cond = 'id BETWEEN {} and {}'.format(p1, remainder)
         elif v > parts:
             pass  
         if table == 'pages':
             cur.execute("""SELECT id, part, page FROM pages WHERE {} AND {}""".format(cond, condition), ls_term)
             i_pgs = cur.fetchall()
             for i in i_pgs:
                 j = i[0]
                 try: pg = int(i[2])
                 except: pg = 1
                 try: pr = int(i[1])
                 except: pr = 1
                 cur.execute('SELECT tit FROM titles WHERE id<=?', (j,)) 
                 try: tit = cur.fetchall()[-1][0]
                 except: tit = '......'
                 self.store_results.append([j, self.n_r, nm_book, tit, pr, pg, id_book])
                 self.n_r += 1
                 self.lab_n_result.set_text('عدد النتائج : {}'.format(self.n_r-1, ))
         else:
             cur.execute("""SELECT id, tit FROM titles WHERE {} AND {}""".format(cond, condition), ls_term)
             i_tits = cur.fetchall()
             for i in i_tits:
                 self.store_results.append([i[0], self.n_r, nm_book, i[1], 0, 0, id_book])
                 self.n_r += 1
                 self.lab_n_result.set_text('عدد النتائج : {}'.format(self.n_r-1, ))
         v += 1
     cur.close()
     con.close()
Пример #2
0
 def search_in_book(self, id_book, nm_book, text, dict_perf, dict_field):
     self.cursive = dict_perf["cursive"]
     text = text.replace('"', "")
     text = text.replace("'", "")
     ls_term = []
     if dict_field["nass"]:
         field = "nass"
         table = "pages"
     else:
         field = "tit"
         table = "titles"
     if dict_perf["with_tachkil"] == True:
         cond = "{} MATCH ?".format(field)
     else:
         cond = "fuzzy({}) MATCH ?".format(field)
         text = asm_araby.fuzzy_plus(text)
     if dict_perf["identical"] == True:
         pfx, sfx = "% ", " %"
     else:
         pfx, sfx = "%", "%"
     if dict_perf["cursive"] == True:
         condition = "fuzzy({}) MATCH ?".format(field)
         ls_term.append(pfx + text + sfx)
     else:
         for a in text.split(u" "):
             ls_term.append(pfx + a + sfx)
         if dict_perf["one_term"] == True:
             condition = " OR ".join([cond] * len(ls_term))
         else:
             condition = " AND ".join([cond] * len(ls_term))
     for a in ls_term:
         self.ls_term.append(a.replace("%", ""))
     book = self.db_list.file_book(id_book)
     con = sqlite3.connect(book)
     con.create_function("fuzzy", 1, asm_araby.fuzzy_plus)
     cur = con.cursor()
     if table == "pages":
         print "SELECT id, part, page FROM pages WHERE {}".format(condition)
         cur.execute("SELECT * FROM pages WHERE nass MATCH 'العدالة'")
         i_pgs = cur.fetchall()
         for i in i_pgs:
             j = i[0]
             try:
                 pg = int(i[2])
             except:
                 pg = 1
             try:
                 pr = int(i[1])
             except:
                 pr = 1
             cur.execute("SELECT tit FROM titles WHERE id<=?", (j,))
             try:
                 tit = cur.fetchall()[-1][0]
             except:
                 tit = "......"
             self.store_results.append([j, self.n_r, nm_book, tit, pr, pg, id_book])
             self.n_r += 1
             self.lab_n_result.set_text("عدد النتائج : {}".format(self.n_r - 1))
     else:
         cur.execute("""SELECT id, tit FROM titles WHERE {} AND {}""".format(cond, condition), ls_term)
         i_tits = cur.fetchall()
         for i in i_tits:
             self.store_results.append([i[0], self.n_r, nm_book, i[1], 0, 0, id_book])
             self.n_r += 1
             self.lab_n_result.set_text("عدد النتائج : {}".format(self.n_r - 1))
     cur.close()
     con.close()