Mercurial > hg > MonetDB-sphinx
changeset 0:190b452ce385 default tip
Separated sphinx module out from MonetDB.
author | Sjoerd Mullender <sjoerd@acm.org> |
---|---|
date | Mon, 20 Feb 2017 10:24:56 +0100 (2017-02-20) |
parents | |
children | |
files | 30_sphinx.mal Makefile sphinx.c sphinx.h sphinx.mal |
diffstat | 5 files changed, 184 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/30_sphinx.mal Mon Feb 20 10:24:56 2017 +0100 @@ -0,0 +1,7 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V. + +include sphinx;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Mon Feb 20 10:24:56 2017 +0100 @@ -0,0 +1,21 @@ +LIBDIR = `pkg-config --variable=libdir monetdb5` + +CC = cc + +CFLAGS = `pkg-config --cflags monetdb5` +LDFLAGS = `pkg-config --libs monetdb5` -lsphinxclient + +all: lib_sphinx.so + +lib_sphinx.so: sphinx.o + $(CC) -fPIC -DPIC -o lib_sphinx.so -shared sphinx.o $(LDFLAGS) -Wl,-soname -Wl,lib_sphinx.so + +sphinx.o: sphinx.c + $(CC) -fPIC -DPIC $(CFLAGS) -c sphinx.c + +clean: + rm -f *.o *.so + +install: lib_sphinx.so + cp sphinx.mal lib_reverse.so $(DESTDIR)$(LIBDIR)/monetdb5 + cp 30_sphinx.mal $(DESTDIR)$(LIBDIR)/monetdb5/autoload
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sphinx.c Mon Feb 20 10:24:56 2017 +0100 @@ -0,0 +1,86 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V. + */ + +/* + * @f sphinx + * @a S.A.M.M. de Konink + * @v 0.2 + * @* The Sphinx module + * The Sphinx module implements an external full text search engine returning a + * list of identifiers based on a query string and an index to search upon. + * + */ +#include "monetdb_config.h" +#include "sphinx.h" +#include "mal.h" +#include "mal_client.h" +#include "mal_exception.h" +#include <sphinxclient.h> + +/* COMMAND "SPHINXsearchIndexLimit": Search the query on the specified indices, with limit + * SIGNATURE: SPHINXsearchIndexLimit(str, str, int) : bat[oid,lng]; */ +static str +sphinx_searchIndexLimit(BAT **ret, /* put pointer to BAT[oid,int] record here. */ + str query, str index, int limit) +{ + int i; + BAT *bn; + sphinx_client *client; + sphinx_result *res; + + client = sphinx_create ( SPH_TRUE ); + if (client == NULL) + throw(MAL, "sphinx.searchIndexLimit", "Cannot create Sphinx object"); + + sphinx_set_limits ( client, 0, limit, limit, 0 ); + + res = sphinx_query ( client, query, index, NULL ); + if (!res || (res && res->num_matches == 0)) { + bn = COLnew(0, TYPE_lng, 0, TRANSIENT); + if (bn == NULL) + throw(MAL, "sphinx.searchIndex", MAL_MALLOC_FAIL); + } else { + bn = COLnew(0, TYPE_lng, res->num_matches, TRANSIENT); + if (bn == NULL) + throw(MAL, "sphinx.searchIndex", MAL_MALLOC_FAIL); + for ( i = 0; i < res->num_matches; i++ ) { + lng sphinx_id = sphinx_get_id ( res, i ); + bunfastapp(bn, &sphinx_id); + } + + } + sphinx_destroy (client); + + bn->tsorted = 0; + bn->trevsorted = 0; + bn->tnonil = 1; + BATkey(bn, FALSE); + + *ret = bn; + return MAL_SUCCEED; + bunins_failed: + BBPunfix(bn->batCacheid); + sphinx_destroy(client); + throw(MAL, "sphinx.searchIndex", MAL_MALLOC_FAIL); +} + +str +SPHINXsearchIndexLimit(bat *ret, const str *query, const str *index, const int *limit) +{ + BAT *b = NULL; + str msg = sphinx_searchIndexLimit(&b, *query, *index, *limit); + + if (msg) { + return msg; + } + assert(b != NULL); + *ret = b->batCacheid; + BBPkeepref(*ret); + return msg; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sphinx.h Mon Feb 20 10:24:56 2017 +0100 @@ -0,0 +1,31 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V. + */ + +#ifndef SPHINX_H +#define SPHINX_H + +#include <gdk.h> +#include <ctype.h> +#include <sphinxclient.h> +#include "mal_client.h" +#include "mal_interpreter.h" + +#ifdef WIN32 +#ifndef LIBSPHINX +#define sphinx_export extern __declspec(dllimport) +#else +#define sphinx_export extern __declspec(dllexport) +#endif +#else +#define sphinx_export extern +#endif + +sphinx_export str SPHINXsearchIndexLimit(bat *ret, const str *query, const str *index, const int *limit); + +#endif /* SPHINX_H */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sphinx.mal Mon Feb 20 10:24:56 2017 +0100 @@ -0,0 +1,39 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V. + +module sphinx; + +command searchIndexLimit(q:str, i:str, l:int) :bat[:lng] +address SPHINXsearchIndexLimit +comment "Search the query on the specified index, with limit"; + +function search(q:str) :bat[:lng]; + ret := searchIndexLimit(q, "*", 20); + return ret; +end search; + +function searchIndex(q:str, i:str) :bat[:lng]; + ret := searchIndexLimit(q, i, 20); + return ret; +end searchIndex; + + +function sphinx_search(q:str)(id:bat[:lng]); + ret := searchIndexLimit(q, "*", 20); + return ret; +end sphinx_search; + +function sphinx_searchIndex(q:str, i:str)(id:bat[:lng]); + ret := searchIndexLimit(q, i, 20); + return ret; +end sphinx_searchIndex; + +function sphinx_searchIndexLimit(q:str, i:str, l:int)(id:bat[:lng]); + ret := searchIndexLimit(q, i, l); + return ret; +end sphinx_searchIndexLimit; + +