From: Sergey Kartashoff Date: Tue, 30 Jan 2001 12:53:51 +0000 (+0000) Subject: mnoGoSearch extension module initial version has been added. X-Git-Tag: php-4.0.5RC1~435 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cdf6b7e2c370c1a529307850ca05d16667974752;p=php mnoGoSearch extension module initial version has been added. This module currently at the alpha state, but it can be used already. @- mnoGoSearch extension module initial version has been added. @ This module currently at the alpha state, but it can be used already. # For details about mnoGoSearch please refer at http://search.mnogo.ru PR: Submitted by: Reviewed by: Obtained from: --- diff --git a/ext/mnogosearch/Makefile.in b/ext/mnogosearch/Makefile.in new file mode 100644 index 0000000000..52c226a869 --- /dev/null +++ b/ext/mnogosearch/Makefile.in @@ -0,0 +1,7 @@ + +LTLIBRARY_NAME = libmnogosearch.la +LTLIBRARY_SOURCES = php_mnogo.c +LTLIBRARY_SHARED_NAME = mnogosearch.la +LTLIBRARY_SHARED_LIBADD = $(MNOGOSEARCH_SHARED_LIBADD) + +include $(top_srcdir)/build/dynlib.mk diff --git a/ext/mnogosearch/README b/ext/mnogosearch/README new file mode 100644 index 0000000000..699774ebe1 --- /dev/null +++ b/ext/mnogosearch/README @@ -0,0 +1,26 @@ +mnoGoSearch extension module version 0.3 for PHP4. +Basic mnoGoSearch function implementation. + +If used with mysql you should not use bundled mysql library +in the php distribution. You should use native mysql +library. To do this you should compile php with specefying mysql-dir +(for example --with-mysql=/usr, not --with-mysql). + + TODO + ---- + +1. Implement more UdmSearch functions. Only basic minimal functions +set is implemented for now. + +2. Fix config.m4 to detect whether UdmSearch is actually installed. +Currently there is no any checking. ./configure just trust that UdmSearch +does exist. + +3. Test with more databases. Currently tested with MySQL which is compiled into +PHP4 by default and does not require any additional UdmSearch libraries. + Actually it should work fine with other supported database. + +4. Write PHP interface documentation. + +5. Add nice warnings when unknown parameters are passed to PHP functions. +Those places are marked with FIXME is php_udm.c diff --git a/ext/mnogosearch/config.m4 b/ext/mnogosearch/config.m4 new file mode 100644 index 0000000000..ab32e2befe --- /dev/null +++ b/ext/mnogosearch/config.m4 @@ -0,0 +1,33 @@ +dnl $Id$ + + +PHP_ARG_WITH(mnogosearch,for mnoGoSearch support, +[ --with-mnogosearch[=DIR] Include mnoGoSearch support. DIR is the mnoGoSearch base + install directory, defaults to /usr/local/udmsearch.]) + + if test "$PHP_MNOGOSEARCH" != "no"; then + + if test "$PHP_MNOGOSEARCH" = "yes"; then + MNOGOSEARCH_BINDIR=/usr/local/udmsearch/bin + MNOGOSEARCH_INCDIR=/usr/local/udmsearch/include + MNOGOSEARCH_LIBDIR=/usr/local/udmsearch/lib + else + MNOGOSEARCH_BINDIR=$PHP_MNOGOSEARCH/bin + MNOGOSEARCH_INCDIR=$PHP_MNOGOSEARCH/include + MNOGOSEARCH_LIBDIR=$PHP_MNOGOSEARCH/lib + fi + + AC_ADD_INCLUDE($MNOGOSEARCH_INCDIR) + + if test -x "$MNOGOSEARCH_BINDIR/udm-config"; then + PHP_EVAL_LIBLINE(`$MNOGOSEARCH_BINDIR/udm-config --libs`, MNOGOSEARCH_SHARED_LIBADD) + else + AC_ADD_LIBRARY_WITH_PATH(udmsearch, $MNOGOSEARCH_LIBDIR, MNOGOSEARCH_SHARED_LIBADD) + fi + + AC_DEFINE(HAVE_MNOGOSEARCH,1,[ ]) + + PHP_SUBST(MNOGOSEARCH_SHARED_LIBADD) + PHP_EXTENSION(mnogosearch,$ext_shared) + + fi diff --git a/ext/mnogosearch/php_mnogo.c b/ext/mnogosearch/php_mnogo.c new file mode 100644 index 0000000000..b51346ea83 --- /dev/null +++ b/ext/mnogosearch/php_mnogo.c @@ -0,0 +1,481 @@ +/* + +----------------------------------------------------------------------+ + | PHP version 4.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 2.02 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | http://www.php.net/license/2_02.txt. | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: | + | Initial version by Alex Barkov | + | and Ramil Kalimullin | + | Further development by Sergey Kartashoff | + +----------------------------------------------------------------------+ + */ + +/* $Id: php_mnogo.c,v 0.3 2001/01/27 15:30:00 */ + +#include "php.h" +#include "php_mnogo.h" +#include "ext/standard/php_standard.h" +#include "ext/standard/info.h" +#include "php_globals.h" + +#ifdef HAVE_MNOGOSEARCH + +#define UDM_FIELD_URLID 1 +#define UDM_FIELD_URL 2 +#define UDM_FIELD_CONTENT 4 +#define UDM_FIELD_TITLE 8 +#define UDM_FIELD_KEYWORDS 16 +#define UDM_FIELD_DESC 32 +#define UDM_FIELD_TEXT 64 +#define UDM_FIELD_SIZE 128 +#define UDM_FIELD_SCORE 256 +#define UDM_FIELD_MODIFIED 512 + +#define UDM_PARAM_PAGE_SIZE 1 +#define UDM_PARAM_PAGE_NUM 2 +#define UDM_PARAM_SEARCH_MODE 4 +#define UDM_PARAM_CHARSET 8 +#define UDM_PARAM_NUM_ROWS 16 +#define UDM_PARAM_FOUND 32 + +/* True globals, no need for thread safety */ +static int le_link,le_res; + +#include + +function_entry mnogosearch_functions[] = { + PHP_FE(udm_alloc_agent, NULL) + PHP_FE(udm_set_agent_param, NULL) + PHP_FE(udm_free_agent, NULL) + + PHP_FE(udm_errno, NULL) + PHP_FE(udm_error, NULL) + + PHP_FE(udm_find, NULL) + PHP_FE(udm_free_res, NULL) + PHP_FE(udm_get_res_field, NULL) + PHP_FE(udm_get_res_param, NULL) + + {NULL, NULL, NULL} +}; + + +zend_module_entry mnogosearch_module_entry = { + "mnogosearch", + mnogosearch_functions, + PHP_MINIT(mnogosearch), + PHP_MSHUTDOWN(mnogosearch), + PHP_RINIT(mnogosearch), + NULL, + PHP_MINFO(mnogosearch), + STANDARD_MODULE_PROPERTIES +}; + + +#ifdef COMPILE_DL_MNOGOSEARCH +ZEND_GET_MODULE(mnogosearch) +#endif + +static void _free_udm_agent(zend_rsrc_list_entry *rsrc){ + UDM_AGENT * Agent = (UDM_AGENT *)rsrc->ptr; + UdmFreeAgent(Agent); +} + +static void _free_udm_res(zend_rsrc_list_entry *rsrc){ + UDM_RESULT * Res = (UDM_RESULT *)rsrc->ptr; + UdmFreeResult(Res); +} + +DLEXPORT PHP_MINIT_FUNCTION(mnogosearch) +{ + UdmInit(); + le_link = zend_register_list_destructors_ex(_free_udm_agent,NULL,"mnogosearch agent",module_number); + le_res = zend_register_list_destructors_ex(_free_udm_res,NULL,"mnogosearch result",module_number); + + REGISTER_LONG_CONSTANT("UDM_FIELD_URLID", UDM_FIELD_URLID,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UDM_FIELD_URL", UDM_FIELD_URL,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UDM_FIELD_CONTENT",UDM_FIELD_CONTENT,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UDM_FIELD_TITLE", UDM_FIELD_TITLE,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UDM_FIELD_KEYWORDS",UDM_FIELD_KEYWORDS,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UDM_FIELD_DESC", UDM_FIELD_DESC,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UDM_FIELD_TEXT", UDM_FIELD_TEXT,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UDM_FIELD_SIZE", UDM_FIELD_SIZE,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UDM_FIELD_SCORE", UDM_FIELD_SCORE,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UDM_FIELD_MODIFIED",UDM_FIELD_MODIFIED,CONST_CS | CONST_PERSISTENT); + + REGISTER_LONG_CONSTANT("UDM_PARAM_PAGE_SIZE",UDM_PARAM_PAGE_SIZE,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UDM_PARAM_PAGE_NUM",UDM_PARAM_PAGE_NUM,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UDM_PARAM_SEARCH_MODE",UDM_PARAM_SEARCH_MODE,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UDM_PARAM_CHARSET",UDM_PARAM_CHARSET,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UDM_PARAM_FOUND",UDM_PARAM_FOUND,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UDM_PARAM_NUM_ROWS",UDM_PARAM_NUM_ROWS,CONST_CS | CONST_PERSISTENT); + + + REGISTER_LONG_CONSTANT("UDM_MODE_ALL",UDM_MODE_ALL,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UDM_MODE_ANY",UDM_MODE_ANY,CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("UDM_MODE_BOOL",UDM_MODE_BOOL,CONST_CS | CONST_PERSISTENT); + + return SUCCESS; +} + + +DLEXPORT PHP_MSHUTDOWN_FUNCTION(mnogosearch) +{ + return SUCCESS; +} + + +DLEXPORT PHP_RINIT_FUNCTION(mnogosearch) +{ + return SUCCESS; +} + + +DLEXPORT PHP_MINFO_FUNCTION(mnogosearch) +{ + php_info_print_table_start(); + php_info_print_table_row(2, "mnoGoSearch Support", "enabled" ); + php_info_print_table_end(); +} + + +/* {{{ proto int mnogosearch_alloc_agent(string dbaddr [, string dbmode]) + Allocate mnoGoSearch session */ +DLEXPORT PHP_FUNCTION(udm_alloc_agent) +{ + switch(ZEND_NUM_ARGS()){ + + case 1: { + pval **yydbaddr; + char *dbaddr; + UDM_ENV * Env; + UDM_AGENT * Agent; + + if(zend_get_parameters_ex(1,&yydbaddr)==FAILURE){ + RETURN_FALSE; + } + convert_to_string_ex(yydbaddr); + dbaddr = (*yydbaddr)->value.str.val; + + Env=UdmAllocEnv(); + UdmEnvSetDBAddr(Env,dbaddr); + Agent=UdmAllocAgent(Env,0,UDM_OPEN_MODE_READ); + + ZEND_REGISTER_RESOURCE(return_value,Agent,le_link); + } + break; + + case 2: { + pval **yydbaddr; + pval **yydbmode; + char *dbaddr; + char *dbmode; + UDM_ENV * Env; + UDM_AGENT * Agent; + + if(zend_get_parameters_ex(2,&yydbaddr,&yydbmode)==FAILURE){ + RETURN_FALSE; + } + convert_to_string_ex(yydbaddr); + convert_to_string_ex(yydbmode); + dbaddr = (*yydbaddr)->value.str.val; + dbmode = (*yydbmode)->value.str.val; + + Env=UdmAllocEnv(); + UdmEnvSetDBAddr(Env,dbaddr); + UdmEnvSetDBMode(Env,dbmode); + Agent=UdmAllocAgent(Env,0,UDM_OPEN_MODE_READ); + + ZEND_REGISTER_RESOURCE(return_value,Agent,le_link); + } + break; + + default: + WRONG_PARAM_COUNT; + break; + } +} +/* }}} */ + + +/* {{{ proto int udm_set_agent_param(agent,var,val) + Set mnoGoSearch agent session parameters */ +DLEXPORT PHP_FUNCTION(udm_set_agent_param) +{ + pval **yyagent, **yyvar, **yyval; + char *val; + int var; + UDM_AGENT * Agent; + + switch(ZEND_NUM_ARGS()){ + + case 3: { + if(zend_get_parameters_ex(3,&yyagent,&yyvar,&yyval)==FAILURE){ + RETURN_FALSE; + } + convert_to_long_ex(yyvar); + convert_to_string_ex(yyval); + ZEND_FETCH_RESOURCE(Agent, UDM_AGENT *, yyagent, -1, "mnoGoSearch-agent", le_link); + var = (*yyvar)->value.lval; + val = (*yyval)->value.str.val; + } + break; + + default: + WRONG_PARAM_COUNT; + break; + } + + switch(var){ + case UDM_PARAM_PAGE_SIZE: { + Agent->page_size=atoi(val); + if(Agent->page_size<1)Agent->page_size=20; + } + break; + case UDM_PARAM_PAGE_NUM: { + Agent->page_number=atoi(val); + if(Agent->page_number<0)Agent->page_number=0; + } + break; + case UDM_PARAM_SEARCH_MODE: { + switch (atoi(val)){ + case UDM_MODE_ALL: + Agent->search_mode=UDM_MODE_ALL; + break; + case UDM_MODE_ANY: + Agent->search_mode=UDM_MODE_ANY; + break; + case UDM_MODE_BOOL: + Agent->search_mode=UDM_MODE_BOOL; + break; + default: + RETURN_STRING("",1); + break; + } + } + break; + default: + RETURN_STRING("",1); + break; + } +} +/* }}} */ + + + +/* {{{ proto int udm_free_agent(int agent_identifier) + Free mnoGoSearch session */ +DLEXPORT PHP_FUNCTION(udm_free_agent) +{ + pval ** yyagent; + UDM_RESULT * Agent; + switch(ZEND_NUM_ARGS()){ + case 1: { + if (zend_get_parameters_ex(1, &yyagent)==FAILURE) { + RETURN_FALSE; + } + } + break; + default: + WRONG_PARAM_COUNT; + break; + } + ZEND_FETCH_RESOURCE(Agent, UDM_RESULT *, yyagent, -1, "mnoGoSearch-agent", le_link); + zend_list_delete((*yyagent)->value.lval); +} +/* }}} */ + + +/* {{{ proto int udm_find(int agent_identifier,string query) + perform search */ +DLEXPORT PHP_FUNCTION(udm_find) +{ + pval ** yyquery, ** yyagent; + UDM_RESULT * Res; + UDM_AGENT * Agent; + int id=-1; + + switch(ZEND_NUM_ARGS()){ + case 2: { + if (zend_get_parameters_ex(2, &yyagent,&yyquery)==FAILURE) { + RETURN_FALSE; + } + } + break; + default: + WRONG_PARAM_COUNT; + break; + } + ZEND_FETCH_RESOURCE(Agent, UDM_AGENT *, yyagent, id, "mnoGoSearch-Agent", le_link); + convert_to_string_ex(yyquery); + Res=UdmFind(Agent,(*yyquery)->value.str.val); + ZEND_REGISTER_RESOURCE(return_value,Res,le_res); +} +/* }}} */ + + +/* {{{ proto int udm_get_res_field(int res_identifier,int row_num,const int field_name) + Fetch mnoGoSearch result field */ +DLEXPORT PHP_FUNCTION(udm_get_res_field){ + pval **yyres, **yyrow_num, **yyfield_name; + + UDM_RESULT * Res; + int row,field; + + switch(ZEND_NUM_ARGS()){ + case 3: { + if (zend_get_parameters_ex(3, &yyres,&yyrow_num,&yyfield_name)==FAILURE){ + RETURN_FALSE; + } + convert_to_string_ex(yyrow_num); + convert_to_string_ex(yyfield_name); + field=atoi((*yyfield_name)->value.str.val); + row=atoi((*yyrow_num)->value.str.val); + } + break; + default: + WRONG_PARAM_COUNT; + break; + } + ZEND_FETCH_RESOURCE(Res, UDM_RESULT *, yyres, -1, "mnoGoSearch-Result", le_res); + if(rownum_rows){ + switch(field){ + case UDM_FIELD_URL: RETURN_STRING((Res->Doc[row].url),1);break; + case UDM_FIELD_CONTENT: RETURN_STRING((Res->Doc[row].content_type),1);break; + case UDM_FIELD_TITLE: RETURN_STRING((Res->Doc[row].title),1);break; + case UDM_FIELD_KEYWORDS: RETURN_STRING((Res->Doc[row].keywords),1);break; + case UDM_FIELD_DESC: RETURN_STRING((Res->Doc[row].description),1);break; + case UDM_FIELD_TEXT: RETURN_STRING((Res->Doc[row].text),1);break; + case UDM_FIELD_SIZE: RETURN_LONG((Res->Doc[row].size));break; + case UDM_FIELD_URLID: RETURN_LONG((Res->Doc[row].url_id));break; + case UDM_FIELD_SCORE: RETURN_LONG((Res->Doc[row].rating));break; + case UDM_FIELD_MODIFIED: RETURN_LONG((Res->Doc[row].last_mod_time));break; + default: + RETURN_STRING("",1);break; + } + }else{ + RETURN_STRING("",1); + } +} +/* }}} */ + + +/* {{{ proto int udm_free_res(int res_identifier) + mnoGoSearch free result */ +DLEXPORT PHP_FUNCTION(udm_free_res) +{ + pval ** yyres; + UDM_RESULT * Res; + switch(ZEND_NUM_ARGS()){ + case 1: { + if (zend_get_parameters_ex(1, &yyres)==FAILURE) { + RETURN_FALSE; + } + } + break; + default: + WRONG_PARAM_COUNT; + break; + } + ZEND_FETCH_RESOURCE(Res, UDM_RESULT *, yyres, -1, "mnoGoSearch-Result", le_res); + zend_list_delete((*yyres)->value.lval); + +} +/* }}} */ + + +/* {{{ proto int udm_error(int agent_identifier) + mnoGoSearch error message */ +DLEXPORT PHP_FUNCTION(udm_error) +{ + pval ** yyagent; + UDM_AGENT * Agent; + + switch(ZEND_NUM_ARGS()){ + case 1: { + if (zend_get_parameters_ex(1, &yyagent)==FAILURE) { + RETURN_FALSE; + } + } + break; + default: + WRONG_PARAM_COUNT; + break; + } + ZEND_FETCH_RESOURCE(Agent, UDM_AGENT *, yyagent, -1, "mnoGoSearch-Agent", le_link); + RETURN_STRING(UdmDBErrorMsg(Agent->db),1); +} +/* }}} */ + +/* {{{ proto int udm_errno(int agent_identifier) + mnoGoSearch error number */ +DLEXPORT PHP_FUNCTION(udm_errno) +{ + pval ** yyagent; + UDM_AGENT * Agent; + switch(ZEND_NUM_ARGS()){ + case 1: { + if (zend_get_parameters_ex(1, &yyagent)==FAILURE) { + RETURN_FALSE; + } + } + break; + default: + WRONG_PARAM_COUNT; + break; + } + ZEND_FETCH_RESOURCE(Agent, UDM_AGENT *, yyagent, -1, "mnoGoSearch-Agent", le_link); + RETURN_LONG(UdmDBErrorCode(Agent->db)); +} +/* }}} */ + + +/* {{{ proto int udm_get_res_param(int res_identifier, const int param_id) + mnoGoSearch result parameters */ +DLEXPORT PHP_FUNCTION(udm_get_res_param) +{ + pval ** yyres, ** yyparam; + int param; + UDM_RESULT * Res; + switch(ZEND_NUM_ARGS()){ + case 2: { + if (zend_get_parameters_ex(2, &yyres, &yyparam)==FAILURE) { + RETURN_FALSE; + } + convert_to_long_ex(yyparam); + param=((*yyparam)->value.lval); + } + break; + default: + WRONG_PARAM_COUNT; + break; + } + ZEND_FETCH_RESOURCE(Res, UDM_RESULT *, yyres, -1, "mnoGoSearch-Result", le_res); + switch(param){ + case UDM_PARAM_NUM_ROWS: RETURN_LONG(Res->num_rows);break; + case UDM_PARAM_FOUND: RETURN_LONG(Res->total_found);break; + default: + /* FIXME: unknown parameter */ + RETURN_STRING("",1); + break; + } +} +/* }}} */ + +#endif + + +/* + * Local variables: + * End: + */ + diff --git a/ext/mnogosearch/php_mnogo.h b/ext/mnogosearch/php_mnogo.h new file mode 100644 index 0000000000..f1638db884 --- /dev/null +++ b/ext/mnogosearch/php_mnogo.h @@ -0,0 +1,80 @@ +/* + +----------------------------------------------------------------------+ + | PHP HTML Embedded Scripting Language Version 3.0 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997,1998 PHP Development Team (See Credits file) | + +----------------------------------------------------------------------+ + | This program is free software; you can redistribute it and/or modify | + | it under the terms of one of the following licenses: | + | | + | A) the GNU General Public License as published by the Free Software | + | Foundation; either version 2 of the License, or (at your option) | + | any later version. | + | | + | B) the PHP License as published by the PHP Development Team and | + | included in the distribution in the file: LICENSE | + | | + | This program is distributed in the hope that it will be useful, | + | but WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | + | GNU General Public License for more details. | + | | + | You should have received a copy of both licenses referred to here. | + | If you did not, or have any questions about PHP licensing, please | + | contact core@php.net. | + +----------------------------------------------------------------------+ + | Authors: | + | Initial version by Alex Barkov | + | and Ramil Kalimullin | + | Further development by Sergey Kartashoff | + +----------------------------------------------------------------------+ + */ + +/* $Id: php_mnogo.h,v 0.3 2001/01/27 15:30:00 */ + + +#ifndef _PHP_MNOGO_H +#define _PHP_MNOGO_H + +#if HAVE_MNOGOSEARCH + +extern zend_module_entry mnogosearch_module_entry; +#define mnogosearch_module_ptr &mnogosearch_module_entry + +#ifdef PHP_WIN32 +#define PHP_MNOGO_API __declspec(dllexport) +#else +#define PHP_MNOGO_API +#endif + +#ifdef ZTS +#include "TSRM.h" +#endif + +/* mnoGoSearch functions */ +DLEXPORT PHP_MINIT_FUNCTION(mnogosearch); +DLEXPORT PHP_RINIT_FUNCTION(mnogosearch); +DLEXPORT PHP_MSHUTDOWN_FUNCTION(mnogosearch); +DLEXPORT PHP_MINFO_FUNCTION(mnogosearch); + +DLEXPORT PHP_FUNCTION(udm_alloc_agent); +DLEXPORT PHP_FUNCTION(udm_set_agent_param); +DLEXPORT PHP_FUNCTION(udm_free_agent); + +DLEXPORT PHP_FUNCTION(udm_error); +DLEXPORT PHP_FUNCTION(udm_errno); + +DLEXPORT PHP_FUNCTION(udm_find); +DLEXPORT PHP_FUNCTION(udm_free_res); +DLEXPORT PHP_FUNCTION(udm_get_res_field); +DLEXPORT PHP_FUNCTION(udm_get_res_param); + +#else + +#define mnogosearch_module_ptr NULL + +#endif + +#define phpext_mnogosearch_ptr mnogosearch_module_ptr + +#endif /* _PHP_MNOGO_H */ diff --git a/ext/mnogosearch/setup.stub b/ext/mnogosearch/setup.stub new file mode 100644 index 0000000000..e92ebc06f9 --- /dev/null +++ b/ext/mnogosearch/setup.stub @@ -0,0 +1,10 @@ +# $Source$ +# $Id$ + +define_option with-mnogosearch 'mnoGoSearch support?' yesnodir \ + 'no /usr/local/udmsearch mnoGoSearch install' \ +' Whether to build PHP with mnoGoSearch support. + More info about mnoGoSearch can be found at http://search.mnogo.ru/.' + + + \ No newline at end of file diff --git a/ext/mnogosearch/test.php b/ext/mnogosearch/test.php new file mode 100644 index 0000000000..736eac727f --- /dev/null +++ b/ext/mnogosearch/test.php @@ -0,0 +1,79 @@ + + + +
+ + +
+ +
+
+\n");
+		exit();
+	}
+	
+// Stage 1: allocate UdmSearch agent, set DBAddr and DBMode
+// DBMode is optional, "single" by default
+
+	$udm=Udm_Alloc_Agent("mysql://udm:udm@localhost/udm/",'crc-multi');
+	
+// Stage 2: set search parameters
+
+	$page_size=10;
+	$page_number=0;
+	$search_mode=UDM_MODE_BOOL;
+	$first=$page_size*$page_number+1;
+
+	Udm_Set_Agent_Param($udm,UDM_PARAM_PAGE_SIZE,$page_size);
+	Udm_Set_Agent_Param($udm,UDM_PARAM_PAGE_NUM,$page_number);
+	Udm_Set_Agent_Param($udm,UDM_PARAM_SEARCH_MODE,$search_mode);
+	
+
+// Stage 3: perform search 
+
+	$res=Udm_Find($udm,$q);	
+
+// Stage 4: display results
+
+	// Check error code
+	if(($errno=Udm_Errno($udm))>0){
+		// Display error message
+		printf("Error #%d: '%s'\n",$errno,Udm_Error($udm));
+	}else{
+
+		// Get result parameters
+		$total=Udm_Get_Res_Param($res,UDM_PARAM_FOUND);
+		$rows=Udm_Get_Res_Param($res,UDM_PARAM_NUM_ROWS);
+
+		printf("Documents %d-%d from %d total found\n\n",
+			$first,$first+$rows-1,$total);
+
+		// Fetch all rows
+		for($i=0;$i<$rows;$i++){
+			printf("%3d. %s\n",$first+$i,Udm_Get_Res_Field($res,$i,UDM_FIELD_URL));
+			printf("     CONT : %s\n",htmlspecialchars(Udm_Get_Res_Field($res,$i,UDM_FIELD_CONTENT)));
+			printf("     TITLE: %s\n",htmlspecialchars(Udm_Get_Res_Field($res,$i,UDM_FIELD_TITLE)));
+			printf("     KEYWORDS: %s\n",htmlspecialchars(Udm_Get_Res_Field($res,$i,UDM_FIELD_KEYWORDS)));
+			printf("     DESC: %s\n",htmlspecialchars(Udm_Get_Res_Field($res,$i,UDM_FIELD_DESC)));
+			printf("     TEXT: %s\n",htmlspecialchars(Udm_Get_Res_Field($res,$i,UDM_FIELD_TEXT)));
+			printf("     SIZE : %d\n",Udm_Get_Res_Field($res,$i,UDM_FIELD_SIZE));
+			printf("     MODIFIED : %s\n",Udm_Get_Res_Field($res,$i,UDM_FIELD_MODIFIED));
+			printf("     URLID : %d\n",Udm_Get_Res_Field($res,$i,UDM_FIELD_URLID));
+			printf("     SCORE : %d\n",Udm_Get_Res_Field($res,$i,UDM_FIELD_SCORE));
+			printf("---------\n");
+		}
+				
+		// Free result
+		Udm_Free_Res($res);
+	}
+
+//Stage 5: free UdmSearch agent
+
+	Udm_Free_Agent($udm);
+?>
+
+
+ +