diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-11-04 11:52:00 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-11-04 11:52:00 +0000 |
commit | d9421cf8d4cf47f8f3befa8a3b988af87aa73216 (patch) | |
tree | 9a8e18a0de409f7dde269c6eef4ab51dbfb177ce | |
parent | Add basic methods for getting information about use flags (diff) | |
download | gentoobrowse-api-d9421cf8d4cf47f8f3befa8a3b988af87aa73216.tar.bz2 gentoobrowse-api-d9421cf8d4cf47f8f3befa8a3b988af87aa73216.tar.xz gentoobrowse-api-d9421cf8d4cf47f8f3befa8a3b988af87aa73216.zip |
Add support for search for use flags
-rw-r--r-- | gentoobrowse-api/api/portage.ice | 1 | ||||
-rw-r--r-- | gentoobrowse-api/db/schema.sql | 11 | ||||
-rw-r--r-- | gentoobrowse-api/service/portageimpl.cpp | 7 | ||||
-rw-r--r-- | gentoobrowse-api/service/portageimpl.h | 1 | ||||
-rw-r--r-- | gentoobrowse-api/service/sql/portage/getUsesSearch.sql | 4 | ||||
-rw-r--r-- | gentoobrowse-api/unittests/testPortage.cpp | 10 |
6 files changed, 34 insertions, 0 deletions
diff --git a/gentoobrowse-api/api/portage.ice b/gentoobrowse-api/api/portage.ice index c7d7da6..26c7987 100644 --- a/gentoobrowse-api/api/portage.ice +++ b/gentoobrowse-api/api/portage.ice @@ -36,6 +36,7 @@ module Gentoo { idempotent StringList getUseGroups(); idempotent Uses getUseUsage(string flag); idempotent Packages getUsePackages(string flag); + idempotent Uses getUsesSearch(string query); idempotent Bug getBug(int id) throws Slicer::NoRowsReturned; idempotent Bugs getPackageBugs(int packageId); diff --git a/gentoobrowse-api/db/schema.sql b/gentoobrowse-api/db/schema.sql index 2607185..25a4532 100644 --- a/gentoobrowse-api/db/schema.sql +++ b/gentoobrowse-api/db/schema.sql @@ -520,6 +520,15 @@ CREATE TABLE use_global ( description text ); ALTER TABLE use_global OWNER TO gentoo; +-- Name: use_globalfts(use_global); Type: FUNCTION; Schema: gentoobrowse; Owner: gentoo +CREATE FUNCTION use_globalfts(ug use_global) RETURNS tsvector + LANGUAGE plpgsql IMMUTABLE + AS $$ +BEGIN + RETURN TO_TSVECTOR('english', ug.description); +END +$$; +ALTER FUNCTION gentoobrowse.use_globalfts(ug use_global) OWNER TO gentoo; -- Name: use_group; Type: TABLE; Schema: gentoobrowse; Owner: gentoo; Tablespace: CREATE TABLE use_group ( usegroupid integer NOT NULL, @@ -727,6 +736,8 @@ CREATE INDEX idx_ebuilds_firstseen ON ebuilds USING btree (firstseen); CREATE INDEX idx_ebuilduses_use ON ebuild_uses USING btree (use); -- Name: idx_news_fts; Type: INDEX; Schema: gentoobrowse; Owner: gentoo; Tablespace: CREATE INDEX idx_news_fts ON news USING gin (newsfts(news.*)); +-- Name: idx_use_global_fts; Type: INDEX; Schema: gentoobrowse; Owner: gentoo; Tablespace: +CREATE INDEX idx_use_global_fts ON use_global USING gin (use_globalfts(use_global.*)); -- Name: idx_news_posted; Type: INDEX; Schema: gentoobrowse; Owner: gentoo; Tablespace: CREATE INDEX idx_news_posted ON news USING btree (posted); -- Name: idx_package_name; Type: INDEX; Schema: gentoobrowse; Owner: gentoo; Tablespace: diff --git a/gentoobrowse-api/service/portageimpl.cpp b/gentoobrowse-api/service/portageimpl.cpp index f39653c..bba0091 100644 --- a/gentoobrowse-api/service/portageimpl.cpp +++ b/gentoobrowse-api/service/portageimpl.cpp @@ -28,6 +28,7 @@ #include <sql/portage/getUseGroups.sql.h> #include <sql/portage/getUseUsage.sql.h> #include <sql/portage/getUsePackages.sql.h> +#include <sql/portage/getUsesSearch.sql.h> #include <sql/portage/getSyncs.sql.h> #include <sql/portage/getBug.sql.h> #include <sql/portage/getPackageBugs.sql.h> @@ -231,6 +232,12 @@ Portage::getUsePackages(const std::string & use, const Ice::Current &) return fetchCache<Gentoo::Packages>(sql::portage::getUsePackages, 30, use, use); } +Gentoo::Uses +Portage::getUsesSearch(const std::string & query, const Ice::Current &) +{ + return fetchCache<Gentoo::Uses>(sql::portage::getUsesSearch, 30, query); +} + Gentoo::BugPtr Portage::getBug(Ice::Int id, const Ice::Current &) { diff --git a/gentoobrowse-api/service/portageimpl.h b/gentoobrowse-api/service/portageimpl.h index 5440b6b..2600799 100644 --- a/gentoobrowse-api/service/portageimpl.h +++ b/gentoobrowse-api/service/portageimpl.h @@ -43,6 +43,7 @@ class DLL_PUBLIC Portage : public Gentoo::Portage, IceTray::AbstractCachingDatab Gentoo::StringList getUseGroups(const Ice::Current &) override; Gentoo::Uses getUseUsage(const std::string &, const Ice::Current &) override; Gentoo::Packages getUsePackages(const std::string &, const Ice::Current &) override; + Gentoo::Uses getUsesSearch(const std::string &, const Ice::Current &) override; Gentoo::BugPtr getBug(Ice::Int id, const Ice::Current &) override; Gentoo::Bugs getPackageBugs(Ice::Int packageId, const Ice::Current &) override; diff --git a/gentoobrowse-api/service/sql/portage/getUsesSearch.sql b/gentoobrowse-api/service/sql/portage/getUsesSearch.sql new file mode 100644 index 0000000..a4f1ec7 --- /dev/null +++ b/gentoobrowse-api/service/sql/portage/getUsesSearch.sql @@ -0,0 +1,4 @@ +SELECT use, description +FROM gentoobrowse.use_global ug +WHERE gentoobrowse.use_globalfts(ug) @@ plainto_tsquery('english', ?) +ORDER BY use diff --git a/gentoobrowse-api/unittests/testPortage.cpp b/gentoobrowse-api/unittests/testPortage.cpp index ee8f96b..7052d90 100644 --- a/gentoobrowse-api/unittests/testPortage.cpp +++ b/gentoobrowse-api/unittests/testPortage.cpp @@ -345,6 +345,16 @@ BOOST_AUTO_TEST_CASE( getGlobalUses ) BOOST_REQUIRE(!us.back()->group); } +BOOST_AUTO_TEST_CASE( getUsesSearch ) +{ + auto us = p->getUsesSearch("encoding"); + BOOST_REQUIRE_EQUAL(4, us.size()); + BOOST_REQUIRE_EQUAL("encode", us.front()->use); + BOOST_REQUIRE_EQUAL("Add support for encoding of audio or video files", us.front()->description); + BOOST_REQUIRE_EQUAL("x264", us.back()->use); + BOOST_REQUIRE_EQUAL("Enable h264 encoding using x264", us.back()->description); +} + BOOST_AUTO_TEST_CASE( getGroupUses ) { auto gs = p->getGroupUses("abi_x86"); |