def run(self, minutes_passed): writer = CoprWhoosheer.index.writer() query = db.session.query(models.Copr).filter( models.Copr.latest_indexed_data_update >= time.time() - int(minutes_passed) * 60) for copr in query.all(): CoprWhoosheer.update_copr(writer, copr) writer.commit()
def run(self): writer = CoprWhoosheer.index.writer() for copr in coprs_logic.CoprsLogic.get_all(): CoprWhoosheer.delete_copr(writer, copr) writer.commit(optimize=True) writer = CoprWhoosheer.index.writer() writer.schema = CoprWhoosheer.schema writer.commit(optimize=True) writer = CoprWhoosheer.index.writer() for copr in coprs_logic.CoprsLogic.get_all(): CoprWhoosheer.insert_copr(writer, copr) writer.commit(optimize=True)
def update_indexes_quick(minutes_passed): """ Recreates whoosh indexes for projects for which indexed data were updated in last n minutes. Doesn't update schema. """ index = Whooshee.get_or_create_index(app, CoprWhoosheer) writer = index.writer() query = db.session.query(models.Copr).filter( models.Copr.latest_indexed_data_update >= time.time() - int(minutes_passed) * 60) for copr in query.all(): CoprWhoosheer.update_copr(writer, copr) writer.commit()
def test_fulltext_whooshee_return_all_hits(self, f_users, f_db): # https://bugzilla.redhat.com/show_bug.cgi?id=1153039 self.prefix = u"prefix" self.s_coprs = [] index = Whooshee.get_or_create_index(app, CoprWhoosheer) writer = index.writer() u1_count = 150 for x in range(u1_count): self.s_coprs.append( models.Copr(name=self.prefix + str(x), user=self.u1)) u2_count = 7 for x in range(u2_count): self.s_coprs.append( models.Copr(name=self.prefix + str(x), user=self.u2)) u3_count = 9 for x in range(u3_count): self.s_coprs.append( models.Copr(name=u"_wrong_" + str(x), user=self.u3)) self.db.session.add_all(self.s_coprs) self.db.session.commit() for copr in self.s_coprs: CoprWhoosheer.insert_copr(writer, copr) writer.commit(optimize=True) query = CoprsLogic.get_multiple_fulltext("prefix") pre_query = models.Copr.query.order_by(desc(models.Copr.created_on))\ .join(models.User).filter(models.Copr.deleted == False) query = pre_query.whooshee_search( self.prefix, whoosheer=CoprWhoosheer) # needs flask-whooshee-0.2.0 results = query.all() for obj in results: assert self.prefix in obj.name obtained = len(results) expected = u1_count + u2_count assert obtained == expected
def update_indexes(): """ recreates whoosh indexes for all projects """ index = Whooshee.get_or_create_index(app, CoprWhoosheer) writer = index.writer() for copr in coprs_logic.CoprsLogic.get_all(): CoprWhoosheer.delete_copr(writer, copr) writer.commit(optimize=True) writer = index.writer() writer.schema = CoprWhoosheer.schema writer.commit(optimize=True) writer = index.writer() for copr in coprs_logic.CoprsLogic.get_all(): CoprWhoosheer.insert_copr(writer, copr) writer.commit(optimize=True) WhoosheeStamp.store()
def test_project_list_search(self, f_users, f_mock_chroots, f_coprs, f_db): self.prefix = u"prefix" self.s_coprs = [] c1_username = self.c1.user.username index = Whooshee.get_or_create_index(app, CoprWhoosheer) writer = index.writer() k1 = 3 k2 = 5 for x in range(k1): self.s_coprs.append(Copr(name=self.prefix + str(x), user=self.u1)) for x in range(k2): self.s_coprs.append(Copr(name=self.prefix + str(x), user=self.u2)) self.db.session.add_all(self.s_coprs) self.db.session.commit() for copr in self.s_coprs: CoprWhoosheer.insert_copr(writer, copr) writer.commit(optimize=True) r0 = self.tc.get(u"/api_2/projects?search_query={}".format( self.prefix)) assert r0.status_code == 200 obj = json.loads(r0.data.decode("utf-8")) assert len(obj["projects"]) == k1 + k2 for p in obj["projects"]: assert self.prefix in p["project"]["name"] r1 = self.tc.get(u"/api_2/projects?search_query={}&owner={}".format( self.prefix, c1_username)) assert r1.status_code == 200 obj = json.loads(r1.data.decode("utf-8")) assert len(obj["projects"]) == k1 for p in obj["projects"]: assert self.prefix in p["project"]["name"]