def before_search(self, search_params): search_string = search_params.get("q") or "" # for search cloud we don't make any changes to the search_params, # just log the search string to the database for later analysis. # do some clean up of the search string so that the analysis # will be easier later search_string = searchcloud.unify_terms(search_string, max_length=200) if not search_string: return search_params lang = str(helpers.current_locale()) try: # Unfortunately a nested session doesn't behave the way we want, # failing to actually commit the change made. # We can either create a separate connection for this # functionality on each request (potentially costly), # or just commit at this point on the basis that for a search # request, no changes that can't be committed will have been # saved to the database. For now, we choose the latter. ## model.Session.begin_nested() # establish a savepoint searchcloud.track_term(model.Session, lang, search_string) except sqlalchemy.exc.ProgrammingError, e: # We don't want the non-existence of the search_query table to # crash searches, we just won't log queries log.error(e) if 'relation "search_query" does not exist' in str(e): log.error( "Please run the paster searchcloud-install-tables " "command to set up the correct tables for " "search logging" ) model.Session.rollback() else: raise
def test_07_searches_are_made_uniform_correctly(self): #How should capitalization be taken into account? In the search itself? for search_string, expected in ( # Simple case ['One Two', 'One Two'], # Leading and trailing space [' One Two ', 'One Two'], # Multiple spaces in words ['One Two Three', 'One Two Three'], # Over max length (one long word) ['One_Two_Three_Four', 'One_Two_Three_Fo'], # Over max length (multiple words) ['One Two Three Four', 'One Two Three'], ): self.assert_equal( searchcloud.unify_terms(search_string, max_length=16), expected )