Ejemplo n.º 1
0
 /**
  * List all pages in the given namespace (and below)
  */
 function search($query)
 {
     $regex = '';
     $data = ft_pageSearch($query, $regex);
     $pages = array();
     // prepare additional data
     $idx = 0;
     foreach ($data as $id => $score) {
         $file = wikiFN($id);
         if ($idx < FT_SNIPPET_NUMBER) {
             $snippet = ft_snippet($id, $regex);
             $idx++;
         } else {
             $snippet = '';
         }
         $pages[] = array('id' => $id, 'score' => intval($score), 'rev' => filemtime($file), 'mtime' => filemtime($file), 'size' => filesize($file), 'snippet' => $snippet, 'title' => useHeading('navigation') ? p_get_first_heading($id) : $id);
     }
     return $pages;
 }
Ejemplo n.º 2
0
/**
 * Run a search and display the result
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function html_search()
{
    global $conf;
    global $QUERY;
    global $ID;
    global $lang;
    $intro = p_locale_xhtml('searchpage');
    // allow use of placeholder in search intro
    $intro = str_replace(array('@QUERY@', '@SEARCH@'), array(hsc(rawurlencode($QUERY)), hsc($QUERY)), $intro);
    echo $intro;
    flush();
    //show progressbar
    print '<div class="centeralign" id="dw__loading">' . NL;
    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--' . NL;
    print 'showLoadBar();' . NL;
    print '//--><!]]></script>' . NL;
    print '<br /></div>' . NL;
    flush();
    //do quick pagesearch
    $data = array();
    $data = ft_pageLookup($QUERY, true, useHeading('navigation'));
    if (count($data)) {
        print '<div class="search_quickresult">';
        print '<h3>' . $lang['quickhits'] . ':</h3>';
        print '<ul class="search_quickhits">';
        foreach ($data as $id => $title) {
            print '<li> ';
            if (useHeading('navigation')) {
                $name = $title;
            } else {
                $ns = getNS($id);
                if ($ns) {
                    $name = shorten(noNS($id), ' (' . $ns . ')', 30);
                } else {
                    $name = $id;
                }
            }
            print html_wikilink(':' . $id, $name);
            print '</li> ';
        }
        print '</ul> ';
        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
        print '<div class="clearer"></div>';
        print '</div>';
    }
    flush();
    //do fulltext search
    $data = ft_pageSearch($QUERY, $regex);
    if (count($data)) {
        $num = 1;
        foreach ($data as $id => $cnt) {
            print '<div class="search_result">';
            print html_wikilink(':' . $id, useHeading('navigation') ? null : $id, $regex);
            if ($cnt !== 0) {
                print ': <span class="search_cnt">' . $cnt . ' ' . $lang['hits'] . '</span><br />';
                if ($num < FT_SNIPPET_NUMBER) {
                    // create snippets for the first number of matches only
                    print '<div class="search_snippet">' . ft_snippet($id, $regex) . '</div>';
                }
                $num++;
            }
            print '</div>';
            flush();
        }
    } else {
        print '<div class="nothing">' . $lang['nothingfound'] . '</div>';
    }
    //hide progressbar
    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--' . NL;
    print 'hideLoadBar("dw__loading");' . NL;
    print '//--><!]]></script>' . NL;
    flush();
}
Ejemplo n.º 3
0
/**
 * Add the result of a full text search to the feed object
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function rssSearch($opt)
{
    if (!$opt['search_query']) {
        return;
    }
    require_once DOKU_INC . 'inc/fulltext.php';
    $data = array();
    $data = ft_pageSearch($opt['search_query'], $poswords);
    $data = array_keys($data);
    return $data;
}
Ejemplo n.º 4
0
 /**
  * Just a wrapper around the Dokuwiki pageSearch function.
  *
  * @param $query
  * @return mixed
  */
 function page_search($query)
 {
     $result = array_keys(ft_pageSearch($query, $highlight));
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * List all pages in the given namespace (and below)
  */
 function search($query)
 {
     require_once DOKU_INC . 'inc/fulltext.php';
     $regex = '';
     $data = ft_pageSearch($query, $regex);
     $pages = array();
     // prepare additional data
     $idx = 0;
     foreach ($data as $id => $score) {
         $file = wikiFN($id);
         if ($idx < FT_SNIPPET_NUMBER) {
             $snippet = ft_snippet($id, $regex);
             $idx++;
         } else {
             $snippet = '';
         }
         $pages[] = array('id' => $id, 'score' => $score, 'rev' => filemtime($file), 'mtime' => filemtime($file), 'size' => filesize($file), 'snippet' => $snippet);
     }
     return $pages;
 }
Ejemplo n.º 6
0
/**
 * Run a search and display the result
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function html_search()
{
    require_once DOKU_INC . 'inc/search.php';
    require_once DOKU_INC . 'inc/fulltext.php';
    global $conf;
    global $QUERY;
    global $ID;
    global $lang;
    print p_locale_xhtml('searchpage');
    flush();
    //check if search is restricted to namespace
    if (preg_match('/([^@]*)@([^@]*)/', $QUERY, $match)) {
        $id = cleanID($match[1]);
        if (empty($id)) {
            print '<div class="nothing">' . $lang['nothingfound'] . '</div>';
            flush();
            return;
        }
    } else {
        $id = cleanID($QUERY);
    }
    //show progressbar
    print '<div class="centeralign" id="dw__loading">' . NL;
    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--' . NL;
    print 'showLoadBar();' . NL;
    print '//--><!]]></script>' . NL;
    print '<br /></div>' . NL;
    flush();
    //do quick pagesearch
    $data = array();
    $data = ft_pageLookup($id);
    if (count($data)) {
        print '<div class="search_quickresult">';
        print '<h3>' . $lang['quickhits'] . ':</h3>';
        print '<ul class="search_quickhits">';
        foreach ($data as $id) {
            print '<li> ';
            $ns = getNS($id);
            if ($ns) {
                $name = shorten(noNS($id), ' (' . $ns . ')', 30);
            } else {
                $name = $id;
            }
            print html_wikilink(':' . $id, $name);
            print '</li> ';
        }
        print '</ul> ';
        //clear float (see http://www.complexspiral.com/publications/containing-floats/)
        print '<div class="clearer">&nbsp;</div>';
        print '</div>';
    }
    flush();
    //do fulltext search
    $data = ft_pageSearch($QUERY, $regex);
    if (count($data)) {
        $num = 1;
        foreach ($data as $id => $cnt) {
            print '<div class="search_result">';
            print html_wikilink(':' . $id, useHeading('navigation') ? NULL : $id, $regex);
            print ': <span class="search_cnt">' . $cnt . ' ' . $lang['hits'] . '</span><br />';
            if ($num < 15) {
                // create snippets for the first number of matches only #FIXME add to conf ?
                print '<div class="search_snippet">' . ft_snippet($id, $regex) . '</div>';
            }
            print '</div>';
            flush();
            $num++;
        }
    } else {
        print '<div class="nothing">' . $lang['nothingfound'] . '</div>';
    }
    //hide progressbar
    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--' . NL;
    print 'hideLoadBar("dw__loading");' . NL;
    print '//--><!]]></script>' . NL;
    flush();
}
Ejemplo n.º 7
0
 function render($mode, &$renderer, $data)
 {
     $sortkeys = array();
     $incl_ns = array();
     $excl_ns = array();
     list($query, $fulltext, $sort, $group, $limit, $maxns, $proper, $cols, $inwords, $border, $fullregex, $nostart, $title, $snippet, $case, $natsort, $underline) = $data;
     if ($mode == 'xhtml') {
         // first get a raw list of matching results
         if ($fulltext) {
             // full text (Dokuwiki style) searching
             $results = array_keys(ft_pageSearch($query, $highlight));
         } else {
             // by page id only (
             if ($fullregex) {
                 // allow for raw regex mode, for power users, this searches the full page id
                 $pageonly = false;
             } else {
                 list($query, $incl_ns, $excl_ns) = $this->_parse_ns_query($query);
                 $pageonly = true;
             }
             if ($query == '*') {
                 $query = '.*';
             }
             // a lazy man's option!
             $results = $this->_page_lookup($query, $pageonly, $incl_ns, $excl_ns, $nostart, $maxns);
         }
         if (!empty($results)) {
             // this section is where the essential pagequery functionality happens...
             // prepare the necessary sorting arrays, as per users options
             $get_abstract = $snippet[0] != 'none';
             list($sort_array, $sort_opts, $group_opts) = $this->_build_sorting_array($results, $sort, $title, $proper, $inwords, $case, $natsort, $get_abstract);
             // now do the sorting (inc/msort.php)
             msort($sort_array, $sort_opts);
             // limit the result list length if required; this can only be done after sorting!
             $sort_array = $limit > 0 ? array_slice($sort_array, 0, $limit) : $sort_array;
             // and finally the grouping
             if ($group) {
                 $keys = array(NAME_KEY, ID_KEY, ABST_KEY);
                 $sorted_results = mgroup($sort_array, $keys, $group_opts);
             } else {
                 foreach ($sort_array as $row) {
                     $sorted_results[] = array(0, $row[NAME_KEY], $row[ID_KEY], $row[ABST_KEY]);
                 }
             }
             $renderer->doc .= $this->_render_list($sorted_results, $cols, $proper, $snippet, $border, $underline);
         } else {
             $renderer->doc .= $this->_render_no_list($query);
         }
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 8
0
 /**
  * Search for query in given namespace and give results list as array.
  */
 function _fulltext_search($QUERY, $namespace)
 {
     $results = array();
     $data = ft_pageSearch($QUERY, $QUERY);
     if (count($data)) {
         foreach ($data as $id => $cnt) {
             $pieces = explode(":", $id);
             list($ns, $id2) = $pieces;
             if ($ns == $namespace) {
                 array_push($results, $id);
             }
         }
     } else {
     }
     return $results;
 }
Ejemplo n.º 9
0
/**
 * Run a search and display the result
 *
 * @author Andreas Gohr <*****@*****.**>
 */
function html_search()
{
    global $conf;
    global $QUERY;
    global $ID;
    global $lang;
    print '<div class="toc">
<div class="tocheader toctoggle" id="toc__header">Table of Contents</div>
<div id="toc__inside">

<ul class="toc">
<li class="level1"><div class="li"><span class="li"><a href="#pages" class="toc">Pagenames</a></span></div></li>
<li class="level1"><div class="li"><span class="li"><a href="#authors" class="toc">Authors</a></span></div>
<li class="level1"><div class="li"><span class="li"><a href="#tools" class="toc">Tools</a></span></div></li>
<li class="level1"><div class="li"><span class="li"><a href="#articles" class="toc">Articles</a></span></div></li>
<li class="level1"><div class="li"><span class="li"><a href="#conferences" class="toc">Conferences</a></span></div></li>
<li class="level1"><div class="li"><span class="li"><a href="#other" class="toc">Other pages</a></span></div>
</ul>
</div>
</div>';
    $intro = p_locale_xhtml('searchpage');
    // allow use of placeholder in search intro
    $intro = str_replace(array('@QUERY@', '@SEARCH@'), array(hsc(rawurlencode($QUERY)), hsc($QUERY)), $intro);
    //echo $intro;
    print '<h1>Search: ' . $QUERY . '</h1>';
    flush();
    //show progressbar
    print '<div class="centeralign" id="dw__loading">' . NL;
    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--' . NL;
    print 'showLoadBar();' . NL;
    print '//--><!]]></script>' . NL;
    print '<br /></div>' . NL;
    flush();
    $articles = '/^(clip|kindle|notes)\\:/';
    $avoid = '/((^(ref|kbib|abib|jbib|bib|t|clip|kindle|notes|skimg|conf)\\:)|^start$)/';
    // add more conference namespaces at the end of $avoid and in $conferences, if you use first level namespaces
    // for this, for example I have aera11: cscl11: etc.
    $conferences = '/^(conf)\\:/';
    $tool = '/^t\\:/';
    $author = '/^a\\:/';
    //do quick pagesearch
    $data = array();
    $data = ft_pageLookup($QUERY, true, useHeading('navigation'));
    $out = '';
    foreach ($data as $id => $title) {
        if (!preg_match($avoid, $id) || preg_match('/^abib:/', $id)) {
            $out = $out . '<li> ';
            if (useHeading('navigation')) {
                $name = $title;
            } else {
                $ns = getNS($id);
                if ($ns) {
                    $name = shorten(noNS($id), ' (' . $ns . ')', 30);
                } else {
                    $name = $id;
                }
            }
            $out = $out . html_wikilink(':' . $id, $name);
            $out = $out . '</li> ';
        }
    }
    if ($out != '') {
        print '<h2 name=pages id=pages>Page titles</h2>';
        print '<ul class="search_quickhits">';
        print $out;
        print "</ul>";
        print '<div class="clearer"></div>';
        flush();
    }
    $data = ft_pageSearch($QUERY, $regexp);
    ///////////////////////////////////////////////////////////////////////////
    // authors
    $out = '';
    foreach ($data as $id => $cnt) {
        if (preg_match($author, $id)) {
            $out = $out . '<li>' . html_wikilink(':' . $id, useHeading('navigation') ? null : $id, $regexp) . '</li>';
        }
    }
    if ($out != '') {
        print '<br><h2 name=authors id=authors>Authors</h2>';
        print '<ul class="search_quickhits">';
        print $out;
        print "</ul>";
        print '<div class="clearer"></div>';
    }
    ///////////////////////////////////////////////////////////////////////////
    // tools
    $out = '';
    foreach ($data as $id => $cnt) {
        if (preg_match($tool, $id)) {
            $out = $out . '<li>' . html_wikilink(':' . $id, useHeading('navigation') ? null : $id, $regexp) . '</li>';
        }
    }
    if ($out != '') {
        print '<br><h2 name=tools id=tools>Tool results</h2>';
        print '<ul class="search_quickhits">';
        print $out;
        print "</ul>";
        print '<div class="clearer"></div>';
        flush();
    }
    ///////////////////////////////////////////////////////////////////////////
    // articles
    $out = '';
    $out2 = '';
    $pattern = '/^(clip:|skimg:|kindle:|notes:|ref:)(.*)$/';
    $already = array();
    // $json =file_get_contents(dirname ( __FILE__ )."/../lib/plugins/dokuresearchr/json.tmp");
    // $jbib = json_decode($json,true);
    foreach ($data as $id => $cnt) {
        if (preg_match('/^notes\\:/', $id)) {
            if (preg_match($pattern, $id, $matches)) {
                $idshow = $matches[2];
            } else {
                $idshow = $id;
            }
            if (!in_array($idshow, $already)) {
                $cnttxt = '';
                if ($cnt !== 0) {
                    $cnttxt = ': <span class="search_cnt">' . $cnt . ' ' . $lang['hits'] . '</span><br />';
                }
                $already[] = $idshow;
                $pub = '<div class="search_result">';
                // $entry = $jbib[$idshow];
                //print var_dump($entry);
                //$pub = $pub . html_wikilink('ref:'.$idshow,$entry[2],$regexp);
                $pub = $pub . html_wikilink('ref:' . $idshow, useHeading('navigation') ? null : $id, $regexp);
                // $citekey = substr($match,2,-1);
                // $json =file_get_contents(dirname ( __FILE__ )."/json.tmp");
                // $t = json_decode($json,true);
                // $entry = $t[$citekey];
                // $cit =  $entry[0];
                // $year = $entry[1];
                // return array($citekey,$cit,$year,$entry[2]);
                // break;
                $pub = $pub . $cnttxt;
                $out = $out . $pub . '</div>';
            }
        }
    }
    foreach ($data as $id => $cnt) {
        if (preg_match($articles, $id)) {
            if (preg_match($pattern, $id, $matches)) {
                $idshow = 'ref:' . $matches[2];
            } else {
                $idshow = $id;
            }
            if (!in_array($idshow, $already)) {
                $cnttxt = '';
                if ($cnt !== 0) {
                    $cnttxt = ': <span class="search_cnt">' . $cnt . ' ' . $lang['hits'] . '</span><br />';
                }
                $already[] = $idshow;
                $pub = '<div class="search_result">';
                $pub = $pub . html_wikilink(':' . $idshow, useHeading('navigation') ? null : $id, $regexp);
                $pub = $pub . $cnttxt . '</div>';
                $out2 = $out2 . $pub;
            }
        }
    }
    if ($out != '') {
        print '<br><h2 name=articles id=articles>Article results (notes)</h2>';
        print $out;
        flush();
    }
    if ($out != '') {
        print '<br><h2 name=articles id=articles>Article results (clippings)</h2>';
        print $out2;
        flush();
    }
    ///////////////////////////////////////////////////////////////////////////
    //conferences
    $out = '';
    foreach ($data as $id => $cnt) {
        if (preg_match($conferences, $id)) {
            if ($cnt !== 0) {
                $cnttxt = ': <span class="search_cnt">' . $cnt . ' ' . $lang['hits'] . '</span><br />';
            }
            $out = $out . '<div class="search_result">' . html_wikilink(':' . $id, useHeading('navigation') ? null : $id, $regexp);
            $out = $out . $cnttxt . '</span></div>';
        }
    }
    if ($out != '') {
        print '<br><h2 name=conferences id=conferences>Conference results</h2>';
        print $out;
        flush();
    }
    ///////////////////////////////////////////////////////////////////////////
    //other
    $out = '';
    foreach ($data as $id => $cnt) {
        if (!preg_match($avoid, $id)) {
            if ($cnt !== 0) {
                $cnttxt = ': <span class="search_cnt">' . $cnt . ' ' . $lang['hits'] . '</span><br />';
            }
            $out = $out . '<div class="search_result">' . html_wikilink(':' . $id, useHeading('navigation') ? null : $id, $regexp);
            $out = $out . $cnttxt . '</span></div>';
        }
    }
    if ($out != '') {
        print '<br><h2 name=other id=other>All other pages results</h2>';
        print $out;
        flush();
    }
    //hide progressbar
    print '<script type="text/javascript" charset="utf-8"><!--//--><![CDATA[//><!--' . NL;
    print 'hideLoadBar("dw__loading");' . NL;
    print '//--><!]]></script>' . NL;
    flush();
}