diff --git a/Drupal_Apache_Solr_Service.php b/Drupal_Apache_Solr_Service.php
index f3632f5..4d6a3a8 100644
--- a/Drupal_Apache_Solr_Service.php
+++ b/Drupal_Apache_Solr_Service.php
@@ -79,6 +79,7 @@ class DrupalApacheSolrService implements DrupalApacheSolrServiceInterface {
const LUKE_SERVLET = 'admin/luke';
const SYSTEM_SERVLET = 'admin/system';
const STATS_SERVLET = 'admin/stats.jsp';
+ const STATS_SERVLET_4 = 'admin/mbeans?wt=xml&stats=true';
/**
* Server url
@@ -220,14 +221,29 @@ class DrupalApacheSolrService implements DrupalApacheSolrServiceInterface {
return $this->luke[$num_terms];
}
+ protected function getSolrVersion() {
+ $system_info = $this->getSystemInfo();
+ // Get our solr version number
+ if (isset($system_info->lucene->{'solr-spec-version'})) {
+ return $system_info->lucene->{'solr-spec-version'}[0];
+ }
+ return 0;
+ }
+
/**
- * Sets $this->stats with the information about the Solr Core form /admin/stats.jsp
+ * Sets $this->stats with the information about the Solr Core form
*/
protected function setStats() {
$data = $this->getLuke();
+ $solr_version = $this->getSolrVersion();
// Only try to get stats if we have connected to the index.
if (empty($this->stats) && isset($data->index->numDocs)) {
- $url = $this->_constructUrl(self::STATS_SERVLET);
+ if ($solr_version >= 4) {
+ $url = $this->_constructUrl(self::STATS_SERVLET_4);
+ }
+ else {
+ $url = $this->_constructUrl(self::STATS_SERVLET);
+ }
if ($this->env_id) {
$this->stats_cid = $this->env_id . ":stats:" . drupal_hash_base64($url);
$cache = cache_get($this->stats_cid, 'cache_apachesolr');
@@ -263,6 +279,8 @@ class DrupalApacheSolrService implements DrupalApacheSolrServiceInterface {
*/
public function getStatsSummary() {
$stats = $this->getStats();
+ $solr_version = $this->getSolrVersion();
+
$summary = array(
'@pending_docs' => '',
'@autocommit_time_seconds' => '',
@@ -276,24 +294,47 @@ class DrupalApacheSolrService implements DrupalApacheSolrServiceInterface {
);
if (!empty($stats)) {
- $docs_pending_xpath = $stats->xpath('//stat[@name="docsPending"]');
- $summary['@pending_docs'] = (int) trim(current($docs_pending_xpath));
- $max_time_xpath = $stats->xpath('//stat[@name="autocommit maxTime"]');
- $max_time = (int) trim(current($max_time_xpath));
- // Convert to seconds.
- $summary['@autocommit_time_seconds'] = $max_time / 1000;
- $summary['@autocommit_time'] = format_interval($max_time / 1000);
- $deletes_id_xpath = $stats->xpath('//stat[@name="deletesById"]');
- $summary['@deletes_by_id'] = (int) trim(current($deletes_id_xpath));
- $deletes_query_xpath = $stats->xpath('//stat[@name="deletesByQuery"]');
- $summary['@deletes_by_query'] = (int) trim(current($deletes_query_xpath));
- $summary['@deletes_total'] = $summary['@deletes_by_id'] + $summary['@deletes_by_query'];
- $schema = $stats->xpath('/solr/schema[1]');
- $summary['@schema_version'] = trim($schema[0]);;
- $core = $stats->xpath('/solr/core[1]');
- $summary['@core_name'] = trim($core[0]);
- $size_xpath = $stats->xpath('//stat[@name="indexSize"]');
- $summary['@index_size'] = trim(current($size_xpath));
+ if ($solr_version <= 3) {
+ $docs_pending_xpath = $stats->xpath('//stat[@name="docsPending"]');
+ $summary['@pending_docs'] = (int) trim(current($docs_pending_xpath));
+ $max_time_xpath = $stats->xpath('//stat[@name="autocommit maxTime"]');
+ $max_time = (int) trim(current($max_time_xpath));
+ // Convert to seconds.
+ $summary['@autocommit_time_seconds'] = $max_time / 1000;
+ $summary['@autocommit_time'] = format_interval($max_time / 1000);
+ $deletes_id_xpath = $stats->xpath('//stat[@name="deletesById"]');
+ $summary['@deletes_by_id'] = (int) trim(current($deletes_id_xpath));
+ $deletes_query_xpath = $stats->xpath('//stat[@name="deletesByQuery"]');
+ $summary['@deletes_by_query'] = (int) trim(current($deletes_query_xpath));
+ $summary['@deletes_total'] = $summary['@deletes_by_id'] + $summary['@deletes_by_query'];
+ $schema = $stats->xpath('/solr/schema[1]');
+ $summary['@schema_version'] = trim($schema[0]);
+ $core = $stats->xpath('/solr/core[1]');
+ $summary['@core_name'] = trim($core[0]);
+ $size_xpath = $stats->xpath('//stat[@name="indexSize"]');
+ $summary['@index_size'] = trim(current($size_xpath));
+ }
+ else {
+ $system_info = $this->getSystemInfo();
+ $docs_pending_xpath = $stats->xpath('//lst["stats"]/long[@name="docsPending"]');
+ $summary['@pending_docs'] = (int) trim(current($docs_pending_xpath));
+ $max_time_xpath = $stats->xpath('//lst["stats"]/str[@name="autocommit maxTime"]');
+ $max_time = (int) trim(current($max_time_xpath));
+ // Convert to seconds.
+ $summary['@autocommit_time_seconds'] = $max_time / 1000;
+ $summary['@autocommit_time'] = format_interval($max_time / 1000);
+ $deletes_id_xpath = $stats->xpath('//lst["stats"]/long[@name="deletesById"]');
+ $summary['@deletes_by_id'] = (int) trim(current($deletes_id_xpath));
+ $deletes_query_xpath = $stats->xpath('//lst["stats"]/long[@name="deletesByQuery"]');
+ $summary['@deletes_by_query'] = (int) trim(current($deletes_query_xpath));
+ $summary['@deletes_total'] = $summary['@deletes_by_id'] + $summary['@deletes_by_query'];
+ $schema = $system_info->core->schema;
+ $summary['@schema_version'] = $schema;
+ $core = $stats->xpath('//lst["core"]/str[@name="coreName"]');
+ $summary['@core_name'] = trim(current($core));
+ $size_xpath = $stats->xpath('//lst["core"]/str[@name="indexSize"]');
+ $summary['@index_size'] = trim(current($size_xpath));
+ }
}
return $summary;
@@ -640,20 +681,33 @@ class DrupalApacheSolrService implements DrupalApacheSolrServiceInterface {
* Send a commit command. Will be synchronous unless both wait parameters are set to false.
*
* @param boolean $optimize Defaults to true
- * @param boolean $waitFlush Defaults to true
- * @param boolean $waitSearcher Defaults to true
- * @param float $timeout Maximum expected duration (in seconds) of the commit operation on the server (otherwise, will throw a communication exception). Defaults to 1 hour
- *
+ * optimizes the index files. Only valid for solr versions <= 3
+ * @param boolean $waitFlush
+ * block until index changes are flushed to disk. Only valid for solr versions <= 3
+ * @param boolean $waitSearcher
+ * block until a new searcher is opened and registered as the main query searcher, making the changes visible.
+ * @param float $timeout
+ * Maximum expected duration of the commit operation on the server (otherwise, will throw a communication exception)
+ * @param boolean $softCommit
+ * perform a soft commit - this will refresh the 'view' of the index in a more performant manner, but without "on-disk" guarantees.
+ *
* @return response object
*
* @throws Exception If an error occurs during the service call
*/
- public function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600) {
+ public function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600, $softCommit = false) {
$optimizeValue = $optimize ? 'true' : 'false';
$flushValue = $waitFlush ? 'true' : 'false';
$searcherValue = $waitSearcher ? 'true' : 'false';
+ $softCommit = $softCommit ? 'true' : 'false';
- $rawPost = '';
+ $solr_version = $this->getSolrVersion();
+ if ($solr_version <= 3) {
+ $rawPost = '';
+ }
+ else {
+ $rawPost = '';
+ }
$response = $this->update($rawPost, $timeout);
$this->_clearCache();
@@ -715,18 +769,30 @@ class DrupalApacheSolrService implements DrupalApacheSolrServiceInterface {
* to false.
*
* @param boolean $waitFlush
+ * block until index changes are flushed to disk Removed in Solr 4.0
* @param boolean $waitSearcher
- * @param float $timeout Maximum expected duration of the commit operation on the server (otherwise, will throw a communication exception)
+ * block until a new searcher is opened and registered as the main query searcher, making the changes visible.
+ * @param float $timeout
+ * Maximum expected duration of the commit operation on the server (otherwise, will throw a communication exception)
+ * @param boolean $softCommit
+ * perform a soft commit - this will refresh the 'view' of the index in a more performant manner, but without "on-disk" guarantees.
*
* @return response object
*
* @throws Exception If an error occurs during the service call
*/
- public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600) {
+ public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600, $softCommit = false) {
$flushValue = $waitFlush ? 'true' : 'false';
$searcherValue = $waitSearcher ? 'true' : 'false';
-
- $rawPost = '';
+ $softCommit = $softCommit ? 'true' : 'false';
+
+ $solr_version = $this->getSolrVersion();
+ if ($solr_version <= 3) {
+ $rawPost = '';
+ }
+ else {
+ $rawPost = '';
+ }
return $this->update($rawPost, $timeout);
}
diff --git a/apachesolr.admin.inc b/apachesolr.admin.inc
index 407febe..c289638 100644
--- a/apachesolr.admin.inc
+++ b/apachesolr.admin.inc
@@ -594,7 +594,9 @@ function apachesolr_index_report($environment = NULL) {
$solr = apachesolr_get_solr($environment['env_id']);
// Note: we use 2 since 1 fails on Ubuntu Hardy.
$data = $solr->getLuke(2);
- $messages[] = array(t('# of terms in index'), $data->index->numTerms);
+ if (isset($data->index->numTerms)) {
+ $messages[] = array(t('# of terms in index'), $data->index->numTerms);
+ }
}
catch (Exception $e) {
watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
diff --git a/apachesolr.interface.inc b/apachesolr.interface.inc
index a13fa8d..d6ee382 100644
--- a/apachesolr.interface.inc
+++ b/apachesolr.interface.inc
@@ -448,7 +448,7 @@ interface DrupalApacheSolrServiceInterface {
*
* @throws Exception If an error occurs during the service call
*/
- function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600);
+ function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600, $softCommit = false);
/**
* Create a delete document based on document ID
@@ -497,7 +497,7 @@ interface DrupalApacheSolrServiceInterface {
*
* @throws Exception If an error occurs during the service call
*/
- function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600);
+ function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600, $softCommit = false);
/**
* Simple Search interface
diff --git a/solr-conf/solr-4.x/protwords.txt b/solr-conf/solr-4.x/protwords.txt
new file mode 100644
index 0000000..f0fd084
--- /dev/null
+++ b/solr-conf/solr-4.x/protwords.txt
@@ -0,0 +1,8 @@
+#-----------------------------------------------------------------------
+# This file blocks words from being operated on by the stemmer and word delimiter.
+&
+<
+>
+'
+"
+
diff --git a/solr-conf/solr-4.x/schema.xml b/solr-conf/solr-4.x/schema.xml
new file mode 100644
index 0000000..eeb25b1
--- /dev/null
+++ b/solr-conf/solr-4.x/schema.xml
@@ -0,0 +1,548 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id
+
+
+ content
+
+
+
+
+
diff --git a/solr-conf/solr-4.x/solrconfig.xml b/solr-conf/solr-4.x/solrconfig.xml
new file mode 100644
index 0000000..df21783
--- /dev/null
+++ b/solr-conf/solr-4.x/solrconfig.xml
@@ -0,0 +1,1637 @@
+
+
+
+
+
+
+
+
+ ${solr.abortOnConfigurationError:true}
+
+
+ ${luceneVersion:LUCENE_35}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ false
+
+ 4
+
+ 32
+
+
+
+ 2147483647
+ 100000
+ 1000
+
+
+
+
+
+
+
+
+ single
+
+
+
+
+ false
+ 32
+ 10
+
+
+ false
+
+
+ true
+
+
+
+
+ 1
+
+ 0
+
+
+
+
+
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 10000
+ 120000
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1024
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+
+
+
+ 20
+
+
+ 200
+
+
+
+
+
+
+
+
+
+
+
+ solr rocks010
+
+
+
+
+
+ false
+
+
+ 2
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ edismax
+ explicit
+ true
+ 0.01
+
+ ${pinkPony.timeAllowed:-1}
+ *:*
+
+
+ false
+
+ true
+ false
+
+ 1
+
+
+ spellcheck
+
+
+
+
+
+
+ 1
+ 1
+ 3
+ 15
+ 20
+ false
+
+ ${mlt.timeAllowed:2000}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text
+ true
+ ignored_
+
+
+ true
+ links
+ ignored_
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ pinkPony
+ solrpingquery
+
+
+ all
+
+
+
+
+
+
+ explicit
+ true
+
+
+
+
+
+
+ ${enable.master:false}
+ commit
+ startup
+ ${confFiles}
+
+
+ ${enable.slave:false}
+ ${masterCoreUrl}/replication
+ ${pollTime:00:00:60}
+
+
+
+
+
+
+
+
+ textSpell
+
+
+
+
+
+ default
+ name
+ spellchecker
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ false
+ false
+ 1
+
+
+ spellcheck
+
+
+
+
+
+
+
+
+
+ true
+
+
+ tvComponent
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+ terms
+
+
+
+
+
+
+
+ string
+ elevate.xml
+
+
+
+
+
+ explicit
+
+
+ elevator
+
+
+
+
+
+
+
+
+
+
+ 100
+
+
+
+
+
+
+
+ 70
+
+ 0.5
+
+ [-\w ,/\n\"']{20,200}
+
+
+
+
+
+
+ ]]>
+ ]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ,,
+ ,,
+ ,,
+ ,,
+ ,]]>
+ ]]>
+
+
+
+
+
+ 10
+ .,!?
+
+
+
+
+
+
+ WORD
+
+
+ en
+ US
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/plain; charset=UTF-8
+
+
+
+
+
+
+
+
+
+ 5
+
+
+
+
+
+
+
+
+
+
+
+
+ *:*
+
+
+
+
+
+
diff --git a/solr-conf/solr-4.x/solrcore.properties b/solr-conf/solr-4.x/solrcore.properties
new file mode 100644
index 0000000..2f009ce
--- /dev/null
+++ b/solr-conf/solr-4.x/solrcore.properties
@@ -0,0 +1,10 @@
+#solrcore.properties for this specific core
+enable.master=false
+enable.slave=false
+pollTime=00:00:60
+masterCoreUrl=http://localhost:8983/solr
+confFiles=schema.xml,mapping-ISOLatin1Accent.txt,protwords.txt,stopwords.txt,synonyms.txt,elevate.xml
+mlt.timeAllowed=2000
+# You should not set your luceneVersion to anything lower then your Solr Version
+luceneVersion=LUCENE_40
+pinkPony.timeAllowed=-1
diff --git a/tests/Dummy_Solr.php b/tests/Dummy_Solr.php
index 27286c9..84d3ca1 100644
--- a/tests/Dummy_Solr.php
+++ b/tests/Dummy_Solr.php
@@ -379,7 +379,7 @@ class DummySolr implements DrupalApacheSolrServiceInterface {
*
* @throws Exception If an error occurs during the service call
*/
- function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600) {
+ function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600, $softCommit = false) {
}
/**
@@ -432,7 +432,7 @@ class DummySolr implements DrupalApacheSolrServiceInterface {
*
* @throws Exception If an error occurs during the service call
*/
- function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600) {
+ function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600, $softCommit = false) {
}
}