From ae1e86db167236255de2f3852acc30e2ef8b8250 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 4 Nov 2016 11:52:00 +0000 Subject: Add support for search for use flags --- gentoobrowse-api/api/portage.ice | 1 + gentoobrowse-api/db/schema.sql | 11 +++++++++++ gentoobrowse-api/service/portageimpl.cpp | 7 +++++++ gentoobrowse-api/service/portageimpl.h | 1 + gentoobrowse-api/service/sql/portage/getUsesSearch.sql | 4 ++++ gentoobrowse-api/unittests/testPortage.cpp | 10 ++++++++++ 6 files changed, 34 insertions(+) create mode 100644 gentoobrowse-api/service/sql/portage/getUsesSearch.sql 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 #include #include +#include #include #include #include @@ -231,6 +232,12 @@ Portage::getUsePackages(const std::string & use, const Ice::Current &) return fetchCache(sql::portage::getUsePackages, 30, use, use); } +Gentoo::Uses +Portage::getUsesSearch(const std::string & query, const Ice::Current &) +{ + return fetchCache(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"); -- cgit v1.2.3