Not logged in. · Lost password · Register
Forum: General Help and Support Development RSS
how to index content injected into page?
Avatar
gilcot #1
Member since Aug 2018 · 12 posts · Location: France
Group memberships: Members
Show profile · Link to this post
Subject: how to index content injected into page?
Hello,

I'm writing a plugin that pull data from database tables into DokuWiki.
But I'm facing a problem: the content pulled into the wiki cannont be found in search.

To reproduce, copy the NOW example so:
    <?php
    /**
     * Plugin Now: Inserts a timestamp.
     *
     * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
     * @author     Christopher Smith <chris@jalakai.co.uk>
     */
    
    // must be run within DokuWiki
    if(!defined('DOKU_INC')) die();
    
    /**
     * All DokuWiki plugins to extend the parser/rendering mechanism
     * need to inherit from this class
     */
    class syntax_plugin_now extends DokuWiki_Syntax_Plugin {
    
        public function getType() { return 'substition'; }
        public function getSort() { return 32; }
    
        public function connectTo($mode) {
            $this->Lexer->addSpecialPattern('\[lorem\]',$mode,'plugin_now');
        }
    
        public function handle($match, $state, $pos, Doku_Handler $handler) {
            return array($match, $state, $pos);
        }
    
        public function render($mode, Doku_Renderer $renderer, $data) {
        // $data is what the function handle return'ed.
            if($mode == 'xhtml'){
                /** @var Doku_Renderer_xhtml $renderer */
                $renderer->doc .= "Aliquam convallis sollicitudin purus. Praesent aliquam, enim at fermentum mollis, ligula massa adipiscing nisl, ac euismod nibh nisl eu lectus. Fusce vulputate sem at sapien. Vivamus leo. Aliquam euismod libero eu enim. Nulla nec felis sed leo placerat imperdiet. Aenean suscipit nulla in justo. Suspendisse cursus rutrum augue. Nulla tincidunt tincidunt mi. Curabitur iaculis, lorem vel rhoncus faucibus, felis magna fermentum augue, et ultricies lacus lorem varius purus. Curabitur eu amet.";
                return true;
            }
            return false;
        }
    }

...Then put "[lorem]" in a page, save it, then search for "nisl" or "massa" for example. Even days after, it won't be found... How to solve it? How to inject my data in the indexer?

Thanks a lot.
Avatar
turnermm (Moderator) #2
Member since Oct 2009 · 4544 posts · Location: Canada
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
It can only be indexed if the data is actually embedded in the page, and not if it is inserted during the html phase of the output. 

render->doc includes the data in the html output and not in the wiki page.  Indexing occurs on the server, i.e. from the wiki page, and this data in not on the server.
Myron Turner
github: https://github.com/turnermm
plugins, templates: http://www.mturner.org/devel
Avatar
gilcot #3
Member since Aug 2018 · 12 posts · Location: France
Group memberships: Members
Show profile · Link to this post
Thanks a lot: your answer makes things clear for me.

Well, is it possible to "inject" needed words in the indexation and refer to the page I'm doing that from?
(hmm maybe I should also change my subject from here?)
Avatar
turnermm (Moderator) #4
Member since Oct 2009 · 4544 posts · Location: Canada
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
One possibility is the tag plugin, if what you want is to find pages on which a certain subject appears.  The tags themselves will be indexed by the dokuwiki indexer and also the tag plugin will create its own indexes of pages which contain a particular tag.
Myron Turner
github: https://github.com/turnermm
plugins, templates: http://www.mturner.org/devel
Avatar
gilcot #5
Member since Aug 2018 · 12 posts · Location: France
Group memberships: Members
Show profile · Link to this post
This one plugin:tagging or this one plugin:tag or something else ? I'll look at them deeper, but at first it's like I'll have to add my data again (as tag) :-/
Avatar
andi (Administrator) #6
User title: splitbrain
Member since May 2006 · 3400 posts · Location: Berlin Germany
Group memberships: Administrators, Members
Show profile · Link to this post
In reply to post #3
Quote by gilcot on 2018-08-14, 13:23:
Well, is it possible to "inject" needed words in the indexation

Yes. See https://www.dokuwiki.org/devel:event:indexer_page_add
Read this if you don't get any useful answers.
Lies dies wenn du keine hilfreichen Antworten bekommst.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-03-21, 23:15:53 (UTC +01:00)