summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authorMichael Hamann <michael@content-space.de>2012-12-03 00:13:01 +0100
committerMichael Hamann <michael@content-space.de>2012-12-03 00:13:01 +0100
commit03aafe1cc677b4b0b0b0ef9ed04d8ab72f3ce583 (patch)
treefe7ab0d31d7bf435ca7696c435629d268089190b /inc
parent4f4c6fd5079db8beb50ea9b9aa08351a49a57d21 (diff)
downloadrpg-03aafe1cc677b4b0b0b0ef9ed04d8ab72f3ce583.tar.gz
rpg-03aafe1cc677b4b0b0b0ef9ed04d8ab72f3ce583.tar.bz2
Indexer: add getPID/getPageFromPID functions and PID to INDEXER_PAGE_ADD
This allows plugins to get the PID for a page and also to get the page for a certain PID. That way plugins can build their own index that uses numeric ids.
Diffstat (limited to 'inc')
-rw-r--r--inc/indexer.php59
1 files changed, 53 insertions, 6 deletions
diff --git a/inc/indexer.php b/inc/indexer.php
index f22aee3a0..cbb817d78 100644
--- a/inc/indexer.php
+++ b/inc/indexer.php
@@ -120,7 +120,7 @@ class Doku_Indexer {
return "locked";
// load known documents
- $pid = $this->addIndexKey('page', '', $page);
+ $pid = $this->getPIDNoLock($page);
if ($pid === false) {
$this->unlock();
return false;
@@ -256,7 +256,7 @@ class Doku_Indexer {
return "locked";
// load known documents
- $pid = $this->addIndexKey('page', '', $page);
+ $pid = $this->getPIDNoLock($page);
if ($pid === false) {
$this->unlock();
return false;
@@ -348,7 +348,7 @@ class Doku_Indexer {
return "locked";
// load known documents
- $pid = $this->addIndexKey('page', '', $page);
+ $pid = $this->getPIDNoLock($page);
if ($pid === false) {
$this->unlock();
return false;
@@ -454,6 +454,48 @@ class Doku_Indexer {
}
/**
+ * Get the numeric PID of a page
+ *
+ * @param string $page The page to get the PID for
+ * @return bool|int The page id on success, false on error
+ */
+ public function getPID($page) {
+ if (!$this->lock())
+ return false;
+
+ // load known documents
+ $pid = $this->getPIDNoLock($page);
+ if ($pid === false) {
+ $this->unlock();
+ return false;
+ }
+
+ $this->unlock();
+ return $pid;
+ }
+
+ /**
+ * Get the numeric PID of a page without locking the index.
+ * Only use this function when the index is already locked.
+ *
+ * @param string $page The page to get the PID for
+ * @return bool|int The page id on success, false on error
+ */
+ protected function getPIDNoLock($page) {
+ return $this->addIndexKey('page', '', $page);
+ }
+
+ /**
+ * Get the page id of a numeric PID
+ *
+ * @param int $pid The PID to get the page id for
+ * @return string The page id
+ */
+ public function getPageFromPID($pid) {
+ return $this->getIndexKey('page', '', $pid);
+ }
+
+ /**
* Find pages in the fulltext index containing the words,
*
* The search words must be pre-tokenized, meaning only letters and
@@ -946,7 +988,7 @@ class Doku_Indexer {
* @param string $idx name of the index
* @param string $suffix subpart identifier
* @param string $value line to find in the index
- * @return int line number of the value in the index
+ * @return int|bool line number of the value in the index or false if writing the index failed
* @author Tom N Harris <tnharris@whoopdedo.org>
*/
protected function addIndexKey($idx, $suffix, $value) {
@@ -1223,6 +1265,12 @@ function idx_addPage($page, $verbose=false, $force=false) {
return $result;
}
+ $Indexer = idx_get_indexer();
+ $pid = $Indexer->getPID($page);
+ if ($pid === false) {
+ if ($verbose) print("Indexer: getting the PID failed for $page".DOKU_LF);
+ return false;
+ }
$body = '';
$metadata = array();
$metadata['title'] = p_get_metadata($page, 'title', METADATA_RENDER_UNLIMITED);
@@ -1230,14 +1278,13 @@ function idx_addPage($page, $verbose=false, $force=false) {
$metadata['relation_references'] = array_keys($references);
else
$metadata['relation_references'] = array();
- $data = compact('page', 'body', 'metadata');
+ $data = compact('page', 'body', 'metadata', 'pid');
$evt = new Doku_Event('INDEXER_PAGE_ADD', $data);
if ($evt->advise_before()) $data['body'] = $data['body'] . " " . rawWiki($page);
$evt->advise_after();
unset($evt);
extract($data);
- $Indexer = idx_get_indexer();
$result = $Indexer->addPageWords($page, $body);
if ($result === "locked") {
if ($verbose) print("Indexer: locked".DOKU_LF);