summaryrefslogtreecommitdiff
path: root/ext/mnogosearch
diff options
context:
space:
mode:
authorSergey Kartashoff <gluke@php.net>2002-08-03 08:53:27 +0000
committerSergey Kartashoff <gluke@php.net>2002-08-03 08:53:27 +0000
commit37e58c21b2197c5f96a802ba3b2cd0740e36593e (patch)
treee45f940df5dac5c05fff09109503527ed7cffda1 /ext/mnogosearch
parentc90764d753d853d75d660c108433feecbf4fcdf1 (diff)
downloadphp-git-37e58c21b2197c5f96a802ba3b2cd0740e36593e.tar.gz
- An Udm_Make_Excerpt function has been added to mnogosearch extension
to support excerpts while using with mnogosearch-3.2.5 or later.
Diffstat (limited to 'ext/mnogosearch')
-rw-r--r--ext/mnogosearch/index.php4
-rw-r--r--ext/mnogosearch/php_mnogo.c55
-rw-r--r--ext/mnogosearch/php_mnogo.h1
3 files changed, 59 insertions, 1 deletions
diff --git a/ext/mnogosearch/index.php b/ext/mnogosearch/index.php
index b7f5cb19c1..4bf504f9cf 100644
--- a/ext/mnogosearch/index.php
+++ b/ext/mnogosearch/index.php
@@ -970,6 +970,10 @@ if(($errno=Udm_Errno($udm_agent))>0){
}
for($i=0;$i<$rows;$i++){
+ if (Udm_Api_Version() >= 30204) {
+ $excerpt_flag=Udm_Make_Excerpt($udm_agent, $res, $i);
+ }
+
$ndoc=Udm_Get_Res_Field($res,$i,UDM_FIELD_ORDER);
$rating=Udm_Get_Res_Field($res,$i,UDM_FIELD_RATING);
$url=Udm_Get_Res_Field($res,$i,UDM_FIELD_URL);
diff --git a/ext/mnogosearch/php_mnogo.c b/ext/mnogosearch/php_mnogo.c
index 1f2a70f01f..60b5d16d6f 100644
--- a/ext/mnogosearch/php_mnogo.c
+++ b/ext/mnogosearch/php_mnogo.c
@@ -149,7 +149,8 @@ function_entry mnogosearch_functions[] = {
PHP_FE(udm_crc32, NULL)
#endif
#if UDM_VERSION_ID >= 30204
- PHP_FE(udm_parse_query_string,NULL)
+ PHP_FE(udm_parse_query_string, NULL)
+ PHP_FE(udm_make_excerpt, NULL)
#endif
#endif
@@ -1502,6 +1503,58 @@ DLEXPORT PHP_FUNCTION(udm_parse_query_string)
RETURN_TRUE;
}
/* }}} */
+
+/* {{{ proto int udm_make_excerpt(int agent, int res, int row)
+ Perform search */
+DLEXPORT PHP_FUNCTION(udm_make_excerpt)
+{
+ pval ** yyagent, **yyres, **yyrow_num;
+ UDM_RESULT * Res;
+ UDM_AGENT * Agent;
+ int id=-1, row;
+
+ switch(ZEND_NUM_ARGS()){
+ case 3: {
+ if (zend_get_parameters_ex(3, &yyagent, &yyres, &yyrow_num)==FAILURE) {
+ RETURN_FALSE;
+ }
+ convert_to_string_ex(yyrow_num);
+ row=atoi(Z_STRVAL_PP(yyrow_num));
+ }
+ break;
+ default:
+ WRONG_PARAM_COUNT;
+ break;
+ }
+ ZEND_FETCH_RESOURCE(Agent, UDM_AGENT *, yyagent, id, "mnoGoSearch-Agent", le_link);
+ ZEND_FETCH_RESOURCE(Res, UDM_RESULT *, yyres, -1, "mnoGoSearch-Result", le_res);
+
+ if(row<Res->num_rows){
+ const char *al;
+ char *Excerpt;
+
+ al = UdmVarListFindStr(&(Res->Doc[row].Sections), "URL", "");
+ UdmVarListReplaceInt(&(Res->Doc[row].Sections), "STORED_ID", UdmCRC32(al, strlen(al)));
+ Excerpt = UdmExcerptDoc(Agent, Res, &(Res->Doc[row]), 256);
+
+ if (Excerpt != NULL) {
+ char *HlExcerpt = UdmHlConvert(&Res->WWList, Excerpt, Agent->Conf->lcs, Agent->Conf->bcs);
+ UdmVarListReplaceInt(&(Res->Doc[row].Sections),"ST",1);
+ UdmVarListReplaceStr(&(Res->Doc[row].Sections),"body",HlExcerpt);
+ UDM_FREE(HlExcerpt);
+ UDM_FREE(Excerpt);
+ } else {
+ UdmVarListReplaceInt(&(Res->Doc[row].Sections),"ST",0);
+ RETURN_FALSE;
+ }
+ }else{
+ php_error(E_WARNING,"%s(): row number too large", get_active_function_name(TSRMLS_C));
+ RETURN_FALSE;
+ }
+
+ RETURN_TRUE;
+}
+/* }}} */
#endif
/* {{{ proto int udm_find(int agent, string query)
diff --git a/ext/mnogosearch/php_mnogo.h b/ext/mnogosearch/php_mnogo.h
index ab91a520a9..10116682a8 100644
--- a/ext/mnogosearch/php_mnogo.h
+++ b/ext/mnogosearch/php_mnogo.h
@@ -67,6 +67,7 @@ DLEXPORT PHP_FUNCTION(udm_crc32);
#endif
#if UDM_VERSION_ID >= 30204
DLEXPORT PHP_FUNCTION(udm_parse_query_string);
+DLEXPORT PHP_FUNCTION(udm_make_excerpt);
#endif
#endif