summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Hamann <michael@content-space.de>2011-01-23 02:00:32 +0100
committerMichael Hamann <michael@content-space.de>2011-01-23 02:06:45 +0100
commit320f489ae6a653f52f9d489b84b9bdd26f4241ac (patch)
tree6ba549bcec2c40d3c8971b484217bb00f750d403
parente1e1a7e012189660a2cfd7631e82234b5ae92f69 (diff)
downloadrpg-320f489ae6a653f52f9d489b84b9bdd26f4241ac.tar.gz
rpg-320f489ae6a653f52f9d489b84b9bdd26f4241ac.tar.bz2
Indexer v3 Rewrite: Use the metadata index for backlinks; add INDEXER_METADATA_INDEX event
This new event allows plugins to add or modify the metadata that will be indexed. Collecting this metadata in an event allows plugins to see if other plugins have already added the metadata they need and leads to just one single indexer call thus fewer files are read and written. Plugins could also replace/prevent the metadata indexer call using this event.
-rw-r--r--inc/fulltext.php19
-rw-r--r--inc/indexer.php19
2 files changed, 22 insertions, 16 deletions
diff --git a/inc/fulltext.php b/inc/fulltext.php
index 0411b9f99..35ee4ba34 100644
--- a/inc/fulltext.php
+++ b/inc/fulltext.php
@@ -124,26 +124,13 @@ function _ft_pageSearch(&$data) {
/**
* Returns the backlinks for a given page
*
- * Does a quick lookup with the fulltext index, then
- * evaluates the instructions of the found pages
+ * Uses the metadata index.
*/
function ft_backlinks($id){
$result = array();
- // quick lookup of the pagename
- // FIXME use metadata key lookup
- $page = noNS($id);
- $matches = idx_lookup(idx_tokenizer($page)); // pagename may contain specials (_ or .)
- $docs = array_keys(ft_resultCombine(array_values($matches)));
- $docs = array_filter($docs,'isVisiblePage'); // discard hidden pages
- if(!count($docs)) return $result;
-
- // check metadata for matching links
- foreach($docs as $match){
- // metadata relation reference links are already resolved
- $links = p_get_metadata($match,'relation references');
- if (isset($links[$id])) $result[] = $match;
- }
+ $result = idx_get_indexer()->lookupKey('relation_references', $id);
+ $result = $result[$id];
if(!count($result)) return $result;
diff --git a/inc/indexer.php b/inc/indexer.php
index d3d05ecd8..8859ada33 100644
--- a/inc/indexer.php
+++ b/inc/indexer.php
@@ -935,6 +935,25 @@ function idx_addPage($page, $verbose=false) {
if ($verbose) print("Indexer: locked".DOKU_LF);
return false;
}
+
+ if ($result) {
+ $data = array('page' => $page, 'metadata' => array());
+
+ if (($references = p_get_metadata($page, 'relation references')) !== null)
+ $data['metadata']['relation_references'] = array_keys($references);
+
+ $evt = new Doku_Event('INDEXER_METADATA_INDEX', $data);
+ if ($evt->advise_before()) {
+ $result = $Indexer->addMetaKeys($page, $data['metadata']);
+ if ($result === "locked") {
+ if ($verbose) print("Indexer: locked".DOKU_LF);
+ return false;
+ }
+ }
+ $evt->advise_after();
+ unset($evt);
+ }
+
if ($result)
io_saveFile(metaFN($page,'.indexed'), idx_get_version());
if ($verbose) {