From: gfawcett Date: Fri, 3 Apr 2009 01:30:52 +0000 (+0000) Subject: search-box now handles barcode and short-number searches. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=0fb586b397a9ce56abcfc9047c1a012d4f37e421;p=syrup%2Fmasslnc.git search-box now handles barcode and short-number searches. Well, sort of. I'm using Item ID for 'short-number' right now, and that's not quite correct. Barcode searches are correct, though. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@244 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- diff --git a/conifer/TODO b/conifer/TODO new file mode 100644 index 0000000..7ed6d55 --- /dev/null +++ b/conifer/TODO @@ -0,0 +1,7 @@ +* a short-number for physical items. Sort of a barcode, but intended + for easier communicatinon between patrons and staff. + + * Update views.search() when this is in place. + +* ... + diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index 7209447..f6e53d6 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -401,6 +401,10 @@ class Item(m.Model): creators = self.metadata_set.filter(name='dc:creator') return creators and creators[0].value or None + def barcode(self): + bc = self.metadata_set.filter(name='syrup:barcode') + return bc and bc[0].value or None + def author_hl(self, terms): hl_author = self.author() diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index 08c8fa3..d293340 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -843,7 +843,6 @@ def search(request, in_course=None): - page through item entries If in_course is provided, then limit search to the contents of the specified course. ''' - query_string = '' found_entries = None page_num = int(request.GET.get('page', 1)) count = int(request.GET.get('count', 5)) @@ -859,22 +858,36 @@ def search(request, in_course=None): if len(query_string) > 0: norm_query = normalize_query(query_string) + # we start with an empty results_list, as a default + results_list = models.Item.objects.filter(pk=-1) + + # numeric search: If the query-string is a single number, then + # we do an item-ID search, or a barcode search. fixme: + # item-ID is not a good short-id, since the physical item may + # be represented in multiple Item records. We need a + # short-number for barcodes. + + if re.match(r'\d+', query_string): + # Search by short ID. + results_list = models.Item.objects.filter(pk=query_string, + item_type='PHYS') + if not results_list: + # Search by barcode. + results_list = models.Item.objects.filter( + item_type='PHYS', + metadata__name='syrup:barcode', + metadata__value=query_string) + else: + # Textual (non-numeric) queries. + item_query = get_query(query_string, ['title', 'metadata__value']) + #need to think about sort order here, probably better by author (will make sortable at display level) + results_list = models.Item.objects.filter(item_query) - #item search - this will be expanded - - # fixme, when moving author to the Metadata table, we can no - # longer do a straight search on author. Using - # 'metadata__value' sort of works, but also searches other - # metadata fields. - - item_query = get_query(query_string, ['title', 'metadata__value']) - #need to think about sort order here, probably better by author (will make sortable at display level) - results_list = models.Item.objects.filter(item_query).order_by('title') if in_course: results_list = results_list.filter(course=in_course) + results_list = results_list.order_by('title') results_len = len(results_list) - paginator = Paginator( results_list, - count) + paginator = Paginator(results_list, count) #course search if in_course: diff --git a/conifer/templates/search_results.xhtml b/conifer/templates/search_results.xhtml index 20dcc12..32aa2d8 100644 --- a/conifer/templates/search_results.xhtml +++ b/conifer/templates/search_results.xhtml @@ -74,6 +74,7 @@ courses = course_list ${Markup(item.author_hl(norm_query))} ${Markup(item.title_hl(norm_query))} ${item.course.title} + ${item.id} • ${item.barcode()} ${pagetable(paginator, count, pagerow, pageheader)}