• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisión4e68acffee5720799755c9ea9483bb3c24216162 (tree)
Tiempo2016-11-25 03:17:15
Autorumorigu <umorigu@gmai...>
Commiterumorigu

Log Message

BugTrack/692 Show search result details

Cambiar Resumen

Diferencia incremental

--- a/lib/func.php
+++ b/lib/func.php
@@ -269,6 +269,7 @@ function do_search($word, $type = 'AND', $non_format = FALSE, $base = '')
269269
270270 ksort($pages, SORT_STRING);
271271
272+
272273 $retval = '<ul>' . "\n";
273274 foreach (array_keys($pages) as $page) {
274275 $r_page = rawurlencode($page);
@@ -286,6 +287,116 @@ function do_search($word, $type = 'AND', $non_format = FALSE, $base = '')
286287 return $retval;
287288 }
288289
290+function do_search_part($words, $start_index, $search_page_count)
291+{
292+// echo 'aaa';
293+// print_r($words);
294+// echo 'bbb';
295+ global $non_list;
296+ $pages = get_existpages();
297+ // Avoid
298+ if ($base != '') {
299+ $pages = preg_grep('/^' . preg_quote($base, '/') . '/S', $pages);
300+ }
301+ if (! $search_non_list) {
302+ $pages = array_diff($pages, preg_grep('/' . $non_list . '/S', $pages));
303+ }
304+ $pages = array_flip($pages);
305+ unset($pages[$whatsnew]);
306+ $count = count($pages);
307+ foreach (array_keys($pages) as $page) {
308+ if (! check_readable($page, false, false)) {
309+ unset($pages[$page]);
310+ --$count;
311+ }
312+ }
313+ $found_pages = array();
314+ $i = 0;
315+ $end_index = $start_index + $search_page_count;
316+ $last_index = -1;
317+ $last_search_page = '';
318+ $next_search_index = -1;
319+ foreach (array_keys($pages) as $page) {
320+ if (($index = $i++) < $start_index) {
321+ continue;
322+ }
323+ if ($end_index <= $index) {
324+ $next_search_index = $index;
325+ break;
326+ }
327+ $last_index = $index;
328+ $last_search_page = $page;
329+ $page_result = do_search_singlepage($words, $page);
330+ if ($page_result === FALSE) {
331+ continue;
332+ }
333+ $found_pages[] = $page_result;
334+ }
335+ $result = array(
336+ 'start_index' => $start_index,
337+ 'last_index' => $last_index,
338+ 'last_search_page' => $last_search_page,
339+ 'end_index' => $end_index,
340+ 'found_pages' => $found_pages,
341+ 'total_page_count' => count($pages),
342+ 'q' => $words
343+ );
344+ if ($next_search_index >= 0) {
345+ $result['next_search_index'] = $next_search_index;
346+ }
347+ return $result;
348+}
349+
350+function do_search_singlepage($words, $page) {
351+ $max_lines = 20;
352+ $prevlines = 2;
353+ $extralines = 2;
354+ $lines = get_source($page, TRUE, FALSE);
355+ $result_lines = array();
356+ $last_added_index = -1;
357+ $last_found_index = -1;
358+ foreach ($lines as $i => $line) {
359+ if (search_words($words, $line)) {
360+ for ($j = max($i - $prevlines, $last_added_index + 1); $j < $i; $j++) {
361+ $result_lines[] = array('index' => $j, 'line' => $lines[$j]);
362+ }
363+ $result_lines[] = array('index' => $i, 'line' => $line);
364+ $last_found_index = $i;
365+ $last_added_index = $i;
366+ } else {
367+ if ($last_found_index >= 0 &&
368+ $i <= $last_found_index + $extralines) {
369+ $result_lines[] = array('index' => $i, 'line' => $line);
370+ $last_added_index = $i;
371+ }
372+ }
373+ if (count($result_lines) > $max_lines) {
374+ break;
375+ }
376+ }
377+ $link = get_script_uri() . '?' . pagename_urlencode($page);
378+ if (count($result_lines) > 0) {
379+ return array(
380+ 'page' => $page,
381+ 'lines' => $result_lines,
382+ 'link' => $link
383+ );
384+ } else {
385+ return FALSE;
386+ }
387+}
388+
389+function search_words($words, $target) {
390+ $qwords = preg_quote($words, '/');
391+ $m = null;
392+ if (preg_match('/' . $qwords . '/i', $target, $m)) {
393+ return TRUE;
394+ } else {
395+ return FALSE;
396+ }
397+}
398+
399+
289400 // Argument check for program
290401 function arg_check($str)
291402 {
--- a/plugin/search.inc.php
+++ b/plugin/search.inc.php
@@ -29,6 +29,13 @@ function plugin_search_action()
2929 {
3030 global $post, $vars, $_title_result, $_title_search, $_msg_searching;
3131
32+ if (isset($vars['action']) && $vars['action'] === 'list') {
33+ header('Content-Type: applicaton/json');
34+ $result = do_search_part($vars['q'], 0, 10);
35+ $json = json_encode($result, JSON_UNESCAPED_UNICODE);
36+ echo($json);
37+ exit;
38+ }
3239 if (PLUGIN_SEARCH_DISABLE_GET_ACCESS) {
3340 $s_word = isset($post['word']) ? htmlsc($post['word']) : '';
3441 } else {
@@ -56,6 +63,7 @@ function plugin_search_action()
5663 // Show search form
5764 $bases = ($base == '') ? array() : array($base);
5865 $body .= plugin_search_search_form($s_word, $type, $bases);
66+ $body .= '<script src="skin/search.js"></script>' . "\n";
5967
6068 return array('msg'=>$msg, 'body'=>$body);
6169 }
--- /dev/null
+++ b/skin/search.js
@@ -0,0 +1,63 @@
1+window.addEventListener && window.addEventListener('load', function() {
2+ 'use strict';
3+ var xhr = new XMLHttpRequest();
4+ xhr.responseType = 'json';
5+ xhr.onload = function(e) {
6+ console.log('status: ' + e);
7+ console.log(e);
8+ var searchResult = xhr.response;
9+ console.log(searchResult);
10+ addResultArea();
11+ addSearchResults(searchResult.found_pages);
12+ };
13+ console.log(xhr);
14+ console.log('aaa');
15+ xhr.open('POST', 'http://localhost:8070/pwd/b2390/', true);
16+ console.log('bbb');
17+ xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
18+ xhr.send('q=bug&cmd=search&action=list&start=0');
19+
20+ function addSearchResults(resultList) {
21+ var ul = document.querySelector('#search_result_ul');
22+ resultList.forEach(function(value, index) {
23+ addSearchResult(ul, value);
24+ });
25+
26+ }
27+ function getLinedText(data) {
28+ var lines = [];
29+ data.lines.forEach(function(item) {
30+ lines.push('' + (item.index + 1) + ':' + item.line);
31+ });
32+ return lines.join('');
33+ }
34+ function addSearchResult(ul, data) {
35+ // <li>
36+ var a = document.createElement('a');
37+ var aLabel = document.createTextNode(data.page);
38+ a.href = data.link;
39+ a.appendChild(aLabel);
40+ var li = document.createElement('li');
41+ li.appendChild(a);
42+ ul.appendChild(li);
43+ // <pre>
44+ var pre = document.createElement('pre');
45+ //var preText = document.createTextNode(getLinedText(data));
46+ pre.innerHTML = getLinedText(data);
47+ //pre.appendChild(preText);
48+ ul.appendChild(pre);
49+ }
50+ function addResultArea() {
51+ var bodyDiv = document.querySelector('div#body');
52+ // <hr>
53+ var hr = document.createElement('hr');
54+ hr.className = 'full_hr';
55+ //var hr
56+ bodyDiv.insertBefore(hr, bodyDiv.childNodes[0]);
57+
58+ // <ul>
59+ var ul = document.createElement('ul');
60+ ul.id = 'search_result_ul';
61+ bodyDiv.insertBefore(ul, hr);
62+ }
63+});