Josh, Looks useful. If you wouldn't mind, could you submit a ticket with a patch and I'll take a look at incorporating.
Thanks, Chris On Fri, Jan 7, 2011 at 5:53 PM, Josh <[email protected]> wrote: > In base.html I opted to use satchmo_category_search_form rather than > satchmo_search_form to allow users to search on a per category basis. > I noticed a bug which is that if you select a category other than all > products and click search with an empty search box you get an error > rather than no results. So I dove into the code (search.py) and fixed > it by adding a check that if keywords is empty it should immediately > return with results as none. I also made it so that quoted strings > are preserved in search terms i.e. putting: > just a "test string" > in the search box would produce the following search keywords: > ['test string', 'just', 'a'] > rather than > ['just', 'a', '"test', 'string"'] > Allowing for searching for exact phrases. > > I realize that it reorders the terms but I don't think this matters. > Anyways here is what I changed. In search_view (satchmo_store/shop/ > views/search.py) I replaced: > > keywords = data.get('keywords', '').split(' ') > category = data.get('category', None) > > keywords = filter(None, keywords) > > results = {} > > with: > > keywords = " ".join(data.get('keywords', '').split()).split('"') > if keywords == ['']: #thats two single quotes, not a > double quote > category = data.get('category', None) > context = RequestContext(request, { > 'results': None, > 'category' : category, > 'keywords' : keywords}) > return render_to_response(template, context_instance=context) > keywords = ["" + t.strip(punctuation) > for t in keywords[1::2] + "".join(keywords[::2]).split()] > category = data.get('category', None) > > keywords = filter(None, keywords) > > results = {} > > The code that allows for quoted strings is based on the same thing in > mezzanine, a django cms. > > Feel free to include this in satchmo, or improve upon it or whatever. > Another option would be to use shlex.split() rather than just split > but apparently it doesn't play nice with unicode characters so I > figured it wasn't the best option. > > Josh > > -- > You received this message because you are subscribed to the Google Groups > "Satchmo users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<satchmo-users%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/satchmo-users?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Satchmo users" 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/satchmo-users?hl=en.
