eZ Community » Learn » eZ Publish » eZ Find Demystified: Installing and...

eZ Find Demystified: Installing and configuring a multi-core Solr/eZ Find 2.6 instance with eZ Tika

Monday 14 May 2012 8:34:25 pm

  • Currently 5 out of 5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Step 10: Index your sites

Run the following commands as the web user, substituting your_admin_sitaccess as necessary.

su – www-data
cd /var/www/ezpublish/ezfindexample1/
php extension/ezfind/bin/php/updatesearchindexsolr.php -s your_admin_siteaccess
cd /var/www/ezpublish/ezfindexample2/
php extension/ezfind/bin/php/updatesearchindexsolr.php -s your_admin_siteaccess
exit

 

 

You should see some indexing feedback as Solr indexes your sites, such as threads started/stopped and total time to index. If you have Solr running in a separate terminal, you can examine its output in case of any errors.

By default, eZ Find indexes new content as it is added. You can also defer indexing to a cronjob – see the official eZ Find documentation. 

 

Step 11: Edit your search template and start searching

Create or edit the search template for each of your sites, substituting path and design directory as necessary:

/var/www/ezpublish/ezfindexample1/design/plain_site/templates/content/search.tpl
/var/www/ezpublish/ezfindexample2/design/plain_site/templates/content/search.tpl

To just get started, the files should contain the code below. You can of course do lots of further customisation, but this is enough to test that Solr search is working and show off Solr’s relevancy sorting and keyword highlighting.

{let search=false()}
{section show=$use_template_search}
{set page_limit=10}
{set search=fetch(ezfind,search,
                      hash(query,$search_text,
        section_id,$search_section_id,
        subtree_array,$search_subtree_array,
        offset,$view_parameters.offset,
        limit,$page_limit))}
{set search_result=$search['SearchResult']}
{set search_count=$search['SearchCount']}
{set stop_word_array=$search['StopWordArray']}
{set search_data=$search}
{/section}
<h1>{"Search"|i18n("design/standard/content/search")}</h1>
<form action={"/content/search/"|ezurl} method="get">
<p>
<input type="text" class="textshort" name="SearchText" value="{$search_text|wash}" />
<input name="SearchButton" type="submit" class="submit" value="{'Search'|i18n('global/labels')}" />
</p>
{switch name=Sw match=$search_count}
{case match=0}
<div class="warning">
<h2>{'No results were found when searching for "%1"'|i18n("design/standard/content/search",,array($search_text|wash))}</h2>
</div>
{/case}
{case}
<div class="feedback">
<h2>{'Search for "%1" returned %2 matches'|i18n("design/standard/content/search",,array($search_text|wash,$search_count))}</h2>
</div>
{/case}
{/switch}
{foreach $search_result as $snode}
<h2><a href="{$snode.url_alias|ezurl(no)}">{$snode.name}</a></h2>
<p>{$snode.highlight}</p>
{/foreach}
{include name=Navigator
uri='design:navigator/google.tpl'
page_uri='/content/search'
page_uri_suffix=concat('?SearchText=',$search_text|urlencode,$search_timestamp|gt(0)|choose('',concat('&SearchTimestamp=',$search_timestamp)))
item_count=$search_count
view_parameters=$view_parameters
item_limit=$page_limit}
</form>
{/let}
 

Clear caches in your site admin, then go to your site and do some searches. Try both regular and wildcard (*) searches, and searching on non-English characters if needed. Check that results are returned from both content objects and uploaded files with text content.

 

Step 12: Create a startup script

Below is a sample startup script for Debian 6, customised for this tutorial. The eZ Find installation also contains example startup scripts for Debian, Gentoo and Red Hat. Note that the PARAMETERS variable is customised for a 64-bit environment. If this doesn’t work for you, you can adapt one of the scripts in the bin/scripts directory in the eZ Find extension. Remember to set SOLR_HOME to the correct path for your installation.

#!/bin/sh -e
#
# eZ Find init script for debian.
#
# Usage:
#
# Set the correct SOLR_HOME value, and copy this file to /etc/init.d
# Symlink to /etc/init.d/solr to /etc/rc3.d/S70solr and /etc/rc5.d/S70solr
#
# Example:
# cp solr /etc/init.d/solr# cd /etc/init.d && chmod 755 solr
# cd /etc/rc2.d && ln -s ../init.d/solr S70solr
# cd /etc/rc5.d && ln -s ../init.d/solr S70solr
# cd /etc/rc2.d && ln -s ../init.d/solr K70solr
# cd /etc/rc5.d && ln -s ../init.d/solr K70solr
 
. /lib/lsb/init-functions
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="Solr indexing server"
NAME=solr
SOLR_HOME=/srv/solr/java
PARAMETERS="-Dezfind -Dsolr.solr.home=/srv/solr/cores -server -d64 -Xmx768m -Xms768m -XX:+UseParallelGC -XX:+AggressiveOpts -XX:NewRatio=5 -jar start.jar"
DAEMON=/usr/bin/java
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
 
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
 
#
#    Function that starts the daemon/service.
#
d_start() {
    start-stop-daemon --start --pidfile $PIDFILE --chdir $SOLR_HOME --background --make-pidfile --exec $DAEMON -- $PARAMETERS
}
#
#    Function that stops the daemon/service.
#
d_stop() {
    start-stop-daemon --stop --quiet --pidfile $PIDFILE --name java
        rm -f $PIDFILE
}
 
#
#    Function that checks if solr is running
#    Returns success (0) if solr is running, failure (1) if not running
#
d_status() {
    if [ -f "$PIDFILE" ] && ps `cat $PIDFILE` >/dev/null 2>&1; then
        return 0 # EXIT_SUCCESS
    else
          return 1 # EXIT_FAILURE
    fi
}
 
case "$1" in
  start)
    echo " * Starting $DESC: $NAME"
    if d_status; then
        echo "   ...$NAME is already running."
        return 1
    fi
    d_start
    if d_status; then
        echo "   ...done."
    else
        echo "   ...failed to start solr"
        exit 1
    fi
    ;;
  stop)
    echo " * Stopping $DESC: $NAME"
    if d_status; then
        d_stop
        if d_status; then
            echo "   ...$NAME is still running."
            exit 1
        else
            echo "   ...done."
        fi
    else
        echo "   ...$NAME is not running."
    fi
    ;;
  status)
    if d_status; then
        echo " * $NAME is running (PID: `cat $PIDFILE`)"
    else
        echo " * $NAME is not running."
    fi
    ;;
  restart|force-reload)
    echo -n "Restarting $DESC: $NAME"
    d_stop
    sleep 1
    d_start
    echo "."
    ;;
  *)
    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
    exit 1
    ;;
esac
exit 0

 

 

You can put the above script in the file /etc/init.d/solr and set it to autostart:

cd /etc/init.d
chmod 755 solr
update-rc.d solr defaults
 

You can then also stop, start, reload or restart Solr using:

/etc/init.d/solr start|stop|restart|force-reload
 
36 542 Users on board!

Tutorial menu

Printable

Printer Friendly version of the full article on one page with plain styles

Author(s)

Proudly Developed with from