Mercurial > hg > extraction-interface
comparison search/search_locust_temple.php @ 0:b12c99b7c3f0
commit for previous development
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Mon, 19 Jan 2015 17:13:49 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b12c99b7c3f0 |
---|---|
1 <?php | |
2 | |
3 include_once('../interface/Lib_mb_utf8.php'); | |
4 include_once('../interface/config.php'); | |
5 include_once('search_function.php'); | |
6 /* | |
7 set_time_limit(0); | |
8 ini_set('memory_limit', '-1'); | |
9 | |
10 $link_mysql = mysql_connect($mysql_server, $mysql_user, $mysql_password); | |
11 mysql_query("SET NAMES utf8"); | |
12 | |
13 if (!$link_mysql) { | |
14 die('Could not connect: ' . mysql_error()); | |
15 } | |
16 | |
17 $db_selected = mysql_select_db($mysql_database, $link_mysql); | |
18 if (!$db_selected) { | |
19 die ('Can\'t use foo : ' . mysql_error()); | |
20 } | |
21 function trimKeyword($keywords){ | |
22 $token=strtok($keywords,","); | |
23 while($token!=false){ | |
24 $token=trim($token); | |
25 $keywordArray[]=$token; | |
26 $token=strtok(","); | |
27 } | |
28 return $keywordArray; | |
29 } | |
30 | |
31 function search($keywordArray){ | |
32 $condition=""; | |
33 foreach($keywordArray as $i=>$keyword){ | |
34 if($i!=0){ | |
35 $condition.=" OR "; | |
36 } | |
37 $condition.=" contents.content LIKE '%".$keyword."%' "; | |
38 } | |
39 //$query="SELECT books.name AS book_name, books.level1, books.level2, books.period, contents.books_id, contents.line, contents.content FROM contents JOIN books ON contents.books_id = books.id WHERE MATCH (content) AGAINST ('蝗神廟' IN BOOLEAN MODE) ORDER BY contents.books_id, contents.line"; | |
40 | |
41 $query="SELECT books.name AS book_name, books.level1, books.level2, books.period, contents.books_id, contents.line, contents.content | |
42 FROM contents | |
43 JOIN books ON contents.books_id = books.id | |
44 WHERE ".$condition." | |
45 ORDER BY contents.books_id, contents.line"; | |
46 //WHERE contents.content LIKE '%".$keyword."%' | |
47 $result = mysql_query($query); | |
48 //echo "result length: ".mysql_num_rows($result)."<br>"; | |
49 //go through each page | |
50 while ($row = mysql_fetch_assoc($result)) { | |
51 //find the sections that includes this page | |
52 $subQuery="SELECT id, name, start_page, end_page | |
53 FROM sections | |
54 WHERE books_id=".$row['books_id']." AND start_page<=".$row['line']." AND end_page>=".$row['line']; | |
55 $subResult=mysql_query($subQuery); | |
56 $sectionArray=array(); | |
57 while($subRow=mysql_fetch_assoc($subResult)){ | |
58 $sectionArray[]=$subRow; | |
59 } | |
60 $row['section']=$sectionArray; | |
61 | |
62 //find the next page and concatenate | |
63 $subQuery="SELECT content | |
64 FROM contents | |
65 WHERE books_id=".$row['books_id']." AND line=".($row['line']+1); | |
66 $subResult=mysql_query($subQuery); | |
67 $subRow=mysql_fetch_assoc($subResult); | |
68 $row['content'].=$subRow['content']; | |
69 | |
70 $resultArray[]=$row; | |
71 } | |
72 return $resultArray; | |
73 } | |
74 | |
75 function printTable($array,$keywordArray,$filename){ | |
76 //var_dump($array); | |
77 //return; | |
78 $header='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
79 <html> | |
80 <head> | |
81 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |
82 <link href="../search.css" type="text/css" rel="stylesheet"/> | |
83 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> | |
84 <script src="../search.js" charset="utf-8"></script> | |
85 </head> | |
86 <body>'; | |
87 $keywordStr=""; | |
88 foreach($keywordArray as $i=>$keyword){ | |
89 if($i!=0){ | |
90 $keywordStr.=", "; | |
91 } | |
92 $keywordStr.=$keyword; | |
93 } | |
94 $fp=fopen("./search_results/".$filename.".html","w"); | |
95 fwrite($fp,$header); | |
96 echo sizeof($array)." result(s) of \"".$keywordStr."\" "; | |
97 fwrite($fp,sizeof($array)." result(s) of \"".$keywordStr."\"<br><br>"); | |
98 $str="<table>"; | |
99 $str.="<tr>"; | |
100 $str.="<td class='sequence'>#<td class='bookId'>book id<td class='bookName'>book name<td class='level1'>level1<td class='level2'>level2<td class='period'>period<td class='sectionName'>section info<td class='page'>page<td class='content'>content"; | |
101 fwrite($fp,$str); | |
102 echo $str; | |
103 $i=1; | |
104 foreach($array as $row){ | |
105 $str="<tr>"; | |
106 $str.="<td>".$i; | |
107 $str.="<td>".$row['books_id']; | |
108 $str.="<td>".$row['book_name']; | |
109 $str.="<td>".$row['level1']; | |
110 $str.="<td>".$row['level2']; | |
111 $str.="<td>".$row['period']; | |
112 $str.="<td>"; | |
113 fwrite($fp,$str); | |
114 echo $str; | |
115 foreach($row['section'] as $section){ | |
116 $str="<div class='section'><a href='tagging_text.php?id=".$section['id']."' target='_blank'>".$section['name']."</a>p".$section['start_page']."-".$section['end_page']."</div>"; | |
117 echo $str; | |
118 $str="<div class='section'><a href='../tagging_text.php?id=".$section['id']."' target='_blank'>".$section['name']."</a>p".$section['start_page']."-".$section['end_page']."</div>"; | |
119 fwrite($fp,$str); | |
120 } | |
121 $str="<td>".$row['line']; | |
122 //$str.="<td>".$row['content']; | |
123 $str.="<td>".findLocustTempleDescription($row['content'],$keywordArray,0); | |
124 fwrite($fp,$str); | |
125 echo $str; | |
126 $i++; | |
127 } | |
128 | |
129 echo "</table>"; | |
130 fwrite($fp,"</table></body></html>"); | |
131 fclose($fp); | |
132 } | |
133 */ | |
134 | |
135 ?> | |
136 | |
137 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> | |
138 <html> | |
139 <head> | |
140 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> | |
141 <link href="search.css" type="text/css" rel="stylesheet"/> | |
142 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script> | |
143 <script src="search.js" charset="utf-8"></script> | |
144 </head> | |
145 <body> | |
146 <form action='search_locust_temple.php' method='POST'> | |
147 關鍵字: <input type="text" name="keyword"> (若要搜尋多筆關鍵字請用半型逗號,隔開)<br> | |
148 將結果輸出至: <input type="text" name="filename">.html<br> | |
149 <input type="submit" name="search" value="搜尋"> | |
150 </form> | |
151 <br> | |
152 <div id="search_result"> | |
153 <?php | |
154 if(isset($_POST['search']) && $_POST['keyword']!='' && $_POST['filename']!=''){ | |
155 $keywordArray=trimKeyword($_POST['keyword']); | |
156 $array=search($keywordArray); | |
157 writeCsvFile($array,$_POST['filename']); | |
158 printTable($array,$keywordArray,$_POST['filename'],$LOCUST_TEMPLE); | |
159 } | |
160 ?> | |
161 </div> | |
162 </body> | |
163 </html> | |
164 |