1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
6 include '../inc/common.php';
10 if (preg_match('/^#([a-zA-Z0-9]+)$/', $q, $M)) {
12 header("Location: {$ABSWEB}ticket.php/$M[1]");
15 if (preg_match('/^r([a-zA-Z]*\d+)$/', $q, $M)) {
17 $url = mtrack_changeset_url($M[1]);
18 header("Location: $url");
21 if (preg_match('/^\[([a-zA-Z]*\d+)\]$/', $q, $M)) {
23 $url = mtrack_changeset_url($M[1]);
24 header("Location: $url");
27 if (preg_match('/^\{(\d+)\}$/', $q, $M)) {
29 header("Location: {$ABSWEB}report.php/$M[1]");
32 mtrack_head("Search results for \"$q\"");
35 <h1>Search results</h1>
37 <form action="<?php echo $ABSWEB; ?>search.php">
38 <input type="text" name="q"
40 value="<?php echo htmlentities($q, ENT_QUOTES, 'utf-8'); ?>">
41 <button type="submit">Search</button>
42 Read more about <a href="<?php echo $ABSWEB ; ?>help.php/Searching">Searching</a>.
43 <button id='togglesummary' type='button'>Show Fields</button>
45 $(document).ready(function () {
46 $('#togglesummary').click(function () {
47 $('#fieldsummary').toggle();
51 <div id='fieldsummary' style='display:none'>
52 <p>The following fields are available for targeted searching:</p>
62 <td>The one-line ticket summary</td>
67 <td>The ticket description</td>
72 <td>The changelog field</td>
77 <td>The keyword field</td>
82 <td>The last-changed date</td>
87 <td>who last changed the ticket</td>
92 <td>who opened the ticket</td>
97 <td>The date that the ticket was created</td>
102 <td>who is responsible for the ticket</td>
107 <td>The comment text</td>
112 <td>Date the comment was made</td>
117 <td>who made that comment</td>
122 <td>The content from the wiki page</td>
127 <td>Who last changed that wiki page</td>
132 <td>Date the wiki page was last changed</td>
135 $CF = MTrackTicket_CustomFields::getInstance();
136 foreach ($CF->fields as $f) {
137 echo "<tr><td>Ticket</td><td>$f->name</td><td>",
138 htmlentities($f->label, ENT_QUOTES, 'utf-8'),
150 $start = microtime(true);
151 $hits = MTrackSearchDB::search($q);
152 $end = microtime(true);
153 $elapsed = sprintf("%.2f seconds", $end - $start);
164 echo htmlentities($q, ENT_QUOTES, 'utf-8'), "</i>:</p><br>\n";
166 $hits_by_object = array();
168 /* aggregate results by canonical object; since
169 * we index comments separately from the top level
170 * item, we need to adjust for that here */
171 foreach ($hits as $hit) {
172 /* get canonical object */
173 list($item, $id) = explode(':', $hit->objectid, 3);
175 $object = "$item:$id";
176 if (isset($hits_by_object[$object])) {
177 if ($hit->score > $hits_by_object[$object]) {
178 $hits_by_object[$object] = $hit->score;
179 $objects[$object] = $hit;
182 $hits_by_object[$object] = $hit->score;
183 $objects[$object] = $hit;
186 arsort($hits_by_object);
188 <table class='searchresults'>
194 foreach ($hits_by_object as $object => $score) {
195 list($item, $id) = explode(':', $object, 2);
196 $obj = $objects[$object];
197 $score = (int)($score * 100);
199 $html = "<tr><td valign='right'>$score%</td><td>";
203 $tkt = MTrackIssue::loadByNSIdent($id);
205 $tkt = MTrackIssue::loadById($id);
207 $aclid = "ticket:" . $tkt->tid;
208 $html .= mtrack_ticket($tkt);
210 $url = "{$ABSWEB}ticket.php/$tkt->nsident";
212 $url = "{$ABSWEB}ticket.php/$id";
214 $html .= " <a href='$url'>";
215 $html .= htmlentities($tkt->summary, ENT_QUOTES, 'utf-8');
217 $html .= $obj->getExcerpt($tkt->description);
221 $wiki = new MTrack_Wiki_Item($id);
223 $url = "{$ABSWEB}wiki.php/$id";
224 $html .= "<a href='$url'>".
225 htmlentities($id, ENT_QUOTES, 'utf-8').
227 $html .= $obj->getExcerpt($wiki->content);
234 if (!MTrackACL::hasAnyRights($aclid, 'read')) {
239 $html .= "</td></tr>\n";
244 if (!count($hits_by_object)) {
245 echo "<em>No matches</em>";
247 echo "<em>" . count($hits_by_object) . " results in $elapsed</em>\n";
250 echo "<br>Denied access to $denied items<br>\n";