#3998: boulder-oracle single char wildcard search issue
---------------------------------------+------------------------------------
          Reporter:  bouldersprinters  |         Owner:  adrian          
            Status:  new               |     Component:  Database wrapper
           Version:  other branch      |      Keywords:                  
             Stage:  Unreviewed        |     Has_patch:  0               
        Needs_docs:  0                 |   Needs_tests:  0               
Needs_better_patch:  0                 |  
---------------------------------------+------------------------------------
 I'm trying to implement a search feature in Django where a user can enter
 something like[[BR]]
 
 
 PC-3[[BR]]
 
 
 and the search will return matches with or without punctuation, case
 insensitive[[BR]]
 
 
 results:   PC-3, pc3, BxPC3, Pc 3[[BR]]
 
 
 I've figured out how to do this so I'm getting all of the results above,
 but the only thing that's missing is the "Pc 3" result. It seems that when
 I do an Oracle search using "_" as a single-char wildcard, it doesn't
 consider a "space" to match that wildcard.
 
 The query that is generated:
 
 {{{
 
 SELECT DISTINCT "CRYOINV_WELL"."CELL_LINE"
  FROM "CRYOINV_WELL"
  WHERE ((UPPER("CRYOINV_WELL"."CELL_LINE") LIKE UPPER('%PC-3%')
  OR UPPER("CRYOINV_WELL"."CELL_LINE") LIKE UPPER('%PC\\_3%')
  OR UPPER("CRYOINV_WELL"."CELL_LINE") LIKE UPPER('%PC3%')));
 }}}
 
 
 The problem is the double backslash that's put into the query on line 4.
 
 Here's some code snippets:
 
 models.py:
 
 
 {{{
 class Well(models.Model):
   box = models.ForeignKey(Box, edit_inline=models.TABULAR,
 num_in_admin=18)
   well_name = models.CharField(maxlength=20, core=True)
   cell_line = models.CharField(maxlength=250, null=True, blank=True)
 }}}
 
 
 views.py:
 
 
 {{{
 def search(request):
 
   WellFormClass = forms.form_for_model(Well)
   WellFormClass.base_fields['box'].widget = widgets.HiddenInput()
   WellFormClass.base_fields['well_name'].widget = widgets.HiddenInput()
 
   if request.GET:
     query = request.GET.get("cell_line", "")
     # Do a "liberal" search first
     # Search for:    PC-3
     # Returned results:   PC-3, pc3, BxPC3, pc 3
 
     # replace any punctuation in the query with a '_'
     # *** for some reason ignoring the space?
     punc_trans = string.maketrans(' -:;', '____')
     modQuery1 = query.translate(punc_trans)
     # parse out any punctuation at all
     no_trans = string.maketrans('', '')
     modQuery2 = query.translate(no_trans, '-:; ')
     # now search for any of these combinations
     results = Well.objects.filter(Q(cell_line__icontains=query) |
                                   Q(cell_line__icontains=modQuery1) |
 Q(cell_line__icontains=modQuery2)).values("cell_line").distinct()
 
     results = list(results)
     return render_to_response('cryoInv/cell_line_search_results.html',
                               {"results": results,"query": query})
   else:
     form = WellFormClass()
 
   return render_to_response('cryoInv/search.html', {'form': form})
 
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/3998>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to