Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Global search: Difference between revisions

From MoodleDocs
No edit summary
No edit summary
Line 56: Line 56:


# Go to '''Site administration -> Plugins -> Search -> Manage global search'''
# Go to '''Site administration -> Plugins -> Search -> Manage global search'''
# Enable global search, select '''Solr''' as search engine and tick all search components checkboxes
# Follow '''Search setup''' steps to complete the setup process. Basically you have to:
# Go to '''Site administration -> Plugins -> Search -> Solr'''
## Enable global search
# Set '''Host name''' to localhost, '''Port''' to 8983 and '''Collection name''' to 'moodle' (the name of the index in Solr)
## Set '''Solr''' as search engine and tick all search areas checkboxes
# The following script will add the required fields used by Moodle to the Solr index you just created.
## Go to '''Site administration -> Plugins -> Search -> Solr''' and set '''Host name''' to localhost, '''Port''' to 8983 and '''Collection name''' to 'moodle' (the name of the index in Solr)
 
    php search/engine/solr/cli/setup_schema.php




Line 68: Line 66:
Once global search is enabled a new task will be running through cron, although you can force documents indexing by:
Once global search is enabled a new task will be running through cron, although you can force documents indexing by:


# Going to '''Reports -> Search'''
# Going to '''Reports -> Global search info'''
# Tick '''Recreate index''' and '''Delete''' checkboxes and press '''Save changes'''
# Tick '''Index all site contents''' and press '''Execute'''


or
or
Line 78: Line 76:


= Querying =
= Querying =
# Hover the search icon in the navigation bar, type your query and press '''Enter'''
or


# Add '''Global search''' block somewhere
# Add '''Global search''' block somewhere
# Search stuff
# Type your query and press '''Search'''

Revision as of 08:03, 18 February 2016

Installation

To use Solr as Moodle's search engine you need the PHP Apache Solr extension and a Solr server.

PHP Apache Solr extension

You need PHP Apache Solr extension installed. Use PECL Solr Extension 1.x for Solr Server 3.x, or use PECL Solr 2.x for Solr Server 4.0+.

You can download the official latest versions from [1](http://pecl.php.net/package/solr)

Linux

   sudo apt-get install libpcre3-dev libxml2-dev libcurl4-openssl-dev
   sudo pecl install solr
   sudo service apache2 restart
   sudo echo `"extension=solr.so" > /etc/php5/apache2/conf.d/solr.ini`
   sudo echo `"extension=solr.so" > /etc/php5/cli/conf.d/solr.ini`

OSX using macports

   sudo port install apache-solr4
   sudo port install php54-solr

Windows

Install the pecl package as usual. Sorry it has not been tested yet.


Solr server

The following snippet (feel free to copy & paste into a .sh script with execution permissions) will download Apache Solr 5.4.1 in the current directory, start the solr server and create an index in it named moodle to add moodle data to it.


   #!/bin/bash
   set -e
   SOLRVERSION=5.4.1
   SOLRNAME=solr-$SOLRVERSION
   SOLRTAR=$SOLRNAME'.tgz'
   CORENAME=moodle
   if [ -d $SOLRNAME ]; then
       echo "Error: Directory $SOLRNAME already exists, remove it before starting the setup again."
       exit 1
   fi
   if [ ! -f $SOLRTAR ]; then
       wget http://apache.mirror.digitalpacific.com.au/lucene/solr/$SOLRVERSION/$SOLRTAR
   fi
   tar -xvzf $SOLRTAR
   cd $SOLRNAME
   bin/solr start
   bin/solr create -c $CORENAME
   # After setting it up and creating the index use:
   # - "/yourdirectory/solrdir/bin/solr start" from CLI to start the server
   # - "/yourdirectory/solrdir/bin/solr stop" from CLI to stop the server.

Setup

  1. Go to Site administration -> Plugins -> Search -> Manage global search
  2. Follow Search setup steps to complete the setup process. Basically you have to:
    1. Enable global search
    2. Set Solr as search engine and tick all search areas checkboxes
    3. Go to Site administration -> Plugins -> Search -> Solr and set Host name to localhost, Port to 8983 and Collection name to 'moodle' (the name of the index in Solr)


Indexing

Once global search is enabled a new task will be running through cron, although you can force documents indexing by:

  1. Going to Reports -> Global search info
  2. Tick Index all site contents and press Execute

or

  • Executing the following task from CLI
   php admin/tool/task/cli/schedule_task.php --execute="\\core\\task\\search_task"

Querying

  1. Hover the search icon in the navigation bar, type your query and press Enter

or

  1. Add Global search block somewhere
  2. Type your query and press Search