<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >udm_load_ispell_data</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="mnoGoSearch Functions" HREF="ref.mnogosearch.html"><LINK REL="PREVIOUS" TITLE="udm_hash32" HREF="function.udm-hash32.html"><LINK REL="NEXT" TITLE="udm_open_stored" HREF="function.udm-open-stored.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.udm-hash32.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.udm-open-stored.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.udm-load-ispell-data" ></A >udm_load_ispell_data</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN127529" ></A ><P > (PHP 4 >= 4.0.5, PHP 5 <= 5.0.4)</P >udm_load_ispell_data -- Load ispell data</DIV ><DIV CLASS="refsect1" ><A NAME="AEN127532" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >udm_load_ispell_data</B > ( resource agent, int var, string val1, string val2, int flag )<BR ></BR ><P > <B CLASS="function" >udm_load_ispell_data()</B > loads ispell data. 如果成功则返回 <TT CLASS="constant" ><B >TRUE</B ></TT >,失败则返回 <TT CLASS="constant" ><B >FALSE</B ></TT >。 </P ><P > <CODE CLASS="parameter" >agent</CODE > - agent link identifier, received after call to <A HREF="function.udm-alloc-agent.html" ><B CLASS="function" >udm_alloc_agent()</B ></A >. </P ><P > <CODE CLASS="parameter" >var</CODE > - parameter, indicating the source for ispell data. May have the following values: </P ><P > After using this function to free memory allocated for ispell data, please use <A HREF="function.udm-free-ispell-data.html" ><B CLASS="function" >udm_free_ispell_data()</B ></A >, even if you use UDM_ISPELL_TYPE_SERVER mode. </P ><P > The fastest mode is UDM_ISPELL_TYPE_SERVER. UDM_ISPELL_TYPE_TEXT is slower and UDM_ISPELL_TYPE_DB is the slowest. The above pattern is <TT CLASS="constant" ><B >TRUE</B ></TT > for mnoGoSearch 3.1.10 - 3.1.11. It is planned to speed up DB mode in future versions and it is going to be faster than TEXT mode. </P ><P ></P ><UL ><LI ><P > UDM_ISPELL_TYPE_DB - indicates that ispell data should be loaded from SQL. In this case, parameters <CODE CLASS="parameter" >val1</CODE > and <CODE CLASS="parameter" >val2</CODE > are ignored and should be left blank. <CODE CLASS="parameter" >flag</CODE > should be equal to <TT CLASS="literal" >1</TT >. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > <CODE CLASS="parameter" >flag</CODE > indicates that after loading ispell data from defined source it should be sorted (it is necessary for correct functioning of ispell). In case of loading ispell data from files there may be several calls to <B CLASS="function" >udm_load_ispell_data()</B >, and there is no sense to sort data after every call, but only after the last one. Since in db mode all the data is loaded by one call, this parameter should have the value <TT CLASS="literal" >1</TT >. In this mode in case of error, e.g. if ispell tables are absent, the function will return <TT CLASS="constant" ><B >FALSE</B ></TT > and code and error message will be accessible through <A HREF="function.udm-error.html" ><B CLASS="function" >udm_error()</B ></A > and <A HREF="function.udm-errno.html" ><B CLASS="function" >udm_errno()</B ></A >. </P ></BLOCKQUOTE ></DIV ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN127581" ></A ><P ><B >例 1. <B CLASS="function" >udm_load_ispell_data()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#007700">if (! </font><font color="#0000BB">udm_load_ispell_data</font><font color="#007700">(</font><font color="#0000BB">$udm</font><font color="#007700">, </font><font color="#0000BB">UDM_ISPELL_TYPE_DB</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">)) {<br /> </font><font color="#0000BB">printf</font><font color="#007700">(</font><font color="#DD0000">"Error #%d: '%s'\n"</font><font color="#007700">, </font><font color="#0000BB">udm_errno</font><font color="#007700">(</font><font color="#0000BB">$udm</font><font color="#007700">), </font><font color="#0000BB">udm_error</font><font color="#007700">(</font><font color="#0000BB">$udm</font><font color="#007700">));<br /> exit;<br />}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></LI ><LI ><P > UDM_ISPELL_TYPE_AFFIX - indicates that ispell data should be loaded from file and initiates loading affixes file. In this case <CODE CLASS="parameter" >val1</CODE > defines double letter language code for which affixes are loaded, and <CODE CLASS="parameter" >val2</CODE > - file path. Please note, that if a relative path entered, the module looks for the file not in UDM_CONF_DIR, but in relation to current path, i.e. to the path where the script is executed. In case of error in this mode, e.g. if file is absent, the function will return <TT CLASS="constant" ><B >FALSE</B ></TT >, and an error message will be displayed. Error message text cannot be accessed through <A HREF="function.udm-error.html" ><B CLASS="function" >udm_error()</B ></A > and <A HREF="function.udm-errno.html" ><B CLASS="function" >udm_errno()</B ></A >, since those functions can only return messages associated with SQL. Please, see <CODE CLASS="parameter" >flag</CODE > parameter description in UDM_ISPELL_TYPE_DB. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN127594" ></A ><P ><B >例 2. <B CLASS="function" >udm_load_ispell_data()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#007700">if ((! </font><font color="#0000BB">udm_load_ispell_data</font><font color="#007700">(</font><font color="#0000BB">$udm</font><font color="#007700">, </font><font color="#0000BB">UDM_ISPELL_TYPE_AFFIX</font><font color="#007700">, </font><font color="#DD0000">'en'</font><font color="#007700">, </font><font color="#DD0000">'/opt/ispell/en.aff'</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">)) ||<br /> (! </font><font color="#0000BB">udm_load_ispell_data</font><font color="#007700">(</font><font color="#0000BB">$udm</font><font color="#007700">, </font><font color="#0000BB">UDM_ISPELL_TYPE_AFFIX</font><font color="#007700">, </font><font color="#DD0000">'ru'</font><font color="#007700">, </font><font color="#DD0000">'/opt/ispell/ru.aff'</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">)) ||<br /> (! </font><font color="#0000BB">udm_load_ispell_data</font><font color="#007700">(</font><font color="#0000BB">$udm</font><font color="#007700">, </font><font color="#0000BB">UDM_ISPELL_TYPE_SPELL</font><font color="#007700">, </font><font color="#DD0000">'en'</font><font color="#007700">, </font><font color="#DD0000">'/opt/ispell/en.dict'</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">)) ||<br /> (! </font><font color="#0000BB">udm_load_ispell_data</font><font color="#007700">(</font><font color="#0000BB">$udm</font><font color="#007700">, </font><font color="#0000BB">UDM_ISPELL_TYPE_SPELL</font><font color="#007700">, </font><font color="#DD0000">'ru'</font><font color="#007700">, </font><font color="#DD0000">'/opt/ispell/ru.dict'</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">))) {<br /> exit;<br />}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > <CODE CLASS="parameter" >flag</CODE > is equal to <TT CLASS="literal" >1</TT > only in the last call. </P ></BLOCKQUOTE ></DIV ></LI ><LI ><P > UDM_ISPELL_TYPE_SPELL - indicates that ispell data should be loaded from file and initiates loading of ispell dictionary file. In this case <CODE CLASS="parameter" >val1</CODE > defines double letter language code for which affixes are loaded, and <CODE CLASS="parameter" >val2</CODE > - file path. Please note, that if a relative path entered, the module looks for the file not in UDM_CONF_DIR, but in relation to current path, i.e. to the path where the script is executed. In case of error in this mode, e.g. if file is absent, the function will return <TT CLASS="constant" ><B >FALSE</B ></TT >, and an error message will be displayed. Error message text cannot be accessed through <A HREF="function.udm-error.html" ><B CLASS="function" >udm_error()</B ></A > and <A HREF="function.udm-errno.html" ><B CLASS="function" >udm_errno()</B ></A >, since those functions can only return messages associated with SQL. Please, see <CODE CLASS="parameter" >flag</CODE > parameter description in UDM_ISPELL_TYPE_DB. </P ><DIV CLASS="informalexample" ><P ></P ><A NAME="AEN127610" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /> </font><font color="#007700">if ((! </font><font color="#0000BB">Udm_Load_Ispell_Data</font><font color="#007700">(</font><font color="#0000BB">$udm</font><font color="#007700">, </font><font color="#0000BB">UDM_ISPELL_TYPE_AFFIX</font><font color="#007700">, </font><font color="#DD0000">'en'</font><font color="#007700">, </font><font color="#DD0000">'/opt/ispell/en.aff'</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">)) ||<br /> (! </font><font color="#0000BB">Udm_Load_Ispell_Data</font><font color="#007700">(</font><font color="#0000BB">$udm</font><font color="#007700">, </font><font color="#0000BB">UDM_ISPELL_TYPE_AFFIX</font><font color="#007700">, </font><font color="#DD0000">'ru'</font><font color="#007700">, </font><font color="#DD0000">'/opt/ispell/ru.aff'</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">)) ||<br /> (! </font><font color="#0000BB">Udm_Load_Ispell_Data</font><font color="#007700">(</font><font color="#0000BB">$udm</font><font color="#007700">, </font><font color="#0000BB">UDM_ISPELL_TYPE_SPELL</font><font color="#007700">, </font><font color="#DD0000">'en'</font><font color="#007700">, </font><font color="#DD0000">'/opt/ispell/en.dict'</font><font color="#007700">, </font><font color="#0000BB">0</font><font color="#007700">)) ||<br /> (! </font><font color="#0000BB">Udm_Load_Ispell_Data</font><font color="#007700">(</font><font color="#0000BB">$udm</font><font color="#007700">, </font><font color="#0000BB">UDM_ISPELL_TYPE_SPELL</font><font color="#007700">, </font><font color="#DD0000">'ru'</font><font color="#007700">, </font><font color="#DD0000">'/opt/ispell/ru.dict'</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">))) {<br /> exit;<br /> }<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > <CODE CLASS="parameter" >flag</CODE > is equal to <TT CLASS="literal" >1</TT > only in the last call. </P ></BLOCKQUOTE ></DIV ></LI ><LI ><P > UDM_ISPELL_TYPE_SERVER - enables spell server support. <CODE CLASS="parameter" >val1</CODE > parameter indicates address of the host running spell server. <CODE CLASS="parameter" >val2</CODE > ` is not used yet, but in future releases it is going to indicate number of port used by spell server. <CODE CLASS="parameter" >flag</CODE > parameter in this case is not needed since ispell data is stored on spellserver already sorted. </P ><P > Spelld server reads spell-data from a separate configuration file (/usr/local/mnogosearch/etc/spelld.conf by default), sorts it and stores in memory. With clients server communicates in two ways: to indexer all the data is transferred (so that indexer starts faster), from search.cgi server receives word to normalize and then passes over to client (search.cgi) list of normalized word forms. This allows fastest, compared to db and text modes processing of search queries (by omitting loading and sorting all the spell data). </P ><P > <B CLASS="function" >udm_load_ispell_data()</B > function in UDM_ISPELL_TYPE_SERVER mode does not actually load ispell data, but only defines server address. In fact, server is automatically used by <A HREF="function.udm-find.html" ><B CLASS="function" >udm_find()</B ></A > function when performing search. In case of errors, e.g. if spellserver is not running or invalid host indicated, there are no messages returned and ispell conversion does not work. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > This function is available in mnoGoSearch 3.1.12 or later. </P ></BLOCKQUOTE ></DIV ><P >Example:</P ><DIV CLASS="informalexample" ><P ></P ><A NAME="AEN127628" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#007700">if (!</font><font color="#0000BB">udm_load_ispell_data</font><font color="#007700">(</font><font color="#0000BB">$udm</font><font color="#007700">, </font><font color="#0000BB">UDM_ISPELL_TYPE_SERVER</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">, </font><font color="#0000BB">1</font><font color="#007700">)) {<br /> echo </font><font color="#DD0000">"Error loading ispell data from server<br />\n"</font><font color="#007700">;<br /> exit;<br />}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV ></LI ></UL ></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="function.udm-hash32.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.udm-open-stored.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >udm_hash32</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.mnogosearch.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >udm_open_stored</TD ></TR ></TABLE ></DIV ></BODY ></HTML >