Skip to content

Commit

Permalink
Drop support for libstemmer
Browse files Browse the repository at this point in the history
The code is unused now gnome-software is using libappstream.
  • Loading branch information
hughsie committed Jun 5, 2024
1 parent 6f715d6 commit c9ec6d6
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 84 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ copy. To do the latter just do:
dnf install docbook-utils gettext-devel glib-devel \
gobject-introspection-devel gperf gtk-doc gtk3-devel \
json-glib-devel libarchive-devel libcurl-devel \
libstemmer-devel libuuid-devel libyaml-devel \
libuuid-devel libyaml-devel \
meson rpm-devel
mkdir build && cd build
meson .. --prefix=/opt -Dbuilder=false
Expand Down Expand Up @@ -92,7 +92,7 @@ binary and data files, or you can build a local copy. To do the latter just do:
dnf install docbook-utils gettext-devel glib-devel \
gobject-introspection-devel gperf gtk-doc gtk3-devel \
libarchive-devel libsoup-devel \
libstemmer-devel libuuid-devel libyaml-devel \
libuuid-devel libyaml-devel \
meson rpm-devel rpm-devel
mkdir build && cd build
meson .. --prefix=/opt -Dbuilder=true
Expand Down
2 changes: 1 addition & 1 deletion contrib/ci/Dockerfile-debian-buster
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM debian:buster

RUN echo "deb-src http://deb.debian.org/debian/ buster main" >> /etc/apt/sources.list
RUN apt-get update -qq
RUN apt-get install -yq --no-install-recommends meson libstemmer-dev
RUN apt-get install -yq --no-install-recommends meson
RUN apt-get build-dep -yq appstream-glib

RUN mkdir /build
Expand Down
1 change: 0 additions & 1 deletion contrib/ci/Dockerfile-fedora
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ RUN dnf -y install \
json-glib-devel \
libarchive-devel \
libcurl-devel \
libstemmer-devel \
libuuid-devel \
libxslt \
libyaml-devel \
Expand Down
4 changes: 1 addition & 3 deletions contrib/ci/build_and_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ set -e

mkdir -p build && cd build
rm * -rf
meson .. \
-Dgtk-doc=true \
-Dstemmer=true $@
meson .. -Dgtk-doc=true $@
ninja -v
ninja test -v
DESTDIR=/tmp/install-ninja ninja install
Expand Down
2 changes: 0 additions & 2 deletions contrib/libappstream-glib.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ BuildRequires: gtk3-devel
BuildRequires: gettext
BuildRequires: libuuid-devel
BuildRequires: libyaml-devel
BuildRequires: libstemmer-devel
BuildRequires: json-glib-devel >= %{json_glib_version}
BuildRequires: meson

Expand Down Expand Up @@ -80,7 +79,6 @@ from a directory of packages.
%build
%meson \
-Dgtk-doc=true \
-Dstemmer=true \
-Ddep11=true
%meson_build

Expand Down
64 changes: 0 additions & 64 deletions libappstream-glib/as-stemmer.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,12 @@

#include <glib/gi18n.h>

#ifdef HAVE_LIBSTEMMER
#include "libstemmer.h"
#endif

#include "as-stemmer.h"
#include "as-ref-string.h"

struct _AsStemmer
{
GObject parent_instance;
gboolean enabled;
GHashTable *hash;
struct sb_stemmer *ctx;
GMutex ctx_mutex;
};

G_DEFINE_TYPE (AsStemmer, as_stemmer, G_TYPE_OBJECT)
Expand All @@ -41,75 +33,19 @@ G_DEFINE_TYPE (AsStemmer, as_stemmer, G_TYPE_OBJECT)
AsRefString *
as_stemmer_process (AsStemmer *stemmer, const gchar *value)
{
#ifdef HAVE_LIBSTEMMER
AsRefString *new;
const gchar *tmp;
gsize value_len;
g_autofree gchar *value_casefold = NULL;
g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&stemmer->ctx_mutex);

/* look for word in the cache */
new = g_hash_table_lookup (stemmer->hash, value);
if (new != NULL)
return as_ref_string_ref (new);

/* not enabled */
value_casefold = g_utf8_casefold (value, -1);
if (stemmer->ctx == NULL || !stemmer->enabled)
return as_ref_string_new (value_casefold);

/* stem, then add to the cache */
value_len = strlen (value_casefold);
tmp = (const gchar *) sb_stemmer_stem (stemmer->ctx,
(guchar *) value_casefold,
(gint) value_len);
if (value_len == (gsize) sb_stemmer_length (stemmer->ctx)) {
new = as_ref_string_new_with_length (value_casefold, value_len);
} else {
new = as_ref_string_new (tmp);
}
g_hash_table_insert (stemmer->hash,
as_ref_string_new (value_casefold),
as_ref_string_ref (new));
return new;
#else
g_autofree gchar *value_casefold = NULL;
value_casefold = g_utf8_casefold (value, -1);
return as_ref_string_new (value_casefold);
#endif
}

static void
as_stemmer_finalize (GObject *object)
{
AsStemmer *stemmer = AS_STEMMER (object);
#ifdef HAVE_LIBSTEMMER
sb_stemmer_delete (stemmer->ctx);
g_mutex_clear (&stemmer->ctx_mutex);
#endif
g_hash_table_unref (stemmer->hash);
G_OBJECT_CLASS (as_stemmer_parent_class)->finalize (object);
}

static void
as_stemmer_class_init (AsStemmerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = as_stemmer_finalize;
}

static void
as_stemmer_init (AsStemmer *stemmer)
{
/* FIXME: use as_utils_locale_to_language()? */
#ifdef HAVE_LIBSTEMMER
stemmer->ctx = sb_stemmer_new ("en", NULL);
g_mutex_init (&stemmer->ctx_mutex);
#endif
stemmer->enabled = g_getenv ("APPSTREAM_GLIB_DISABLE_STEMMER") == NULL;
stemmer->hash = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) as_ref_string_unref,
(GDestroyNotify) as_ref_string_unref);
}

/**
Expand Down
4 changes: 0 additions & 4 deletions libappstream-glib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ if get_option('rpm')
deps += rpm
endif

if get_option('stemmer')
deps += stemmer
endif

asresources = gnome.compile_resources(
'as-resources', 'appstream-glib.gresource.xml',
c_name : 'as'
Expand Down
6 changes: 0 additions & 6 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,6 @@ if get_option('dep11')
conf.set('AS_BUILD_DEP11', 1)
endif

# support stemming of search tokens
if get_option('stemmer')
stemmer = cc.find_library('stemmer')
conf.set('HAVE_LIBSTEMMER', 1)
endif

# use gperf for faster string -> enum matching
gperf = find_program('gperf', required : true)

Expand Down
1 change: 0 additions & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ option('builder', type : 'boolean', value : true, description : 'enable AppStrea
option('rpm', type : 'boolean', value : true, description : 'enable RPM support')
option('alpm', type : 'boolean', value : false, description : 'enable ALPM support')
option('fonts', type : 'boolean', value : true, description : 'enable font support')
option('stemmer', type : 'boolean', value : true, description : 'enable stemmer support')
option('man', type : 'boolean', value : true, description : 'generate man pages')
option('gtk-doc', type : 'boolean', value : false, description : 'generate API reference')
option('introspection', type : 'boolean', value : true, description : 'generate GObject Introspection data')

0 comments on commit c9ec6d6

Please sign in to comment.