diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-12-08 14:48:00 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-12-08 14:48:00 +0000 |
commit | 852d05fa3c9347fea41c0e620485659ffda27646 (patch) | |
tree | 0a35974ee4dca3939d168ba3c3371cac23fa5819 | |
parent | First WIP commit of GentooBrowse API (diff) | |
download | gentoobrowse-api-852d05fa3c9347fea41c0e620485659ffda27646.tar.bz2 gentoobrowse-api-852d05fa3c9347fea41c0e620485659ffda27646.tar.xz gentoobrowse-api-852d05fa3c9347fea41c0e620485659ffda27646.zip |
Add the extended user friendly models
-rw-r--r-- | gentoobrowse-api/api/portage.ice | 4 | ||||
-rw-r--r-- | gentoobrowse-api/domain/extended-models.ice | 20 | ||||
-rw-r--r-- | gentoobrowse-api/domain/portage-models.ice | 5 | ||||
-rw-r--r-- | gentoobrowse-api/service/portageimpl.cpp | 22 | ||||
-rw-r--r-- | gentoobrowse-api/service/portageimpl.h | 3 | ||||
-rw-r--r-- | gentoobrowse-api/unittests/testPortage.cpp | 17 |
6 files changed, 65 insertions, 6 deletions
diff --git a/gentoobrowse-api/api/portage.ice b/gentoobrowse-api/api/portage.ice index d7a8a05..9ac9899 100644 --- a/gentoobrowse-api/api/portage.ice +++ b/gentoobrowse-api/api/portage.ice @@ -1,15 +1,17 @@ #include <portage-models.ice> +#include <extended-models.ice> module Gentoo { interface Portage { idempotent Category getCategory(int id); idempotent Categories getAllCategories(); idempotent Categories getCategoriesInSuper(string super); + idempotent OverviewCategories getOverviewCategoriesInSuper(string super); idempotent Package getPackage(int id); idempotent optional(0) Package findPackage(string category, string package); idempotent Packages getPackagesInCategory(int id); - idempotent Packages getPackagesSearch(string query); + idempotent SearchResultPackages getPackagesSearch(string query); }; }; diff --git a/gentoobrowse-api/domain/extended-models.ice b/gentoobrowse-api/domain/extended-models.ice new file mode 100644 index 0000000..956692f --- /dev/null +++ b/gentoobrowse-api/domain/extended-models.ice @@ -0,0 +1,20 @@ +#ifndef GENTOO_PORTAGE_EXTENDEDMODELS +#define GENTOO_PORTAGE_EXTENDEDMODELS + +#include "portage-models.ice" + +module Gentoo { + class OverviewCategory extends Category { + int packagecount; + }; + + class SearchResultPackage extends Package { + double rank; + }; + + sequence<SearchResultPackage> SearchResultPackages; + sequence<OverviewCategory> OverviewCategories; +}; + +#endif + diff --git a/gentoobrowse-api/domain/portage-models.ice b/gentoobrowse-api/domain/portage-models.ice index ea8d53d..9593315 100644 --- a/gentoobrowse-api/domain/portage-models.ice +++ b/gentoobrowse-api/domain/portage-models.ice @@ -1,3 +1,6 @@ +#ifndef GENTOO_PORTAGE_MODELS +#define GENTOO_PORTAGE_MODELS + module Gentoo { sequence<byte> Image; @@ -36,3 +39,5 @@ module Gentoo { sequence<Ebuild> Ebuilds; }; +#endif + diff --git a/gentoobrowse-api/service/portageimpl.cpp b/gentoobrowse-api/service/portageimpl.cpp index 5adc4d0..362483b 100644 --- a/gentoobrowse-api/service/portageimpl.cpp +++ b/gentoobrowse-api/service/portageimpl.cpp @@ -33,6 +33,19 @@ Portage::getCategoriesInSuper(const std::string & super, const Ice::Current &) ORDER BY c.name", super); } +Gentoo::OverviewCategories +Portage::getOverviewCategoriesInSuper(const std::string & super, const Ice::Current &) +{ + return fetch<Gentoo::OverviewCategories>( + "SELECT c.categoryid, c.name, c.summary, COUNT(p.packageid) packagecount \ + FROM gentoobrowse.categories c \ + LEFT OUTER JOIN gentoobrowse.packages p \ + ON p.categoryid = c.categoryid \ + WHERE c.name LIKE ? || '-%'::text \ + GROUP BY c.categoryid \ + ORDER BY c.name", super); +} + Gentoo::PackagePtr Portage::getPackage(Ice::Int id, const Ice::Current &) { @@ -63,13 +76,14 @@ Portage::getPackagesInCategory(Ice::Int id, const Ice::Current &) ORDER BY p.name", id); } -Gentoo::Packages +Gentoo::SearchResultPackages Portage::getPackagesSearch(const std::string & query, const Ice::Current &) { - return fetch<Gentoo::Packages>( - "SELECT p.packageid, p.categoryid, p.name, p.description, p.summary, p.maintainer, p.maintainername, p.herd \ + return fetch<Gentoo::SearchResultPackages>( + "SELECT p.packageid, p.categoryid, p.name, p.description, p.summary, p.maintainer, p.maintainername, p.herd, \ + ts_rank(gentoobrowse.packagefts(p), plainto_tsquery('english', ?)) rank \ FROM gentoobrowse.packages p \ WHERE gentoobrowse.packagefts(p) @@ plainto_tsquery('english', ?) \ - ORDER BY ts_rank(gentoobrowse.packagefts(p), plainto_tsquery('english', ?)) DESC, p.name", query, query); + ORDER BY rank DESC, p.name", query, query); } diff --git a/gentoobrowse-api/service/portageimpl.h b/gentoobrowse-api/service/portageimpl.h index 69e6021..f72fee2 100644 --- a/gentoobrowse-api/service/portageimpl.h +++ b/gentoobrowse-api/service/portageimpl.h @@ -12,11 +12,12 @@ class DLL_PUBLIC Portage : public Gentoo::Portage, AbstractDatabaseClient { Gentoo::CategoryPtr getCategory(Ice::Int id, const Ice::Current &) override; Gentoo::Categories getAllCategories(const Ice::Current &) override; Gentoo::Categories getCategoriesInSuper(const std::string &, const Ice::Current &) override; + Gentoo::OverviewCategories getOverviewCategoriesInSuper(const std::string &, const Ice::Current &) override; Gentoo::PackagePtr getPackage(Ice::Int id, const Ice::Current &) override; IceUtil::Optional<Gentoo::PackagePtr> findPackage(const std::string &, const std::string &, const Ice::Current &) override; Gentoo::Packages getPackagesInCategory(Ice::Int id, const Ice::Current &) override; - Gentoo::Packages getPackagesSearch(const std::string & query, const Ice::Current &) override; + Gentoo::SearchResultPackages getPackagesSearch(const std::string & query, const Ice::Current &) override; }; #endif diff --git a/gentoobrowse-api/unittests/testPortage.cpp b/gentoobrowse-api/unittests/testPortage.cpp index 70afd86..a0b62a8 100644 --- a/gentoobrowse-api/unittests/testPortage.cpp +++ b/gentoobrowse-api/unittests/testPortage.cpp @@ -59,6 +59,22 @@ BOOST_AUTO_TEST_CASE( getCategoriesInSuper ) BOOST_REQUIRE_EQUAL(0, cats.size()); } +BOOST_AUTO_TEST_CASE( getOverviewCategoriesInSuper ) +{ + MockPool mp; + auto p = Portage::PointerType(new Portage(mp)); + auto cats = p->getOverviewCategoriesInSuper("dev", Ice::Current()); + BOOST_REQUIRE_EQUAL(2, cats.size()); + BOOST_REQUIRE_EQUAL("dev-ml", cats.front()->name); + BOOST_REQUIRE_EQUAL("dev-vcs", cats.back()->name); + BOOST_REQUIRE_EQUAL(136, cats.front()->packagecount); + BOOST_REQUIRE_EQUAL(88, cats.back()->packagecount); + cats = p->getOverviewCategoriesInSuper("net", Ice::Current()); + BOOST_REQUIRE_EQUAL(1, cats.size()); + cats = p->getOverviewCategoriesInSuper("sys", Ice::Current()); + BOOST_REQUIRE_EQUAL(0, cats.size()); +} + BOOST_AUTO_TEST_CASE( getPackageMissing ) { MockPool mp; @@ -123,6 +139,7 @@ BOOST_AUTO_TEST_CASE( search ) auto matches = p->getPackagesSearch("git", Ice::Current()); BOOST_REQUIRE_EQUAL(40, matches.size()); BOOST_REQUIRE_EQUAL(58252, matches.front()->packageid); + BOOST_REQUIRE_CLOSE(0.72, matches.front()->rank, 1.0); } BOOST_AUTO_TEST_CASE( searchNotFound ) |