<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<section id="JCR.SynonimProvider">
  <title>Searching By Synonim</title>

  <para>Find all mix:title nodes where title contains synonims to 'fast'
  word.</para>

  <note>
    <para>See also about synonim propvider configuration - <link
    linkend="JCR.SearchingRepositoryContent">Searching Repository
    Content</link></para>
  </note>

  <para>Synonim provider must be configured in indexing-configuration.xml
  :</para>

  <programlisting language="xml">&lt;query-handler class="org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex"&gt;
   &lt;properties&gt;
      ...
      &lt;property name="synonymprovider-class" value="org.exoplatform.services.jcr.impl.core.query.lucene.PropertiesSynonymProvider" /&gt;
      &lt;property name="synonymprovider-config-path" value="../../synonyms.properties" /&gt;
      ...
   &lt;/properties&gt;
&lt;/query-handler&gt;</programlisting>

  <para>File synonim.properties contains next synonims list:</para>

  <programlisting>ASF=Apache Software Foundation
quick=fast
sluggish=lazy</programlisting>

  <section id="JCR.SynonimProvider.RepositoryStructure">
    <title>Repository structure:</title>

    <para>Repository contains mix:title nodes, where jcr:title has different
    values.</para>

    <itemizedlist>
      <listitem>
        <para>root</para>

        <itemizedlist>
          <listitem>
            <para>document1 (mix:title) jcr:title="The quick brown fox jumps
            over the lazy dog."</para>
          </listitem>
        </itemizedlist>
      </listitem>
    </itemizedlist>
  </section>

  <section id="JCR.SynonimProvider.QueryExecution">
    <title>Query execution</title>

    <para><emphasis role="bold">SQL</emphasis></para>

    <programlisting language="java">// make SQL query
QueryManager queryManager = workspace.getQueryManager();
// create query
String sqlStatement = "SELECT * FROM mix:title WHERE CONTAINS(jcr:title, '~fast')";
Query query = queryManager.createQuery(sqlStatement, Query.SQL);
// execute query and fetch result
QueryResult result = query.execute();</programlisting>

    <para><emphasis role="bold">XPath</emphasis></para>

    <programlisting language="java">// make XPath query
QueryManager queryManager = workspace.getQueryManager();
// create query
String xpathStatement = "//element(*,mix:title)[jcr:contains(@jcr:title, '~fast')]";
Query query = queryManager.createQuery(xpathStatement, Query.XPATH);
// execute query and fetch result
QueryResult result = query.execute();</programlisting>
  </section>

  <section id="JCR.SynonimProvider.FetchingResult">
    <title>Fetching result</title>

    <para>Let's get nodes:</para>

    <programlisting language="java">NodeIterator it = result.getNodes();

if(it.hasNext())
{
   Node findedNode = it.nextNode();
}</programlisting>

    <para>NodeIterator will return expected document1. This is a purpose of
    synonim providers. Find by specified word, but return by all synonims
    to.</para>
  </section>
</section>
