2 This module integrates Drupal with the Apache Solr search platform. Solr search
3 can be used as a replacement for core content search and boasts both extra
4 features and better performance. Among the extra features is the ability to have
5 faceted search on facets ranging from content author to taxonomy to arbitrary
8 The module comes with a schema.xml, solrconfig.xml, and protwords.txt file which
9 must be used in your Solr installation.
11 This module depends on the search framework in core. However, you may not want
12 the core searches and only want Solr search. If that is the case, you want to
13 use the Core Searches module in tandem with this module.
15 When used in combination with core search module, Apache Solr is not the default
16 search. Access it via a new tab on the default search page, called "Search".
21 Prerequisite: Java 5 or higher (a.k.a. 1.5.x). PHP 5.1.4 or higher.
23 Those with PHP < 5.2.0 must install the PECL json module or download
24 the Json code from the Zend Framework (see below).
26 Install the Apache Solr Drupal module as you would any Drupal module.
28 Before enabling it, you must also do the following:
30 Get the PHP library from the external project. The project is
31 found at: http://code.google.com/p/solr-php-client/
33 If you use drush make, run this command from the apachesolr module directory:
35 drush make --no-core -y --contrib-destination=. apachesolr.make
37 Otherwise, from the apachesolr module directory, run this command:
39 svn checkout -r22 http://solr-php-client.googlecode.com/svn/trunk/ SolrPhpClient
41 Alternately you may download and extract the library from
42 http://code.google.com/p/solr-php-client/downloads/list
44 Make sure to select a r22 archive, either of these two:
45 http://solr-php-client.googlecode.com/files/SolrPhpClient.r22.2009-11-09.zip
46 http://solr-php-client.googlecode.com/files/SolrPhpClient.r22.2009-11-09.tgz
48 Note that revision 22 is the currently tested and required revision.
49 Make sure that the final directory is named SolrPhpClient under the apachesolr
52 If you are maintaing your code base in subversion, you may choose instead to
53 use svn export or svn externals. For an export (writing a copy to your local
54 directory without .svn files to track changes) use:
56 svn export -r22 http://solr-php-client.googlecode.com/svn/trunk/ SolrPhpClient
58 Instead of checking out, externals can be used too. Externals can be seen as
59 (remote) symlinks in svn. This requires your own project in your own svn ]
60 repository, off course. In the apachesolr module directory, issue the command:
62 svn propedit svn:externals .
64 Your editor will open. Add a line
66 SolrPhpClient -r22 http://solr-php-client.googlecode.com/svn/trunk/
68 On exports and checkouts, svn will grab the externals, but it will keep the
69 references on the remote server.
71 Those without svn, etc may also choose to try the bundled Acquia Search
72 download, which includes all the items which are not in Drupal.org CVS due to
73 CVS use policy. See the download link here:
74 http://acquia.com/documentation/acquia-search/activation
76 Download the latest Solr 1.4.x release (e.g. 1.4.1) from:
77 http://www.apache.org/dyn/closer.cgi/lucene/solr/
79 Unpack the tarball somewhere not visible to the web (not in your apache docroot
80 and not inside of your drupal directory).
82 The Solr download comes with an example application that you can use for
83 testing, development, and even for smaller production sites. This
84 application is found at apache-solr-1.4.1/example.
86 Move apache-solr-1.4.1/example/solr/conf/schema.xml and rename it to
87 something like schema.bak. Then move the schema.xml that comes with the
88 ApacheSolr Drupal module to take its place.
90 Similarly, move apache-solr-1.4.1/example/solr/conf/solrconfig.xml and rename
91 it like solrconfig.bak. Then move the solrconfig.xml that comes with the
92 ApacheSolr Drupal module to take its place.
94 Finally, move apache-solr-1.4.1/example/solr/conf/protwords.txt and rename
95 it like protwords.bak. Then move the protwords.txt that comes with the
96 ApacheSolr Drupal module to take its place.
98 Make sure that the conf directory includes the following files - the Solr core
99 may not load if you don't have at least an empty file present:
103 mapping-ISOLatin1Accent.txt
108 Now start the solr application by opening a shell, changing directory to
109 apache-solr-1.4.1/example, and executing the command java -jar start.jar
111 Test that your solr server is now available by visiting
112 http://localhost:8983/solr/admin/
114 For those using PHP 5.1, you must either install the PECL json extension
115 into PHP on your sever, or you may use the Zend framework Json library.
116 for the PECL extension see: http://pecl.php.net/package/json
117 The Solr client has been tested with Zend framework release 1.7.7.
118 To get this code, you may use svn from the apachesolr directory:
119 svn co http://framework.zend.com/svn/framework/standard/tags/release-1.7.7/library/Zend
120 However, the only required parts are:
121 http://framework.zend.com/svn/framework/standard/tags/release-1.7.7/library/Zend/Exception.php
122 http://framework.zend.com/svn/framework/standard/tags/release-1.7.7/library/Zend/Json/
123 The 'Zend' directory should normally be under the apachesolr
124 directory, but may be elsewhere if you set that location to be
125 in your PHP include path.
127 Now, you should enable the "Apache Solr framework" and "Apache Solr search"
128 modules. Check that you can connect to Solr at ?q=admin/setting/apachesolr
129 Now run cron on your Drupal site until your content is indexed. You
130 can monitor the index at ?q=admin/settings/apachesolr/index
132 The solrconfig.xml that comes with this modules defines auto-commit, so
133 it may take a few minutes between running cron and when the new content
134 is visible in search.
136 Enable blocks for facets first at Administer > Site configuration > Apache Solr > Enabled filters,
137 then position them as you like at Administer > Site building > Blocks.
139 Configuration variables
142 The module provides some (hidden) variables that can be used to tweak its
145 - apachesolr_luke_limit: the limit (in terms of number of documents in the
146 index) above which the module will not retrieve the number of terms per field
147 when performing LUKE queries (for performance reasons).
149 - apachesolr_tags_to_index: the list of HTML tags that the module will index
150 (see apachesolr_add_tags_to_document()).
152 - apachesolr_exclude_nodeapi_types: an array of node types each of which is
153 an array of one or more module names, such as 'comment'. Any type listed
154 will have any listed modules' nodeapi 'update_index' implementation skipped
155 when indexing. This can be useful for excluding comments or taxonomy links.
157 - apachesolr_ping_timeout: the timeout (in seconds) after which the module will
158 consider the Apache Solr server unavailable.
160 - apachesolr_optimize_interval: the interval (in seconds) between automatic
161 optimizations of the Apache Solr index. Set to 0 to disable.
163 - apachesolr_cache_delay: the interval (in seconds) after an update after which
164 the module will requery the Apache Solr for the index structure. Set it to
165 your autocommit delay plus a few seconds.
167 - apachesolr_service_class: the Apache_Solr_Service class used for communicating
168 with the Apache Solr server.
170 - apachesolr_query_class: the default query class to use.
172 - apachesolr_cron_mass_limit: update or delete at most this many documents in
173 each Solr request, such as when making {apachesolr_search_node} consistent
179 Links to nodes appear in the search results with a different host name or
180 subdomain than is preferred. e.g. sometimes at http://example.com
181 and sometimes at http://www.example.com
184 Set $base_url in settings.php to insure that an identical absolute url is
185 generated at all times when nodes are indexed. Alternately, set up a re-direct
186 in .htaccess to prevent site visitors from accessing the site via more than one
193 Exposed Hooks in 6.x:
195 hook_apachesolr_modify_query(&$query, &$params, $caller);
197 Any module performing a search should call apachesolr_modify_query($query, $params, 'modulename').
198 That function then invokes this hook. It allows modules to modify the query object and params array.
199 $caller indicates which module is invoking the hook.
203 function my_module_apachesolr_modify_query(&$query, &$params, $caller) {
204 // I only want to see articles by the admin!
205 $query->add_filter("uid", 1);
208 CALLER_finalize_query(&$query, &$params);
210 The module calling apachesolr_do_query() may implement a function that is run after
211 hook_apachesolr_modify_query() and allows the caller to make final changes to the
212 query and params before the query is sent to Solr. The function name is built
213 from the $caller parameter to apachesolr_do_query().
215 hook_apachesolr_prepare_query(&$query, &$params, $caller);
217 This is pretty much the same as hook_apachesolr_modify_query() but runs earlier
218 and before the query is statically cached. It can e.g. be used to add
219 available sorts to the query.
223 function my_module_apachesolr_prepare_query(&$query) {
224 // Add a sort on the node ID.
225 $query->set_available_sort('nid', array(
226 'title' => t('Node ID'),
231 hook_apachesolr_cck_fields_alter(&$mappings)
233 Add or alter index mappings for CCK types. The default mappings array handles just
234 text fields with option widgets:
236 $mappings['text'] = array(
237 'optionwidgets_select' => array('callback' => '', 'index_type' => 'string'),
238 'optionwidgets_buttons' => array('callback' => '', 'index_type' => 'string')
241 In your _alter hook implementation you can add additional field types such as:
243 $mappings['number_integer']['number'] = array('callback' => '', 'index_type' => 'integer');
245 You can allso add a mapping for a specific field. This will take precedence over any
246 mapping for a general field type. A field-specific mapping would look like:
248 $mappings['per-field']['field_model_name'] = array('callback' => '', 'index_type' => 'string');
252 $mappings['per-field']['field_model_price'] = array('callback' => '', 'index_type' => 'float');
254 If a custom field needs to be searchable but does not need to be faceted you can change the 'facets'
255 parameter to FALSE, like:
257 $mappings['number_integer']['number'] = array('callback' => '', 'index_type' => 'integer', 'facets' => FALSE);
259 hook_apachesolr_types_exclude($namespace)
262 Invoked by apachesolr.module when generating a list of nodes to index for a given
263 namespace. Return an array of node types to be excldued from indexing for that namespace
264 (e.g. 'apachesolr_search'). This is used by apachesolr_search module to exclude
265 certain node types from the index.
267 hook_apachesolr_node_exclude($node, $namespace)
269 This is invoked by apachesolr.module for each node to be added to the index - if any module
270 returns TRUE, the node is skipped for indexing.
272 hook_apachesolr_update_index(&$document, $node)
274 Allows a module to change the contents of the $document object before it is sent to the Solr Server.
275 To add a new field to the document, you should generally use one of the pre-defined dynamic fields.
276 Follow the naming conventions for the type of data being added based on the schema.xml file.
278 hook_apachesolr_search_result_alter(&$doc)
280 The is invoked by apachesolr_search.module for each document returned in a search - new in 6.x-beta7
281 as a replacement for the call to hook_nodeapi().
283 hook_apachesolr_sort_links_alter(&$sort_links)
285 Called by the sort link block code. Allows other modules to modify, add or remove sorts.
290 See inline docs in apachesolr_theme and apachesolr_search_theme functions
291 within apachesolr.module and apachesolr_search.module.