commit 97b582fcae07c5e039075aeea1b85c5a857adb39
parent dd331d891bc654e5cc36b26df530b7c959f73b57
Author: Felicitus <felicitus@felicitus.org>
Date: Thu, 13 Jun 2013 15:28:41 +0200
Added support for searching parts by their internal ID. The search syntax is id:<number>, e.g. id:1234
Note that combining the id search with regular search expressions might not give the expected results; this is due to the "hackish" nature of this filter. This will probably be fixed when we got proper search support by lucene or such.
Diffstat:
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/backend/PartKeepr/Part/PartService.php b/src/backend/PartKeepr/Part/PartService.php
@@ -36,10 +36,26 @@ class PartService extends Service implements RestfulService {
*/
if ($this->hasParameter("query") && $this->getParameter("query") != "") {
+ // Special case: If the user passes id:<number>, we retrieve that number only.
+ // This is
+
+ $additionalResults = array();
+
+ $regExp = "id:[0-9]+";
+ if (preg_match_all("/id:[0-9]+/", $this->getParameter("query"), $pregResults) === 1) {
+ foreach ($pregResults as $match) {
+ foreach ($match as $result) {
+ $additionalResults[] = str_replace("id:", "", $result);
+ }
+ }
+ }
+
$fulltextSearch = new PartFulltextSearch($this->getParameter("query"));
$fulltextSearchResults = $fulltextSearch->query();
-
- $queryBuilder->andWhere("q.id IN (".implode(",", $fulltextSearchResults).")");
+
+ $ids = array_merge($fulltextSearchResults, $additionalResults);
+
+ $queryBuilder->andWhere("q.id IN (".implode(",", $ids).")");
}