def searchBinaryPackages(self, text): """See `IDistroArchSeries`.""" from lp.soyuz.model.publishing import BinaryPackagePublishingHistory origin = [ BinaryPackageRelease, Join( BinaryPackagePublishingHistory, BinaryPackagePublishingHistory.binarypackagerelease == BinaryPackageRelease.id), Join( BinaryPackageName, BinaryPackageRelease.binarypackagename == BinaryPackageName.id)] find_spec = [BinaryPackageRelease, BinaryPackageName] archives = self.distroseries.distribution.getArchiveIDList() clauses = [ BinaryPackagePublishingHistory.distroarchseries == self, BinaryPackagePublishingHistory.archiveID.is_in(archives), BinaryPackagePublishingHistory.status.is_in( active_publishing_status)] order_by = [BinaryPackageName.name] if text: ranking = rank_by_fti(BinaryPackageRelease, text) find_spec.append(ranking) clauses.append( Or( fti_search(BinaryPackageRelease, text), BinaryPackageName.name.contains_string(text.lower()))) order_by.insert(0, ranking) result = IStore(BinaryPackageName).using(*origin).find( tuple(find_spec), *clauses).config(distinct=True).order_by( *order_by) # import here to avoid circular import problems from lp.soyuz.model.distroarchseriesbinarypackagerelease import ( DistroArchSeriesBinaryPackageRelease) # Create a function that will decorate the results, converting # them from the find_spec above into DASBPRs. def result_to_dasbpr(row): return DistroArchSeriesBinaryPackageRelease( distroarchseries=self, binarypackagerelease=row[0]) # Return the decorated result set so the consumer of these # results will only see DSPs. return DecoratedResultSet(result, result_to_dasbpr)
def searchBinaryPackages(self, text): """See `IDistroArchSeries`.""" from lp.soyuz.model.publishing import BinaryPackagePublishingHistory origin = [ BinaryPackageRelease, Join( BinaryPackagePublishingHistory, BinaryPackagePublishingHistory.binarypackagerelease == BinaryPackageRelease.id), Join( BinaryPackageName, BinaryPackageRelease.binarypackagename == BinaryPackageName.id)] find_spec = [BinaryPackageRelease, BinaryPackageName] archives = self.distroseries.distribution.getArchiveIDList() clauses = [ BinaryPackagePublishingHistory.distroarchseries == self, BinaryPackagePublishingHistory.archiveID.is_in(archives), BinaryPackagePublishingHistory.dateremoved == None] order_by = [BinaryPackageName.name] if text: ranking = rank_by_fti(BinaryPackageRelease, text) find_spec.append(ranking) clauses.append( Or( fti_search(BinaryPackageRelease, text), BinaryPackageName.name.contains_string(text.lower()))) order_by.insert(0, ranking) result = IStore(BinaryPackageName).using(*origin).find( tuple(find_spec), *clauses).config(distinct=True).order_by( *order_by) # import here to avoid circular import problems from lp.soyuz.model.distroarchseriesbinarypackagerelease import ( DistroArchSeriesBinaryPackageRelease) # Create a function that will decorate the results, converting # them from the find_spec above into DASBPRs. def result_to_dasbpr(row): return DistroArchSeriesBinaryPackageRelease( distroarchseries=self, binarypackagerelease=row[0]) # Return the decorated result set so the consumer of these # results will only see DSPs. return DecoratedResultSet(result, result_to_dasbpr)
def getOrderByClause(self): """Return the ORDER BY clause to sort the results.""" sort = self.sort if sort is None: if self.search_text is not None: sort = FAQSort.RELEVANCY else: sort = FAQSort.NEWEST_FIRST if sort is FAQSort.NEWEST_FIRST: return "-FAQ.date_created" elif sort is FAQSort.OLDEST_FIRST: return "FAQ.date_created" elif sort is FAQSort.RELEVANCY: if self.search_text: return [ rank_by_fti(FAQ, self.search_text), "-FAQ.date_created"] else: return "-FAQ.date_created" else: raise AssertionError("Unknown FAQSort value: %r" % sort)
def findSimilar(summary, product=None, distribution=None): """Return the FAQs similar to summary. See `IFAQTarget.findSimilarFAQs` for details. """ assert not (product and distribution), ( 'only one of product or distribution should be provided') if product: target_constraint = 'product = %s' % sqlvalues(product) elif distribution: target_constraint = 'distribution = %s' % sqlvalues(distribution) else: raise AssertionError('must provide product or distribution') phrases = nl_phrase_search(summary, FAQ, target_constraint) if not phrases: # No useful words to search on in that summary. return FAQ.select('1 = 2') return FAQ.select( And(target_constraint, fti_search(FAQ, phrases, ftq=False)), orderBy=[ rank_by_fti(FAQ, phrases, ftq=False), "-FAQ.date_created"])