Patchwork [bitbake-devel,46/94] bitbake: webhob: extend search for multiple terms

login
register
mail settings
Submitter Alexandru DAMIAN
Date Sept. 24, 2013, 4:52 p.m.
Message ID <1292e652e0af307e1d2086402c09dd5789e00304.1380041477.git.alexandru.damian@intel.com>
Download mbox | patch
Permalink /patch/58771/
State New
Headers show

Comments

Alexandru DAMIAN - Sept. 24, 2013, 4:52 p.m.
From: Alexandru DAMIAN <alexandru.damian@intel.com>

We extend the search functionality as to be able to narrow
down search results based on multiple terms.

Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
---
 bitbake/lib/webhob/bldviewer/views.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Patch

diff --git a/bitbake/lib/webhob/bldviewer/views.py b/bitbake/lib/webhob/bldviewer/views.py
index a5c4387..4f7b46c 100644
--- a/bitbake/lib/webhob/bldviewer/views.py
+++ b/bitbake/lib/webhob/bldviewer/views.py
@@ -169,10 +169,13 @@  def _validate_input(input, model):
     return input, invalid
 
 def _get_search_results(search_term, queryset, model):
-    q_map = map(lambda x: Q(**{x+'__icontains': search_term}),
+    search_objects = []
+    for st in search_term.split(" "):
+        q_map = map(lambda x: Q(**{x+'__icontains': st}),
                 model.search_allowed_fields)
 
-    search_object = reduce(operator.or_, q_map)
+        search_objects.append(reduce(operator.or_, q_map))
+    search_object = reduce(operator.and_, search_objects)
     queryset = queryset.filter(search_object)
 
     return queryset