<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >UdmFind2</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="mnoGoSearch 3.3.9 reference manual" HREF="index.html"><LINK REL="UP" TITLE="mnoGoSearch C API function reference" HREF="msearch-c-api.html"><LINK REL="PREVIOUS" TITLE="UdmAgentAddLine" HREF="msearch-c-api-udmagentaddline.html"><LINK REL="NEXT" TITLE="UdmResultFree" HREF="msearch-c-api-udmresultfree.html"><LINK REL="STYLESHEET" TYPE="text/css" HREF="mnogo.css"><META NAME="Description" CONTENT="mnoGoSearch - Full Featured Web site Open Source Search Engine Software over the Internet and Intranet Web Sites Based on SQL Database. It is a Free search software covered by GNU license."><META NAME="Keywords" CONTENT="shareware, freeware, download, internet, unix, utilities, search engine, text retrieval, knowledge retrieval, text search, information retrieval, database search, mining, intranet, webserver, index, spider, filesearch, meta, free, open source, full-text, udmsearch, website, find, opensource, search, searching, software, udmsearch, engine, indexing, system, web, ftp, http, cgi, php, SQL, MySQL, database, php3, FreeBSD, Linux, Unix, mnoGoSearch, MacOS X, Mac OS X, Windows, 2000, NT, 95, 98, GNU, GPL, url, grabbing"></HEAD ><BODY CLASS="refentry" BGCOLOR="#EEEEEE" TEXT="#000000" LINK="#000080" VLINK="#800080" ALINK="#FF0000" ><!--#include virtual="body-before.html"--><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" ><SPAN CLASS="application" >mnoGoSearch</SPAN > 3.3.9 reference manual: Full-featured search engine software</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="msearch-c-api-udmagentaddline.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="msearch-c-api-udmresultfree.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="c-api-UdmFind2" ></A >UdmFind2</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN14354" ></A ><H2 >Name</H2 >UdmFind2 -- Executes a search query</DIV ><DIV CLASS="refsect1" ><A NAME="AEN14357" ></A ><H2 >Description</H2 ><code class="methodsynopsis" > <span class="type" >UDM_RESULT* </span >UdmFind2(<span class="methodparam" ><span class="type" >UDM_AGENT* </span ><span class="parameter" >Agent</span ></span ><span class="methodparam" >, <span class="type" >const char* </span ><span class="parameter" >query</span ></span >); </code ><P > Executes a search query in the search session, pointed by the <CODE CLASS="parameter" >Agent</CODE > variable, and returns search results. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN14370" ></A ><H2 >Parameters</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >Agent</CODE ></DT ><DD ><P > Pointer to a variable of type <SPAN CLASS="type" >UDM_AGENT</SPAN >, should be the address of an existing variable of <SPAN CLASS="type" >UDM_AGENT</SPAN > type. </P ></DD ><DT ><CODE CLASS="parameter" >query</CODE ></DT ><DD ><P > Search query, using the same format with <SPAN CLASS="application" >search.cgi</SPAN > <CODE CLASS="varname" >QUERY_STRING</CODE > described in <A HREF="msearch-doingsearch.html#search-params" >the Section called <I >Search parameters <A NAME="AEN4440" ></A ></I > in Chapter 10</A >. </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN14389" ></A ><H2 >Return Values</H2 ><P > A pointer to an allocated variable of <SPAN CLASS="type" >UDM_RESULT</SPAN > type, or <TT CLASS="literal" >NULL</TT > on error. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN14394" ></A ><H2 >Notes</H2 ><P > <CODE CLASS="function" >UdmFind2()</CODE > can fail if the search session could not open a connection to the database specified by the <B CLASS="command" ><A HREF="msearch-cmdref-dbaddr.html" >DBAddr</A ></B > command, or if some of the SQL queries which were sent to the database returnd on error. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN14400" ></A ><H2 >Examples</H2 ><P > <DIV CLASS="example" ><A NAME="AEN14403" ></A ><P ><B >Example 1. <CODE CLASS="function" >UdmFind2</CODE > example</B ></P ><PRE CLASS="programlisting" > UDM_RESULT *Res; if (!(Res= UdmFind2(Agent, "q=search+words&ps=10")) { printf('Error: UdmFind2 failed'); exit(1); } </PRE ></DIV > </P ><P > <DIV CLASS="example" ><A NAME="AEN14408" ></A ><P ><B >Example 2. <CODE CLASS="function" >UdmFind2</CODE > - a complete search application example</B ></P ><PRE CLASS="programlisting" > #include <stdio.h> #include <udmsearch.h> int main(int ac, char **av) { UDM_ENV Env; UDM_AGENT Agent; UDM_RESULT *Res; size_t row; char query[256]; if (ac < 2) { printf("Usage: %s query\n", av[0]); exit(1); } if (!UdmEnvInit(&Env) || !UdmAgentInit(&Agent, &Env, 0)) goto err; if (UDM_OK != UdmAgentAddLine(&Agent, "DBAddr mysql://root@localhost/msdn33/")) goto err; udm_snprintf(query, sizeof(query), "q=%s", av[1]); if (!(Res= UdmFind2(&Agent, query))) goto err; printf("Documents %d-%d from %d total found\n", Res->first, Res->last, Res->total_found); for (row= 0; row < Res->num_rows; row++) { UDM_DOCUMENT *Doc= &Res->Doc[row]; printf("ResultNo: %d\n", UdmVarListFindInt(&Doc->Sections, "Order", 0)); printf("ID : %d\n", UdmVarListFindInt(&Doc->Sections, "ID", 0)); printf("Size : %d bytes\n", UdmVarListFindInt(&Doc->Sections, "Content-Length", 0)); printf("Type : '%s'\n", UdmVarListFindStr(&Doc->Sections, "Content-Type", "")); printf("Title : '%s'\n", UdmVarListFindStr(&Doc->Sections, "title", "")); printf("Body : '%s'\n", UdmVarListFindStr(&Doc->Sections, "body", "")); printf("\n"); } UdmResultFree(Res); UdmAgentFree(&Agent); UdmEnvFree(&Env); return 0; err: fprintf(stderr, "Error: '%s'\n", UdmEnvErrMsg(&Env)); return 1; } </PRE ></DIV > </P ><P > <DIV CLASS="example" ><A NAME="AEN14413" ></A ><P ><B >Example 3. <CODE CLASS="function" >Makefile</CODE > example</B ></P ><PRE CLASS="programlisting" > CFLAGS=-I/usr/local/mnogosearch/include -Wall LDFLAGS=-L/usr/local/mnogosearch/lib -lmnogosearch -Wl,--rpath -Wl,/usr/local/mnogosearch/lib CC=gcc all: search search.o: search.c $(CC) $(CFLAGS) -c search.c -o search.o search: search.o $(CC) $(LDFLAGS) search.o -o search clean: rm -rf search search.o </PRE ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN14417" ></A ><H2 >See Also</H2 ><P > <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD ><CODE CLASS="function" ><A HREF="msearch-c-api-udmenvinit.html" >UdmEnvInit</A ></CODE ></TD ></TR ><TR ><TD ><CODE CLASS="function" ><A HREF="msearch-c-api-udmenvfree.html" >UdmEnvFree</A ></CODE ></TD ></TR ><TR ><TD ><CODE CLASS="function" ><A HREF="msearch-c-api-udmagentfree.html" >UdmAgentFree</A ></CODE ></TD ></TR ><TR ><TD ><A HREF="msearch-doingsearch.html#search-params" >the Section called <I >Search parameters <A NAME="AEN4440" ></A ></I > in Chapter 10</A ></TD ></TR ></TBODY ></TABLE ><P ></P > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="msearch-c-api-udmagentaddline.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="msearch-c-api-udmresultfree.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >UdmAgentAddLine</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="msearch-c-api.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >UdmResultFree</TD ></TR ></TABLE ></DIV ><!--#include virtual="body-after.html"--></BODY ></HTML >