<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>search — Translate Toolkit 1.9.0 documentation</title> <link rel="stylesheet" href="../_static/basic.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <link rel="stylesheet" href="../_static/bootstrap.css" type="text/css" /> <link rel="stylesheet" href="../_static/bootstrap-sphinx.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '1.9.0', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/bootstrap.js"></script> <script type="text/javascript" src="../_static/bootstrap-sphinx.js"></script> <link rel="top" title="Translate Toolkit 1.9.0 documentation" href="../index.html" /> <link rel="up" title="API" href="index.html" /> <link rel="next" title="services" href="services.html" /> <link rel="prev" title="misc" href="misc.html" /> </head> <body> <div id="navbar" class="navbar navbar-fixed-top"> <div class="navbar-inner"> <div class="container-fluid"> <a class="brand" href="../index.html">Translate Toolkit</a> <span class="navbar-text pull-left"><b>1.9.0</b></span> <ul class="nav"> <li class="divider-vertical"></li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Site <b class="caret"></b></a> <ul class="dropdown-menu globaltoc"><ul class="simple"> </ul> <ul> <li class="toctree-l1"><a class="reference internal" href="../features.html">Features</a></li> <li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li> <li class="toctree-l1"><a class="reference internal" href="../commands/index.html">Converters</a></li> <li class="toctree-l1"><a class="reference internal" href="../commands/index.html#tools">Tools</a></li> <li class="toctree-l1"><a class="reference internal" href="../commands/index.html#scripts">Scripts</a></li> <li class="toctree-l1"><a class="reference internal" href="../guides/index.html">Use Cases</a></li> <li class="toctree-l1"><a class="reference internal" href="../formats/index.html">Supported formats</a></li> </ul> <ul> <li class="toctree-l1"><a class="reference internal" href="../styleguide.html">Translate Styleguide</a></li> <li class="toctree-l1"><a class="reference internal" href="../styleguide.html#documentation">Documentation</a></li> <li class="toctree-l1"><a class="reference internal" href="../development/building.html">Building</a></li> <li class="toctree-l1"><a class="reference internal" href="../development/contributing.html">Contributing</a></li> <li class="toctree-l1"><a class="reference internal" href="../development/developers.html">Translate Toolkit Developers Guide</a></li> </ul> <ul> <li class="toctree-l1"><a class="reference internal" href="index.html">API</a></li> </ul> <ul> <li class="toctree-l1"><a class="reference internal" href="../changelog.html">Important Changes</a></li> <li class="toctree-l1"><a class="reference internal" href="../history.html">History of the Translate Toolkit</a></li> <li class="toctree-l1"><a class="reference internal" href="../license.html">License</a></li> </ul> </ul> </li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">Page <b class="caret"></b></a> <ul class="dropdown-menu localtoc"><ul> <li><a class="reference internal" href="#">search</a><ul> <li><a class="reference internal" href="#module-translate.search.indexing">indexing</a><ul> <li><a class="reference internal" href="#module-translate.search.indexing.CommonIndexer">CommonIndexer</a></li> <li><a class="reference internal" href="#pyluceneindexer1">PyLuceneIndexer1</a></li> <li><a class="reference internal" href="#module-translate.search.indexing.PyLuceneIndexer">PyLuceneIndexer</a></li> <li><a class="reference internal" href="#module-translate.search.indexing.XapianIndexer">XapianIndexer</a></li> </ul> </li> <li><a class="reference internal" href="#module-translate.search.lshtein">lshtein</a></li> <li><a class="reference internal" href="#module-translate.search.match">match</a></li> <li><a class="reference internal" href="#module-translate.search.segment">segment</a></li> <li><a class="reference internal" href="#module-translate.search.terminology">terminology</a></li> </ul> </li> </ul> </ul> </li> <li><a href="misc.html" title="previous chapter">« misc</a></li> <li><a href="services.html" title="next chapter">services »</a></li> </ul> <form class="navbar-search pull-right" action="../search.html" method="get"> <input type="text" name="q" placeholder="Search" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </ul> </div> </div> </div> </div> <div class="container content"> <div class="section" id="module-translate.search"> <span id="search"></span><h1>search<a class="headerlink" href="#module-translate.search" title="Permalink to this headline">¶</a></h1> <p>Services for searching and matching of text.</p> <div class="section" id="module-translate.search.indexing"> <span id="indexing"></span><h2>indexing<a class="headerlink" href="#module-translate.search.indexing" title="Permalink to this headline">¶</a></h2> <p>Interface for differrent indexing engines for the Translate Toolkit.</p> <div class="section" id="module-translate.search.indexing.CommonIndexer"> <span id="commonindexer"></span><h3>CommonIndexer<a class="headerlink" href="#module-translate.search.indexing.CommonIndexer" title="Permalink to this headline">¶</a></h3> <p>base class for interfaces to indexing engines for pootle</p> <dl class="class"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase"> <em class="property">class </em><tt class="descclassname">translate.search.indexing.CommonIndexer.</tt><tt class="descname">CommonDatabase</tt><big>(</big><em>basedir</em>, <em>analyzer=None</em>, <em>create_allowed=True</em><big>)</big><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase" title="Permalink to this definition">¶</a></dt> <dd><p>Base class for indexing support.</p> <p>Any real implementation must override most methods of this class.</p> <dl class="attribute"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.ANALYZER_DEFAULT"> <tt class="descname">ANALYZER_DEFAULT</tt><em class="property"> = 6</em><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.ANALYZER_DEFAULT" title="Permalink to this definition">¶</a></dt> <dd><p>the default analyzer to be used if nothing is configured</p> </dd></dl> <dl class="attribute"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.ANALYZER_EXACT"> <tt class="descname">ANALYZER_EXACT</tt><em class="property"> = 0</em><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.ANALYZER_EXACT" title="Permalink to this definition">¶</a></dt> <dd><p>exact matching: the query string must equal the whole term string</p> </dd></dl> <dl class="attribute"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.ANALYZER_PARTIAL"> <tt class="descname">ANALYZER_PARTIAL</tt><em class="property"> = 2</em><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.ANALYZER_PARTIAL" title="Permalink to this definition">¶</a></dt> <dd><p>partial matching: a document matches, even if the query string only matches the beginning of the term value.</p> </dd></dl> <dl class="attribute"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.ANALYZER_TOKENIZE"> <tt class="descname">ANALYZER_TOKENIZE</tt><em class="property"> = 4</em><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.ANALYZER_TOKENIZE" title="Permalink to this definition">¶</a></dt> <dd><p>tokenize terms and queries automatically</p> </dd></dl> <dl class="attribute"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.INDEX_DIRECTORY_NAME"> <tt class="descname">INDEX_DIRECTORY_NAME</tt><em class="property"> = None</em><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.INDEX_DIRECTORY_NAME" title="Permalink to this definition">¶</a></dt> <dd><p>override this with a string to be used as the name of the indexing directory/file in the filesystem</p> </dd></dl> <dl class="attribute"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.QUERY_TYPE"> <tt class="descname">QUERY_TYPE</tt><em class="property"> = None</em><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.QUERY_TYPE" title="Permalink to this definition">¶</a></dt> <dd><p>override this with the query class of the implementation</p> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.begin_transaction"> <tt class="descname">begin_transaction</tt><big>(</big><big>)</big><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.begin_transaction" title="Permalink to this definition">¶</a></dt> <dd><p>begin a transaction</p> <p>You can group multiple modifications of a database as a transaction. This prevents time-consuming database flushing and helps, if you want that a changeset is committed either completely or not at all. No changes will be written to disk until ‘commit_transaction’. ‘cancel_transaction’ can be used to revert an ongoing transaction.</p> <p>Database types that do not support transactions may silently ignore it.</p> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.cancel_transaction"> <tt class="descname">cancel_transaction</tt><big>(</big><big>)</big><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.cancel_transaction" title="Permalink to this definition">¶</a></dt> <dd><p>cancel an ongoing transaction</p> <p>See ‘start_transaction’ for details.</p> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.commit_transaction"> <tt class="descname">commit_transaction</tt><big>(</big><big>)</big><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.commit_transaction" title="Permalink to this definition">¶</a></dt> <dd><p>Submit the currently ongoing transaction and write changes to disk.</p> <p>See ‘start_transaction’ for details.</p> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.delete_doc"> <tt class="descname">delete_doc</tt><big>(</big><em>ident</em><big>)</big><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.delete_doc" title="Permalink to this definition">¶</a></dt> <dd><p>Delete the documents returned by a query.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>ident</strong> (<em>int | list of tuples | dict | list of dicts | query (e.g. xapian.Query) | list of queries</em>) – [list of] document IDs | dict describing a query | query</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.delete_document_by_id"> <tt class="descname">delete_document_by_id</tt><big>(</big><em>docid</em><big>)</big><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.delete_document_by_id" title="Permalink to this definition">¶</a></dt> <dd><p>Delete a specified document.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>docid</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#int" title="(in Python v2.7)"><em>int</em></a>) – the document ID to be deleted</td> </tr> </tbody> </table> </dd></dl> <dl class="attribute"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.field_analyzers"> <tt class="descname">field_analyzers</tt><em class="property"> = {}</em><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.field_analyzers" title="Permalink to this definition">¶</a></dt> <dd><p>mapping of field names and analyzers - see <a class="reference internal" href="#translate.search.indexing.CommonIndexer.CommonDatabase.set_field_analyzers" title="translate.search.indexing.CommonIndexer.CommonDatabase.set_field_analyzers"><tt class="xref py py-meth docutils literal"><span class="pre">set_field_analyzers()</span></tt></a></p> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.flush"> <tt class="descname">flush</tt><big>(</big><em>optimize=False</em><big>)</big><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.flush" title="Permalink to this definition">¶</a></dt> <dd><p>Flush the content of the database - to force changes to be written to disk.</p> <p>Some databases also support index optimization.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>optimize</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#bool" title="(in Python v2.7)"><em>bool</em></a>) – should the index be optimized if possible?</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.get_field_analyzers"> <tt class="descname">get_field_analyzers</tt><big>(</big><em>fieldnames=None</em><big>)</big><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.get_field_analyzers" title="Permalink to this definition">¶</a></dt> <dd><p>Return the analyzer that was mapped to a specific field.</p> <p>See <a class="reference internal" href="#translate.search.indexing.CommonIndexer.CommonDatabase.set_field_analyzers" title="translate.search.indexing.CommonIndexer.CommonDatabase.set_field_analyzers"><tt class="xref py py-meth docutils literal"><span class="pre">set_field_analyzers()</span></tt></a> for details.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>fieldnames</strong> (<em>str | list of str | None</em>) – the analyzer of this field (or all/multiple fields) is requested; leave empty (or <em>None</em>) to request all fields.</td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The analyzer setting of the field - see <em>CommonDatabase.ANALYZER_???</em> or a dict of field names and analyzers</td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">int | dict</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.get_query_result"> <tt class="descname">get_query_result</tt><big>(</big><em>query</em><big>)</big><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.get_query_result" title="Permalink to this definition">¶</a></dt> <dd><p>return an object containing the results of a query</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>query</strong> (<em>a query object of the real implementation</em>) – a pre-compiled query</td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">an object that allows access to the results</td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">subclass of CommonEnquire</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.index_document"> <tt class="descname">index_document</tt><big>(</big><em>data</em><big>)</big><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.index_document" title="Permalink to this definition">¶</a></dt> <dd><p>Add the given data to the database.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>data</strong> (<em>dict | list of str</em>) – the data to be indexed. A dictionary will be treated as <tt class="docutils literal"><span class="pre">fieldname:value</span></tt> combinations. If the fieldname is None then the value will be interpreted as a plain term or as a list of plain terms. Lists of terms are indexed separately. Lists of strings are treated as plain terms.</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.make_query"> <tt class="descname">make_query</tt><big>(</big><em>args</em>, <em>require_all=True</em>, <em>analyzer=None</em><big>)</big><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.make_query" title="Permalink to this definition">¶</a></dt> <dd><p>Create simple queries (strings or field searches) or combine multiple queries (AND/OR).</p> <p>To specifiy rules for field searches, you may want to take a look at <a class="reference internal" href="#translate.search.indexing.CommonIndexer.CommonDatabase.set_field_analyzers" title="translate.search.indexing.CommonIndexer.CommonDatabase.set_field_analyzers"><tt class="xref py py-meth docutils literal"><span class="pre">set_field_analyzers()</span></tt></a>. The parameter ‘match_text_partial’ can override the previously defined default setting.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>args</strong> (<em>list of queries | single query | str | dict</em>) – <p>queries or search string or description of field query examples:</p> <div class="highlight-python"><div class="highlight"><pre><span class="p">[</span><span class="n">xapian</span><span class="o">.</span><span class="n">Query</span><span class="p">(</span><span class="s">"foo"</span><span class="p">),</span> <span class="n">xapian</span><span class="o">.</span><span class="n">Query</span><span class="p">(</span><span class="s">"bar"</span><span class="p">)]</span> <span class="n">xapian</span><span class="o">.</span><span class="n">Query</span><span class="p">(</span><span class="s">"foo"</span><span class="p">)</span> <span class="s">"bar"</span> <span class="p">{</span><span class="s">"foo"</span><span class="p">:</span> <span class="s">"bar"</span><span class="p">,</span> <span class="s">"foobar"</span><span class="p">:</span> <span class="s">"foo"</span><span class="p">}</span> </pre></div> </div> </li> <li><strong>require_all</strong> (<em>boolean</em>) – boolean operator (True -> AND (default) / False -> OR)</li> <li><strong>analyzer</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#int" title="(in Python v2.7)"><em>int</em></a>) – <p>(only applicable for ‘dict’ or ‘str’) Define query options (partial matching, exact matching, tokenizing, ...) as bitwise combinations of <em>CommonIndexer.ANALYZER_???</em>.</p> <p>This can override previously defined field analyzer settings.</p> <p>If analyzer is <tt class="docutils literal"><span class="pre">None</span></tt> (default), then the configured analyzer for the field is used.</p> </li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">the combined query</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">query type of the specific implementation</p> </td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.search"> <tt class="descname">search</tt><big>(</big><em>query</em>, <em>fieldnames</em><big>)</big><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.search" title="Permalink to this definition">¶</a></dt> <dd><p>Return a list of the contents of specified fields for all matches of a query.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>query</strong> (<em>a query object of the real implementation</em>) – the query to be issued</li> <li><strong>fieldnames</strong> (<em>string | list of strings</em>) – the name(s) of a field of the document content</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">a list of dicts containing the specified field(s)</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">list of dicts</p> </td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.CommonIndexer.CommonDatabase.set_field_analyzers"> <tt class="descname">set_field_analyzers</tt><big>(</big><em>field_analyzers</em><big>)</big><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonDatabase.set_field_analyzers" title="Permalink to this definition">¶</a></dt> <dd><p>Set the analyzers for different fields of the database documents.</p> <p>All bitwise combinations of <em>CommonIndexer.ANALYZER_???</em> are possible.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>field_analyzers</strong> (<em>dict containing field names and analyzers</em>) – mapping of field names and analyzers</td> </tr> <tr class="field-even field"><th class="field-name" colspan="2">Raises TypeError:</th></tr> <tr class="field-even field"><td> </td><td class="field-body">invalid values in <em>field_analyzers</em></td> </tr> </tbody> </table> </dd></dl> </dd></dl> <dl class="class"> <dt id="translate.search.indexing.CommonIndexer.CommonEnquire"> <em class="property">class </em><tt class="descclassname">translate.search.indexing.CommonIndexer.</tt><tt class="descname">CommonEnquire</tt><big>(</big><em>enquire</em><big>)</big><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonEnquire" title="Permalink to this definition">¶</a></dt> <dd><p>An enquire object contains the information about the result of a request.</p> <dl class="method"> <dt id="translate.search.indexing.CommonIndexer.CommonEnquire.get_matches"> <tt class="descname">get_matches</tt><big>(</big><em>start</em>, <em>number</em><big>)</big><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonEnquire.get_matches" title="Permalink to this definition">¶</a></dt> <dd><p>Return a specified number of qualified matches of a previous query.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>start</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#int" title="(in Python v2.7)"><em>int</em></a>) – index of the first match to return (starting from zero)</li> <li><strong>number</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#int" title="(in Python v2.7)"><em>int</em></a>) – the number of matching entries to return</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">a set of matching entries and some statistics</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last"><p>tuple of (returned number, available number, matches) “matches” is a dictionary of:</p> <div class="highlight-python"><div class="highlight"><pre><span class="p">[</span><span class="s">"rank"</span><span class="p">,</span> <span class="s">"percent"</span><span class="p">,</span> <span class="s">"document"</span><span class="p">,</span> <span class="s">"docid"</span><span class="p">]</span> </pre></div> </div> </p> </td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.CommonIndexer.CommonEnquire.get_matches_count"> <tt class="descname">get_matches_count</tt><big>(</big><big>)</big><a class="headerlink" href="#translate.search.indexing.CommonIndexer.CommonEnquire.get_matches_count" title="Permalink to this definition">¶</a></dt> <dd><p>Return the estimated number of matches.</p> <p>Use <tt class="xref py py-meth docutils literal"><span class="pre">translate.search.indexing.CommonIndexer.search()</span></tt> to retrieve the exact number of matches</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The estimated number of matches</td> </tr> <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">int</td> </tr> </tbody> </table> </dd></dl> </dd></dl> <dl class="function"> <dt id="translate.search.indexing.CommonIndexer.is_available"> <tt class="descclassname">translate.search.indexing.CommonIndexer.</tt><tt class="descname">is_available</tt><big>(</big><big>)</big><a class="headerlink" href="#translate.search.indexing.CommonIndexer.is_available" title="Permalink to this definition">¶</a></dt> <dd><p>Check if this indexing engine interface is usable.</p> <p>This function must exist in every module that contains indexing engine interfaces.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">is this interface usable?</td> </tr> <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">bool</td> </tr> </tbody> </table> </dd></dl> </div> <div class="section" id="pyluceneindexer1"> <h3>PyLuceneIndexer1<a class="headerlink" href="#pyluceneindexer1" title="Permalink to this headline">¶</a></h3> </div> <div class="section" id="module-translate.search.indexing.PyLuceneIndexer"> <span id="pyluceneindexer"></span><h3>PyLuceneIndexer<a class="headerlink" href="#module-translate.search.indexing.PyLuceneIndexer" title="Permalink to this headline">¶</a></h3> <p>interface for the PyLucene (v2.x) indexing engine</p> <p>take a look at PyLuceneIndexer1.py for the PyLucene v1.x interface</p> <dl class="class"> <dt id="translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase"> <em class="property">class </em><tt class="descclassname">translate.search.indexing.PyLuceneIndexer.</tt><tt class="descname">PyLuceneDatabase</tt><big>(</big><em>basedir</em>, <em>analyzer=None</em>, <em>create_allowed=True</em><big>)</big><a class="headerlink" href="#translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase" title="Permalink to this definition">¶</a></dt> <dd><p>Manage and use a pylucene indexing database.</p> <dl class="method"> <dt id="translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.begin_transaction"> <tt class="descname">begin_transaction</tt><big>(</big><big>)</big><a class="headerlink" href="#translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.begin_transaction" title="Permalink to this definition">¶</a></dt> <dd><p>PyLucene does not support transactions</p> <p>Thus this function just opens the database for write access. Call “cancel_transaction” or “commit_transaction” to close write access in order to remove the exclusive lock from the database directory.</p> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.cancel_transaction"> <tt class="descname">cancel_transaction</tt><big>(</big><big>)</big><a class="headerlink" href="#translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.cancel_transaction" title="Permalink to this definition">¶</a></dt> <dd><p>PyLucene does not support transactions</p> <p>Thus this function just closes the database write access and removes the exclusive lock.</p> <p>See ‘start_transaction’ for details.</p> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.commit_transaction"> <tt class="descname">commit_transaction</tt><big>(</big><big>)</big><a class="headerlink" href="#translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.commit_transaction" title="Permalink to this definition">¶</a></dt> <dd><p>PyLucene does not support transactions</p> <p>Thus this function just closes the database write access and removes the exclusive lock.</p> <p>See ‘start_transaction’ for details.</p> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.delete_document_by_id"> <tt class="descname">delete_document_by_id</tt><big>(</big><em>docid</em><big>)</big><a class="headerlink" href="#translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.delete_document_by_id" title="Permalink to this definition">¶</a></dt> <dd><p>delete a specified document</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>docid</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#int" title="(in Python v2.7)"><em>int</em></a>) – the document ID to be deleted</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.flush"> <tt class="descname">flush</tt><big>(</big><em>optimize=False</em><big>)</big><a class="headerlink" href="#translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.flush" title="Permalink to this definition">¶</a></dt> <dd><p>flush the content of the database - to force changes to be written to disk</p> <p>some databases also support index optimization</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>optimize</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#bool" title="(in Python v2.7)"><em>bool</em></a>) – should the index be optimized if possible?</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.get_field_analyzers"> <tt class="descname">get_field_analyzers</tt><big>(</big><em>fieldnames=None</em><big>)</big><a class="headerlink" href="#translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.get_field_analyzers" title="Permalink to this definition">¶</a></dt> <dd><p>Return the analyzer that was mapped to a specific field.</p> <p>See <a class="reference internal" href="#translate.search.indexing.CommonIndexer.CommonDatabase.set_field_analyzers" title="translate.search.indexing.CommonIndexer.CommonDatabase.set_field_analyzers"><tt class="xref py py-meth docutils literal"><span class="pre">set_field_analyzers()</span></tt></a> for details.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>fieldnames</strong> (<em>str | list of str | None</em>) – the analyzer of this field (or all/multiple fields) is requested; leave empty (or <em>None</em>) to request all fields.</td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The analyzer setting of the field - see <em>CommonDatabase.ANALYZER_???</em> or a dict of field names and analyzers</td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">int | dict</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.get_query_result"> <tt class="descname">get_query_result</tt><big>(</big><em>query</em><big>)</big><a class="headerlink" href="#translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.get_query_result" title="Permalink to this definition">¶</a></dt> <dd><p>return an object containing the results of a query</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>query</strong> (<em>a query object of the real implementation</em>) – a pre-compiled query</td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">an object that allows access to the results</td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">subclass of CommonEnquire</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.index_document"> <tt class="descname">index_document</tt><big>(</big><em>data</em><big>)</big><a class="headerlink" href="#translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.index_document" title="Permalink to this definition">¶</a></dt> <dd><p>Add the given data to the database.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>data</strong> (<em>dict | list of str</em>) – the data to be indexed. A dictionary will be treated as <tt class="docutils literal"><span class="pre">fieldname:value</span></tt> combinations. If the fieldname is None then the value will be interpreted as a plain term or as a list of plain terms. Lists of terms are indexed separately. Lists of strings are treated as plain terms.</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.search"> <tt class="descname">search</tt><big>(</big><em>query</em>, <em>fieldnames</em><big>)</big><a class="headerlink" href="#translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.search" title="Permalink to this definition">¶</a></dt> <dd><p>Return a list of the contents of specified fields for all matches of a query.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>query</strong> (<em>a query object of the real implementation</em>) – the query to be issued</li> <li><strong>fieldnames</strong> (<em>string | list of strings</em>) – the name(s) of a field of the document content</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">a list of dicts containing the specified field(s)</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">list of dicts</p> </td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.set_field_analyzers"> <tt class="descname">set_field_analyzers</tt><big>(</big><em>field_analyzers</em><big>)</big><a class="headerlink" href="#translate.search.indexing.PyLuceneIndexer.PyLuceneDatabase.set_field_analyzers" title="Permalink to this definition">¶</a></dt> <dd><p>Set the analyzers for different fields of the database documents.</p> <p>All bitwise combinations of <em>CommonIndexer.ANALYZER_???</em> are possible.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>field_analyzers</strong> (<em>dict containing field names and analyzers</em>) – mapping of field names and analyzers</td> </tr> <tr class="field-even field"><th class="field-name" colspan="2">Raises TypeError:</th></tr> <tr class="field-even field"><td> </td><td class="field-body">invalid values in <em>field_analyzers</em></td> </tr> </tbody> </table> </dd></dl> </dd></dl> <dl class="class"> <dt id="translate.search.indexing.PyLuceneIndexer.PyLuceneHits"> <em class="property">class </em><tt class="descclassname">translate.search.indexing.PyLuceneIndexer.</tt><tt class="descname">PyLuceneHits</tt><big>(</big><em>enquire</em><big>)</big><a class="headerlink" href="#translate.search.indexing.PyLuceneIndexer.PyLuceneHits" title="Permalink to this definition">¶</a></dt> <dd><p>an enquire object contains the information about the result of a request</p> <dl class="method"> <dt id="translate.search.indexing.PyLuceneIndexer.PyLuceneHits.get_matches"> <tt class="descname">get_matches</tt><big>(</big><em>start</em>, <em>number</em><big>)</big><a class="headerlink" href="#translate.search.indexing.PyLuceneIndexer.PyLuceneHits.get_matches" title="Permalink to this definition">¶</a></dt> <dd><p>return a specified number of qualified matches of a previous query</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>start</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#int" title="(in Python v2.7)"><em>int</em></a>) – index of the first match to return (starting from zero)</li> <li><strong>number</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#int" title="(in Python v2.7)"><em>int</em></a>) – the number of matching entries to return</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">a set of matching entries and some statistics</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last"><p>tuple of (returned number, available number, matches) “matches” is a dictionary of:</p> <div class="highlight-python"><div class="highlight"><pre><span class="p">[</span><span class="s">"rank"</span><span class="p">,</span> <span class="s">"percent"</span><span class="p">,</span> <span class="s">"document"</span><span class="p">,</span> <span class="s">"docid"</span><span class="p">]</span> </pre></div> </div> </p> </td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.PyLuceneIndexer.PyLuceneHits.get_matches_count"> <tt class="descname">get_matches_count</tt><big>(</big><big>)</big><a class="headerlink" href="#translate.search.indexing.PyLuceneIndexer.PyLuceneHits.get_matches_count" title="Permalink to this definition">¶</a></dt> <dd><p>Return the estimated number of matches.</p> <p>Use <tt class="xref py py-meth docutils literal"><span class="pre">translate.search.indexing.CommonIndexer.search()</span></tt> to retrieve the exact number of matches</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The estimated number of matches</td> </tr> <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">int</td> </tr> </tbody> </table> </dd></dl> </dd></dl> </div> <div class="section" id="module-translate.search.indexing.XapianIndexer"> <span id="xapianindexer"></span><h3>XapianIndexer<a class="headerlink" href="#module-translate.search.indexing.XapianIndexer" title="Permalink to this headline">¶</a></h3> <p>Interface to the Xapian indexing engine for the Translate Toolkit</p> <p>Xapian v1.0 or higher is supported.</p> <p>If you are interested in writing an interface for Xapian 0.x, then you should checkout the following:</p> <div class="highlight-python"><pre>svn export -r 7235 https://translate.svn.sourceforge.net/svnroot/translate/src/branches/translate-search-indexer-generic-merging/translate/search/indexer/</pre> </div> <p>It is not completely working, but it should give you a good start.</p> <dl class="class"> <dt id="translate.search.indexing.XapianIndexer.XapianDatabase"> <em class="property">class </em><tt class="descclassname">translate.search.indexing.XapianIndexer.</tt><tt class="descname">XapianDatabase</tt><big>(</big><em>basedir</em>, <em>analyzer=None</em>, <em>create_allowed=True</em><big>)</big><a class="headerlink" href="#translate.search.indexing.XapianIndexer.XapianDatabase" title="Permalink to this definition">¶</a></dt> <dd><p>Interface to the <a class="reference external" href="http://xapian.org">Xapian indexer</a>.</p> <dl class="method"> <dt id="translate.search.indexing.XapianIndexer.XapianDatabase.begin_transaction"> <tt class="descname">begin_transaction</tt><big>(</big><big>)</big><a class="headerlink" href="#translate.search.indexing.XapianIndexer.XapianDatabase.begin_transaction" title="Permalink to this definition">¶</a></dt> <dd><p>Begin a transaction.</p> <p>Xapian supports transactions to group multiple database modifications. This avoids intermediate flushing and therefore increases performance.</p> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.XapianIndexer.XapianDatabase.cancel_transaction"> <tt class="descname">cancel_transaction</tt><big>(</big><big>)</big><a class="headerlink" href="#translate.search.indexing.XapianIndexer.XapianDatabase.cancel_transaction" title="Permalink to this definition">¶</a></dt> <dd><p>cancel an ongoing transaction</p> <p>no changes since the last execution of ‘begin_transcation’ are written</p> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.XapianIndexer.XapianDatabase.commit_transaction"> <tt class="descname">commit_transaction</tt><big>(</big><big>)</big><a class="headerlink" href="#translate.search.indexing.XapianIndexer.XapianDatabase.commit_transaction" title="Permalink to this definition">¶</a></dt> <dd><p>Submit the changes of an ongoing transaction.</p> <p>All changes since the last execution of ‘begin_transaction’ are written.</p> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.XapianIndexer.XapianDatabase.delete_doc"> <tt class="descname">delete_doc</tt><big>(</big><em>ident</em><big>)</big><a class="headerlink" href="#translate.search.indexing.XapianIndexer.XapianDatabase.delete_doc" title="Permalink to this definition">¶</a></dt> <dd><p>Delete the documents returned by a query.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>ident</strong> (<em>int | list of tuples | dict | list of dicts | query (e.g. xapian.Query) | list of queries</em>) – [list of] document IDs | dict describing a query | query</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.XapianIndexer.XapianDatabase.delete_document_by_id"> <tt class="descname">delete_document_by_id</tt><big>(</big><em>docid</em><big>)</big><a class="headerlink" href="#translate.search.indexing.XapianIndexer.XapianDatabase.delete_document_by_id" title="Permalink to this definition">¶</a></dt> <dd><p>Delete a specified document.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>docid</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#int" title="(in Python v2.7)"><em>int</em></a>) – the document ID to be deleted</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.XapianIndexer.XapianDatabase.flush"> <tt class="descname">flush</tt><big>(</big><em>optimize=False</em><big>)</big><a class="headerlink" href="#translate.search.indexing.XapianIndexer.XapianDatabase.flush" title="Permalink to this definition">¶</a></dt> <dd><p>force to write the current changes to disk immediately</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>optimize</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#bool" title="(in Python v2.7)"><em>bool</em></a>) – ignored for xapian</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.XapianIndexer.XapianDatabase.get_field_analyzers"> <tt class="descname">get_field_analyzers</tt><big>(</big><em>fieldnames=None</em><big>)</big><a class="headerlink" href="#translate.search.indexing.XapianIndexer.XapianDatabase.get_field_analyzers" title="Permalink to this definition">¶</a></dt> <dd><p>Return the analyzer that was mapped to a specific field.</p> <p>See <a class="reference internal" href="#translate.search.indexing.CommonIndexer.CommonDatabase.set_field_analyzers" title="translate.search.indexing.CommonIndexer.CommonDatabase.set_field_analyzers"><tt class="xref py py-meth docutils literal"><span class="pre">set_field_analyzers()</span></tt></a> for details.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>fieldnames</strong> (<em>str | list of str | None</em>) – the analyzer of this field (or all/multiple fields) is requested; leave empty (or <em>None</em>) to request all fields.</td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The analyzer setting of the field - see <em>CommonDatabase.ANALYZER_???</em> or a dict of field names and analyzers</td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">int | dict</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.XapianIndexer.XapianDatabase.get_query_result"> <tt class="descname">get_query_result</tt><big>(</big><em>query</em><big>)</big><a class="headerlink" href="#translate.search.indexing.XapianIndexer.XapianDatabase.get_query_result" title="Permalink to this definition">¶</a></dt> <dd><p>Return an object containing the results of a query.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>query</strong> (<em>xapian.Query</em>) – a pre-compiled xapian query</td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">an object that allows access to the results</td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">XapianIndexer.CommonEnquire</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.XapianIndexer.XapianDatabase.index_document"> <tt class="descname">index_document</tt><big>(</big><em>data</em><big>)</big><a class="headerlink" href="#translate.search.indexing.XapianIndexer.XapianDatabase.index_document" title="Permalink to this definition">¶</a></dt> <dd><p>Add the given data to the database.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>data</strong> (<em>dict | list of str</em>) – the data to be indexed. A dictionary will be treated as <tt class="docutils literal"><span class="pre">fieldname:value</span></tt> combinations. If the fieldname is None then the value will be interpreted as a plain term or as a list of plain terms. Lists of terms are indexed separately. Lists of strings are treated as plain terms.</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.XapianIndexer.XapianDatabase.search"> <tt class="descname">search</tt><big>(</big><em>query</em>, <em>fieldnames</em><big>)</big><a class="headerlink" href="#translate.search.indexing.XapianIndexer.XapianDatabase.search" title="Permalink to this definition">¶</a></dt> <dd><p>Return a list of the contents of specified fields for all matches of a query.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>query</strong> (<em>xapian.Query</em>) – the query to be issued</li> <li><strong>fieldnames</strong> (<em>string | list of strings</em>) – the name(s) of a field of the document content</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">a list of dicts containing the specified field(s)</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">list of dicts</p> </td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.XapianIndexer.XapianDatabase.set_field_analyzers"> <tt class="descname">set_field_analyzers</tt><big>(</big><em>field_analyzers</em><big>)</big><a class="headerlink" href="#translate.search.indexing.XapianIndexer.XapianDatabase.set_field_analyzers" title="Permalink to this definition">¶</a></dt> <dd><p>Set the analyzers for different fields of the database documents.</p> <p>All bitwise combinations of <em>CommonIndexer.ANALYZER_???</em> are possible.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>field_analyzers</strong> (<em>dict containing field names and analyzers</em>) – mapping of field names and analyzers</td> </tr> <tr class="field-even field"><th class="field-name" colspan="2">Raises TypeError:</th></tr> <tr class="field-even field"><td> </td><td class="field-body">invalid values in <em>field_analyzers</em></td> </tr> </tbody> </table> </dd></dl> </dd></dl> <dl class="class"> <dt id="translate.search.indexing.XapianIndexer.XapianEnquire"> <em class="property">class </em><tt class="descclassname">translate.search.indexing.XapianIndexer.</tt><tt class="descname">XapianEnquire</tt><big>(</big><em>enquire</em><big>)</big><a class="headerlink" href="#translate.search.indexing.XapianIndexer.XapianEnquire" title="Permalink to this definition">¶</a></dt> <dd><p>interface to the xapian object for storing sets of matches</p> <dl class="method"> <dt id="translate.search.indexing.XapianIndexer.XapianEnquire.get_matches"> <tt class="descname">get_matches</tt><big>(</big><em>start</em>, <em>number</em><big>)</big><a class="headerlink" href="#translate.search.indexing.XapianIndexer.XapianEnquire.get_matches" title="Permalink to this definition">¶</a></dt> <dd><p>Return a specified number of qualified matches of a previous query.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple"> <li><strong>start</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#int" title="(in Python v2.7)"><em>int</em></a>) – index of the first match to return (starting from zero)</li> <li><strong>number</strong> (<a class="reference external" href="http://docs.python.org/2.7/library/functions.html#int" title="(in Python v2.7)"><em>int</em></a>) – the number of matching entries to return</li> </ul> </td> </tr> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">a set of matching entries and some statistics</p> </td> </tr> <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last"><p>tuple of (returned number, available number, matches) “matches” is a dictionary of:</p> <div class="highlight-python"><div class="highlight"><pre><span class="p">[</span><span class="s">"rank"</span><span class="p">,</span> <span class="s">"percent"</span><span class="p">,</span> <span class="s">"document"</span><span class="p">,</span> <span class="s">"docid"</span><span class="p">]</span> </pre></div> </div> </p> </td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.indexing.XapianIndexer.XapianEnquire.get_matches_count"> <tt class="descname">get_matches_count</tt><big>(</big><big>)</big><a class="headerlink" href="#translate.search.indexing.XapianIndexer.XapianEnquire.get_matches_count" title="Permalink to this definition">¶</a></dt> <dd><p>Return the estimated number of matches.</p> <p>Use <tt class="xref py py-meth docutils literal"><span class="pre">translate.search.indexing.CommonIndexer.search()</span></tt> to retrieve the exact number of matches</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The estimated number of matches</td> </tr> <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">int</td> </tr> </tbody> </table> </dd></dl> </dd></dl> </div> </div> <div class="section" id="module-translate.search.lshtein"> <span id="lshtein"></span><h2>lshtein<a class="headerlink" href="#module-translate.search.lshtein" title="Permalink to this headline">¶</a></h2> <p>A class to calculate a similarity based on the Levenshtein distance. See <a class="reference external" href="http://en.wikipedia.org/wiki/Levenshtein_distance">http://en.wikipedia.org/wiki/Levenshtein_distance</a>.</p> <p>If available, the python-Levenshtein package will be used which will provide better performance as it is implemented natively. See <a class="reference external" href="http://trific.ath.cx/python/levenshtein/">http://trific.ath.cx/python/levenshtein/</a></p> <dl class="function"> <dt id="translate.search.lshtein.distance"> <tt class="descclassname">translate.search.lshtein.</tt><tt class="descname">distance</tt><big>(</big><em>a</em>, <em>b</em>, <em>stopvalue=0</em><big>)</big><a class="headerlink" href="#translate.search.lshtein.distance" title="Permalink to this definition">¶</a></dt> <dd><p>Same as python_distance in functionality. This uses the fast C version if we detected it earlier.</p> <p>Note that this does not support arbitrary sequence types, but only string types.</p> </dd></dl> <dl class="function"> <dt id="translate.search.lshtein.native_distance"> <tt class="descclassname">translate.search.lshtein.</tt><tt class="descname">native_distance</tt><big>(</big><em>a</em>, <em>b</em>, <em>stopvalue=0</em><big>)</big><a class="headerlink" href="#translate.search.lshtein.native_distance" title="Permalink to this definition">¶</a></dt> <dd><p>Same as python_distance in functionality. This uses the fast C version if we detected it earlier.</p> <p>Note that this does not support arbitrary sequence types, but only string types.</p> </dd></dl> <dl class="function"> <dt id="translate.search.lshtein.python_distance"> <tt class="descclassname">translate.search.lshtein.</tt><tt class="descname">python_distance</tt><big>(</big><em>a</em>, <em>b</em>, <em>stopvalue=-1</em><big>)</big><a class="headerlink" href="#translate.search.lshtein.python_distance" title="Permalink to this definition">¶</a></dt> <dd><p>Calculates the distance for use in similarity calculation. Python version.</p> </dd></dl> </div> <div class="section" id="module-translate.search.match"> <span id="match"></span><h2>match<a class="headerlink" href="#module-translate.search.match" title="Permalink to this headline">¶</a></h2> <p>Class to perform translation memory matching from a store of translation units.</p> <dl class="class"> <dt id="translate.search.match.matcher"> <em class="property">class </em><tt class="descclassname">translate.search.match.</tt><tt class="descname">matcher</tt><big>(</big><em>store</em>, <em>max_candidates=10</em>, <em>min_similarity=75</em>, <em>max_length=70</em>, <em>comparer=None</em>, <em>usefuzzy=False</em><big>)</big><a class="headerlink" href="#translate.search.match.matcher" title="Permalink to this definition">¶</a></dt> <dd><p>A class that will do matching and store configuration for the matching process.</p> <dl class="method"> <dt id="translate.search.match.matcher.buildunits"> <tt class="descname">buildunits</tt><big>(</big><em>candidates</em><big>)</big><a class="headerlink" href="#translate.search.match.matcher.buildunits" title="Permalink to this definition">¶</a></dt> <dd><p>Builds a list of units conforming to base API, with the score in the comment.</p> </dd></dl> <dl class="method"> <dt id="translate.search.match.matcher.extendtm"> <tt class="descname">extendtm</tt><big>(</big><em>units</em>, <em>store=None</em>, <em>sort=True</em><big>)</big><a class="headerlink" href="#translate.search.match.matcher.extendtm" title="Permalink to this definition">¶</a></dt> <dd><p>Extends the memory with extra unit(s).</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> <li><strong>units</strong> – The units to add to the TM.</li> <li><strong>store</strong> – Optional store from where some metadata can be retrieved and associated with each unit.</li> <li><strong>sort</strong> – Optional parameter that can be set to False to supress sorting of the candidates list. This should probably only be used in <a class="reference internal" href="#translate.search.match.matcher.inittm" title="translate.search.match.matcher.inittm"><tt class="xref py py-meth docutils literal"><span class="pre">matcher.inittm()</span></tt></a>.</li> </ul> </td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.match.matcher.getstartlength"> <tt class="descname">getstartlength</tt><big>(</big><em>min_similarity</em>, <em>text</em><big>)</big><a class="headerlink" href="#translate.search.match.matcher.getstartlength" title="Permalink to this definition">¶</a></dt> <dd><p>Calculates the minimum length we are interested in. The extra fat is because we don’t use plain character distance only.</p> </dd></dl> <dl class="method"> <dt id="translate.search.match.matcher.getstoplength"> <tt class="descname">getstoplength</tt><big>(</big><em>min_similarity</em>, <em>text</em><big>)</big><a class="headerlink" href="#translate.search.match.matcher.getstoplength" title="Permalink to this definition">¶</a></dt> <dd><p>Calculates a length beyond which we are not interested. The extra fat is because we don’t use plain character distance only.</p> </dd></dl> <dl class="method"> <dt id="translate.search.match.matcher.inittm"> <tt class="descname">inittm</tt><big>(</big><em>stores</em>, <em>reverse=False</em><big>)</big><a class="headerlink" href="#translate.search.match.matcher.inittm" title="Permalink to this definition">¶</a></dt> <dd><p>Initialises the memory for later use. We use simple base units for speedup.</p> </dd></dl> <dl class="method"> <dt id="translate.search.match.matcher.matches"> <tt class="descname">matches</tt><big>(</big><em>text</em><big>)</big><a class="headerlink" href="#translate.search.match.matcher.matches" title="Permalink to this definition">¶</a></dt> <dd><p>Returns a list of possible matches for given source text.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>text</strong> (<em>String</em>) – The text that will be search for in the translation memory</td> </tr> <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">list</td> </tr> <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">a list of units with the source and target strings from the translation memory. If <tt class="xref py py-attr docutils literal"><span class="pre">self.addpercentage</span></tt> is <em>True</em> (default) the match quality is given as a percentage in the notes.</td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.match.matcher.setparameters"> <tt class="descname">setparameters</tt><big>(</big><em>max_candidates=10</em>, <em>min_similarity=75</em>, <em>max_length=70</em><big>)</big><a class="headerlink" href="#translate.search.match.matcher.setparameters" title="Permalink to this definition">¶</a></dt> <dd><p>Sets the parameters without reinitialising the tm. If a parameter is not specified, it is set to the default, not ignored</p> </dd></dl> <dl class="method"> <dt id="translate.search.match.matcher.usable"> <tt class="descname">usable</tt><big>(</big><em>unit</em><big>)</big><a class="headerlink" href="#translate.search.match.matcher.usable" title="Permalink to this definition">¶</a></dt> <dd><p>Returns whether this translation unit is usable for TM</p> </dd></dl> </dd></dl> <dl class="function"> <dt id="translate.search.match.sourcelen"> <tt class="descclassname">translate.search.match.</tt><tt class="descname">sourcelen</tt><big>(</big><em>unit</em><big>)</big><a class="headerlink" href="#translate.search.match.sourcelen" title="Permalink to this definition">¶</a></dt> <dd><p>Returns the length of the source string.</p> </dd></dl> <dl class="class"> <dt id="translate.search.match.terminologymatcher"> <em class="property">class </em><tt class="descclassname">translate.search.match.</tt><tt class="descname">terminologymatcher</tt><big>(</big><em>store</em>, <em>max_candidates=10</em>, <em>min_similarity=75</em>, <em>max_length=500</em>, <em>comparer=None</em><big>)</big><a class="headerlink" href="#translate.search.match.terminologymatcher" title="Permalink to this definition">¶</a></dt> <dd><p>A matcher with settings specifically for terminology matching.</p> <dl class="method"> <dt id="translate.search.match.terminologymatcher.buildunits"> <tt class="descname">buildunits</tt><big>(</big><em>candidates</em><big>)</big><a class="headerlink" href="#translate.search.match.terminologymatcher.buildunits" title="Permalink to this definition">¶</a></dt> <dd><p>Builds a list of units conforming to base API, with the score in the comment.</p> </dd></dl> <dl class="method"> <dt id="translate.search.match.terminologymatcher.extendtm"> <tt class="descname">extendtm</tt><big>(</big><em>units</em>, <em>store=None</em>, <em>sort=True</em><big>)</big><a class="headerlink" href="#translate.search.match.terminologymatcher.extendtm" title="Permalink to this definition">¶</a></dt> <dd><p>Extends the memory with extra unit(s).</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple"> <li><strong>units</strong> – The units to add to the TM.</li> <li><strong>store</strong> – Optional store from where some metadata can be retrieved and associated with each unit.</li> <li><strong>sort</strong> – Optional parameter that can be set to False to supress sorting of the candidates list. This should probably only be used in <a class="reference internal" href="#translate.search.match.matcher.inittm" title="translate.search.match.matcher.inittm"><tt class="xref py py-meth docutils literal"><span class="pre">matcher.inittm()</span></tt></a>.</li> </ul> </td> </tr> </tbody> </table> </dd></dl> <dl class="method"> <dt id="translate.search.match.terminologymatcher.inittm"> <tt class="descname">inittm</tt><big>(</big><em>store</em><big>)</big><a class="headerlink" href="#translate.search.match.terminologymatcher.inittm" title="Permalink to this definition">¶</a></dt> <dd><p>Normal initialisation, but convert all source strings to lower case</p> </dd></dl> <dl class="method"> <dt id="translate.search.match.terminologymatcher.matches"> <tt class="descname">matches</tt><big>(</big><em>text</em><big>)</big><a class="headerlink" href="#translate.search.match.terminologymatcher.matches" title="Permalink to this definition">¶</a></dt> <dd><p>Normal matching after converting text to lower case. Then replace with the original unit to retain comments, etc.</p> </dd></dl> <dl class="method"> <dt id="translate.search.match.terminologymatcher.setparameters"> <tt class="descname">setparameters</tt><big>(</big><em>max_candidates=10</em>, <em>min_similarity=75</em>, <em>max_length=70</em><big>)</big><a class="headerlink" href="#translate.search.match.terminologymatcher.setparameters" title="Permalink to this definition">¶</a></dt> <dd><p>Sets the parameters without reinitialising the tm. If a parameter is not specified, it is set to the default, not ignored</p> </dd></dl> <dl class="method"> <dt id="translate.search.match.terminologymatcher.usable"> <tt class="descname">usable</tt><big>(</big><em>unit</em><big>)</big><a class="headerlink" href="#translate.search.match.terminologymatcher.usable" title="Permalink to this definition">¶</a></dt> <dd><p>Returns whether this translation unit is usable for terminology.</p> </dd></dl> </dd></dl> <dl class="function"> <dt id="translate.search.match.unit2dict"> <tt class="descclassname">translate.search.match.</tt><tt class="descname">unit2dict</tt><big>(</big><em>unit</em><big>)</big><a class="headerlink" href="#translate.search.match.unit2dict" title="Permalink to this definition">¶</a></dt> <dd><p>converts a pounit to a simple dict structure for use over the web</p> </dd></dl> </div> <div class="section" id="module-translate.search.segment"> <span id="segment"></span><h2>segment<a class="headerlink" href="#module-translate.search.segment" title="Permalink to this headline">¶</a></h2> <p>Module to deal with different types and uses of segmentation</p> <dl class="function"> <dt id="translate.search.segment.character_iter"> <tt class="descclassname">translate.search.segment.</tt><tt class="descname">character_iter</tt><big>(</big><em>text</em><big>)</big><a class="headerlink" href="#translate.search.segment.character_iter" title="Permalink to this definition">¶</a></dt> <dd><p>Returns an iterator over the characters in text.</p> </dd></dl> <dl class="function"> <dt id="translate.search.segment.characters"> <tt class="descclassname">translate.search.segment.</tt><tt class="descname">characters</tt><big>(</big><em>text</em><big>)</big><a class="headerlink" href="#translate.search.segment.characters" title="Permalink to this definition">¶</a></dt> <dd><p>Returns a list of characters in text.</p> </dd></dl> <dl class="function"> <dt id="translate.search.segment.sentence_iter"> <tt class="descclassname">translate.search.segment.</tt><tt class="descname">sentence_iter</tt><big>(</big><em>text</em><big>)</big><a class="headerlink" href="#translate.search.segment.sentence_iter" title="Permalink to this definition">¶</a></dt> <dd><p>Returns an iterator over the senteces in text.</p> </dd></dl> <dl class="function"> <dt id="translate.search.segment.sentences"> <tt class="descclassname">translate.search.segment.</tt><tt class="descname">sentences</tt><big>(</big><em>text</em><big>)</big><a class="headerlink" href="#translate.search.segment.sentences" title="Permalink to this definition">¶</a></dt> <dd><p>Returns a list of senteces in text.</p> </dd></dl> <dl class="function"> <dt id="translate.search.segment.word_iter"> <tt class="descclassname">translate.search.segment.</tt><tt class="descname">word_iter</tt><big>(</big><em>text</em><big>)</big><a class="headerlink" href="#translate.search.segment.word_iter" title="Permalink to this definition">¶</a></dt> <dd><p>Returns an iterator over the words in text.</p> </dd></dl> <dl class="function"> <dt id="translate.search.segment.words"> <tt class="descclassname">translate.search.segment.</tt><tt class="descname">words</tt><big>(</big><em>text</em><big>)</big><a class="headerlink" href="#translate.search.segment.words" title="Permalink to this definition">¶</a></dt> <dd><p>Returns a list of words in text.</p> </dd></dl> </div> <div class="section" id="module-translate.search.terminology"> <span id="terminology"></span><h2>terminology<a class="headerlink" href="#module-translate.search.terminology" title="Permalink to this headline">¶</a></h2> <p>A class that does terminology matching</p> </div> </div> </div> <hr> <footer class="footer"> <div class="container"> <p class="pull-right"><a href="#">Back to top ↑</a></p> <ul class="unstyled muted"> <li><small> © 2012, Translate.org.za.<br/> </small></li> <li><small> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3. </small></li> </ul> </div> </footer> </body> </html>