View Issue Details

IDProjectCategoryView StatusLast Update
1003RackTablesdefaultpublic2013-10-05 23:29
ReporterJolrael Assigned Toadoom42  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Target Version0.20.6Fixed in Version0.20.6 
Summary1003: Search against 'dictionary' attributes
DescriptionIt would be great if a more extensive search could be added to racktables.

Currently you can use the search in the upper right corner, which searches a couple of object fields, and you can use the tag filter to either filter on tags, or filter on certain dictionary fields, but for the last one you need to know the field ID and value, or an object that has this value, so you can click on it.

Features that would be great to have added to a 'advanced search' page are:
- Searching through all attributes of an object (ie. if I search for 'R300', then all objects with 'HW type' set to 'Dell PowerEdge R300' will also show up)
- Search through specific attributes (ie. a select box that let's me select one or more attributes and define a search value for them (ie. let me search for all objects with 'Object type' set to server, fqdn set to '*.<a certain domain>', and the custom attribute 'role' containing 'database'.

I don't think the tag system is the right place to solve this, as you are required to have a double administration (ie. you need to both enter a value for a certain attribute, and select a tag that represents all possibilities one could need to search for, and if the tagging is forgotten or incomplete, you are missing certain results.
TagsNo tags attached.
Attached Files
racktables-search-dict.patch (1,822 bytes)   
--- a/wwwroot/inc/database.php
+++ b/wwwroot/inc/database.php
@@ -2994,22 +2994,26 @@ function getObjectAttrsSearchResults ($what)
 
 // Search stickers and return a list of pairs "object_id-attribute_id",
 // which matched. A partilar object_id could be returned more than once, if it has
-// multiple matching stickers. Search is only performed on "string" attributes.
+// multiple matching stickers. Search is only performed on "string" or "dict" attributes.
 function getStickerSearchResults ($tablename, $what)
 {
        $result = usePreparedSelectBlade
        (
-               'SELECT object_id, attr_id FROM AttributeValue AV ' .
+               'SELECT AV.object_id, AV.attr_id FROM AttributeValue AV ' .
                "INNER JOIN ${tablename} O ON AV.object_id = O.id " .
-               'WHERE string_value LIKE ? ORDER BY object_id',
-               array ("%${what}%")
+               'INNER JOIN Attribute A ON AV.attr_id = A.id ' .
+               'LEFT JOIN AttributeMap AM ON A.type = "dict" AND AV.object_tid = AM.objtype_id AND AV.attr_id = AM.attr_id ' .
+               'LEFT JOIN Dictionary D ON AM.chapter_id = D.chapter_id AND AV.uint_value = D.dict_key ' .
+               'WHERE string_value LIKE ? ' .
+               'OR (A.type = "dict" AND dict_value LIKE ?) ORDER BY object_id',
+               array ("%${what}%", "%${what}%")
        );
 
        $map = getAttrMap();
        $ret = array();
        while ($row = $result->fetch (PDO::FETCH_ASSOC))
        {
-               if ($map[$row['attr_id']]['type'] == 'string')
+               if (in_array($map[$row['attr_id']]['type'], array('string', 'dict')))
                {
                        $ret[$row['object_id']]['id'] = $row['object_id'];
                        $ret[$row['object_id']]['by_sticker'][] = $row['attr_id'];

racktables-search-dict.patch (1,822 bytes)   

Activities

Jolrael

Jolrael

2013-09-13 15:03

reporter   ~0001751

For the part 'Search through all attributes of an object' I wrote a small patch to include the possibility to search through dict field values of objects.

This is my first contribution to an open source project ever, so bear with me, and feel free to comment if something should be done differently ;-)
adoom42

adoom42

2013-10-05 23:29

administrator   ~0001813

Thanks for the patch. I renamed and closed this issue to reflect your first request, then opened a second issue to handle your second request.

Issue History

Date Modified Username Field Change
2013-09-04 08:10 Jolrael New Issue
2013-09-13 15:02 Jolrael File Added: racktables-search-dict.patch
2013-09-13 15:03 Jolrael Note Added: 0001751
2013-10-05 23:29 adoom42 Note Added: 0001813
2013-10-05 23:29 adoom42 Assigned To => adoom42
2013-10-05 23:29 adoom42 Status new => closed
2013-10-05 23:29 adoom42 Resolution open => fixed
2013-10-05 23:29 adoom42 Fixed in Version => 0.20.6
2013-10-05 23:29 adoom42 Target Version => 0.20.6
2013-10-05 23:29 adoom42 Summary More extensive search capability => Search against 'dictionary' attributes