1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
3 include '../inc/common.php';
7 if (preg_match('/^#([a-zA-Z0-9]+)$/', $q, $M)) {
9 header("Location: {$ABSWEB}ticket.php/$M[1]");
12 if (preg_match('/^r([a-zA-Z]*\d+)$/', $q, $M)) {
14 $url = mtrack_changeset_url($M[1]);
15 header("Location: $url");
18 if (preg_match('/^\[([a-zA-Z]*\d+)\]$/', $q, $M)) {
20 $url = mtrack_changeset_url($M[1]);
21 header("Location: $url");
24 if (preg_match('/^\{(\d+)\}$/', $q, $M)) {
26 header("Location: {$ABSWEB}report.php/$M[1]");
29 mtrack_head("Search results for \"$q\"");
32 <h1>Search results</h1>
34 <form action="<?php echo $ABSWEB; ?>search.php">
35 <input type="text" name="q"
37 value="<?php echo htmlentities($q, ENT_QUOTES, 'utf-8'); ?>">
38 <button type="submit">Search</button>
39 Read more about <a href="<?php echo $ABSWEB ; ?>help.php/Searching">Searching</a>.
40 <button id='togglesummary' type='button'>Show Fields</button>
42 $(document).ready(function () {
43 $('#togglesummary').click(function () {
44 $('#fieldsummary').toggle();
48 <div id='fieldsummary' style='display:none'>
49 <p>The following fields are available for targeted searching:</p>
59 <td>The one-line ticket summary</td>
64 <td>The ticket description</td>
69 <td>The changelog field</td>
74 <td>The keyword field</td>
79 <td>The last-changed date</td>
84 <td>who last changed the ticket</td>
89 <td>who opened the ticket</td>
94 <td>The date that the ticket was created</td>
99 <td>who is responsible for the ticket</td>
104 <td>The comment text</td>
109 <td>Date the comment was made</td>
114 <td>who made that comment</td>
119 <td>The content from the wiki page</td>
124 <td>Who last changed that wiki page</td>
129 <td>Date the wiki page was last changed</td>
132 $CF = MTrackTicket_CustomFields::getInstance();
133 foreach ($CF->fields as $f) {
134 echo "<tr><td>Ticket</td><td>$f->name</td><td>",
135 htmlentities($f->label, ENT_QUOTES, 'utf-8'),
147 $start = microtime(true);
148 $hits = MTrackSearchDB::search($q);
149 $end = microtime(true);
150 $elapsed = sprintf("%.2f seconds", $end - $start);
161 echo htmlentities($q, ENT_QUOTES, 'utf-8'), "</i>:</p><br>\n";
163 $hits_by_object = array();
165 /* aggregate results by canonical object; since
166 * we index comments separately from the top level
167 * item, we need to adjust for that here */
168 foreach ($hits as $hit) {
169 /* get canonical object */
170 list($item, $id) = explode(':', $hit->objectid, 3);
172 $object = "$item:$id";
173 if (isset($hits_by_object[$object])) {
174 if ($hit->score > $hits_by_object[$object]) {
175 $hits_by_object[$object] = $hit->score;
176 $objects[$object] = $hit;
179 $hits_by_object[$object] = $hit->score;
180 $objects[$object] = $hit;
183 arsort($hits_by_object);
185 <table class='searchresults'>
191 foreach ($hits_by_object as $object => $score) {
192 list($item, $id) = explode(':', $object, 2);
193 $obj = $objects[$object];
194 $score = (int)($score * 100);
196 $html = "<tr><td valign='right'>$score%</td><td>";
200 $tkt = MTrackIssue::loadByNSIdent($id);
202 $tkt = MTrackIssue::loadById($id);
204 $aclid = "ticket:" . $tkt->tid;
205 $html .= mtrack_ticket($tkt);
207 $url = "{$ABSWEB}ticket.php/$tkt->nsident";
209 $url = "{$ABSWEB}ticket.php/$id";
211 $html .= " <a href='$url'>";
212 $html .= htmlentities($tkt->summary, ENT_QUOTES, 'utf-8');
214 $html .= $obj->getExcerpt($tkt->description);
218 $wiki = MTrackWikiItem::loadByPageName($id);
220 $url = "{$ABSWEB}wiki.php/$id";
221 $html .= "<a href='$url'>".
222 htmlentities($id, ENT_QUOTES, 'utf-8').
224 $html .= $obj->getExcerpt($wiki->content);
231 if (!MTrackACL::hasAnyRights($aclid, 'read')) {
236 $html .= "</td></tr>\n";
241 if (!count($hits_by_object)) {
242 echo "<em>No matches</em>";
244 echo "<em>" . count($hits_by_object) . " results in $elapsed</em>\n";
247 echo "<br>Denied access to $denied items<br>\n";