def get(self): create_url = self.get_url( '/create', ui='' if self.env.ui == 'small' else self.env.ui, role=self.params.role, given_name=self.params.given_name, family_name=self.params.family_name) min_query_word_length = self.config.min_query_word_length third_party_search_engines = [] for i, search_engine in enumerate( self.config.third_party_search_engines or []): third_party_search_engines.append( {'id': i, 'name': search_engine.get('name', '')}) if self.params.role == 'provide': # The order of family name and given name does matter (see the # scoring function in indexing.py). query_txt = get_full_name( self.params.given_name, self.params.family_name, self.config) query = TextQuery(query_txt) results_url = self.get_results_url(query_txt) # Ensure that required parameters are present. if not self.params.given_name: return self.reject_query(query) if self.config.use_family_name and not self.params.family_name: return self.reject_query(query) if (len(query.query_words) == 0 or max(map(len, query.query_words)) < min_query_word_length): return self.reject_query(query) # Look for *similar* names, not prefix matches. # Eyalf: we need to full query string # for key in criteria: # criteria[key] = criteria[key][:3] # "similar" = same first 3 letters results = self.search(query) # Filter out results with addresses matching part of the query. results = [result for result in results if not getattr(result, 'is_address_match', False)] if results: # Perhaps the person you wanted to report has already been # reported? return self.render('results.html', results=results, num_results=len(results), has_possible_duplicates= has_possible_duplicates(results), results_url=results_url, create_url=create_url, third_party_search_engines= third_party_search_engines, query=self.params.query) else: if self.env.ui == 'small': # show a link to a create page. return self.render('small-create.html', create_url=create_url) else: # No matches; proceed to create a new record. logging.info(repr(self.params.__dict__)) return self.redirect('/create', **self.params.__dict__) if self.params.role == 'seek': query = TextQuery(self.params.query) # If a query looks like a phone number, show the user a result # of looking up the number in the carriers-provided BBS system. if self.config.jp_mobile_carrier_redirect: if jp_mobile_carriers.handle_phone_number(self, query.query): return if is_possible_phone_number(query.query): # If the query looks like a phone number, we show an empty # result page instead of rejecting it. We don't support # search by phone numbers, but third party search engines # may support it. results = [] results_url = None third_party_query_type = 'tel' elif (len(query.query_words) == 0 or max(map(len, query.query_words)) < min_query_word_length): logging.info('rejecting %s' % query.query) return self.reject_query(query) else: # Look for prefix matches. results = self.search(query) results_url = self.get_results_url(self.params.query) third_party_query_type = '' # Show the (possibly empty) matches. return self.render('results.html', results=results, num_results=len(results), has_possible_duplicates= has_possible_duplicates(results), results_url=results_url, create_url=create_url, third_party_search_engines= third_party_search_engines, query=self.params.query, third_party_query_type=third_party_query_type)
def get(self): create_url = self.get_url( '/create', ui='' if self.env.ui == 'small' else self.env.ui, role=self.params.role, given_name=self.params.given_name, family_name=self.params.family_name) min_query_word_length = self.config.min_query_word_length third_party_search_engines = [] for i, search_engine in enumerate( self.config.third_party_search_engines or []): third_party_search_engines.append({ 'id': i, 'name': search_engine.get('name', '') }) if self.params.role == 'provide': # The order of family name and given name does matter (see the # scoring function in indexing.py). query_txt = get_full_name(self.params.given_name, self.params.family_name, self.config) query = TextQuery(query_txt) results_url = self.get_results_url(query_txt, '') # Ensure that required parameters are present. if not self.params.given_name: return self.reject_query(query) if self.config.use_family_name and not self.params.family_name: return self.reject_query(query) if (len(query.query_words) == 0 or max_word_length( query.query_words) < min_query_word_length): return self.reject_query(query) # Look for *similar* names, not prefix matches. # Eyalf: we need to full query string # for key in criteria: # criteria[key] = criteria[key][:3] # "similar" = same first 3 letters results = self.search({'name': query_txt}) # Filter out results with addresses matching part of the query. results = [ result for result in results if not getattr(result, 'is_address_match', False) ] if results: # Perhaps the person you wanted to report has already been # reported? return self.render( 'results.html', results=results, num_results=len(results), has_possible_duplicates=has_possible_duplicates(results), results_url=results_url, create_url=create_url, third_party_search_engines=third_party_search_engines, query_name=self.params.query_name, query_location=self.params.query_location, ) else: if self.env.ui == 'small': # show a link to a create page. return self.render('small-create.html', create_url=create_url) else: # No matches; proceed to create a new record. logging.info(repr(self.params.__dict__)) return self.redirect('/create', **self.params.__dict__) if self.params.role == 'seek': query_dict = { 'name': self.params.query_name, 'location': self.params.query_location } self.params.query = " ".join(q for q in query_dict.values() if q) query = TextQuery(self.params.query) results_based_on_input = True # If a query looks like a phone number, show the user a result # of looking up the number in the carriers-provided BBS system. if self.config.jp_mobile_carrier_redirect: try: if jp_mobile_carriers.handle_phone_number( self, query.query): return except Exception as e: logging.exception( 'failed to scrape search result for the phone number.') return self.error( 500, _('Failed to obtain search result ' 'for the phone number.')) if is_possible_phone_number(query.query): # If the query looks like a phone number, we show an empty # result page instead of rejecting it. We don't support # search by phone numbers, but third party search engines # may support it. results = [] results_url = None third_party_query_type = 'tel' elif (len(query.query_words) == 0 or max_word_length(query.query_words) < min_query_word_length): logging.info('rejecting %s' % query.query) return self.reject_query(query) else: # Look for prefix matches. results = self.search(query_dict) results_url = self.get_results_url(self.params.query_name, self.params.query_location) third_party_query_type = '' query_location = self.params.query_location # If there is no results match for both name and location # Check if there have results match for name if not results: if self.params.query_location: query_dict = { 'name': self.params.query_name, 'location': '' } results = self.search(query_dict) # search result not based on the user input results_based_on_input = False query_location = '' # Show the (possibly empty) matches. return self.render( 'results.html', results=results, num_results=len(results), has_possible_duplicates=has_possible_duplicates(results), results_url=results_url, create_url=create_url, third_party_search_engines=third_party_search_engines, query_name=self.params.query_name, query_location_original=self.params.query_location, query_location=query_location, third_party_query_type=third_party_query_type, results_based_on_input=results_based_on_input)
def get(self): params = { 'role': self.params.role, 'given_name': self.params.given_name, 'family_name': self.params.family_name, } # Links to the default UI from the small UI. Otherwise preserves "ui" # param of the current page. Note that get_url() preserves "ui" param # by default (i.e., when it's not specified in +params+). if self.env.ui == 'small': params['ui'] = None create_url = self.get_url('/create', **params) min_query_word_length = self.config.min_query_word_length third_party_search_engines = [] for i, search_engine in enumerate( self.config.third_party_search_engines or []): third_party_search_engines.append({ 'id': i, 'name': search_engine.get('name', '') }) if self.params.role == 'provide': # The order of family name and given name does matter (see the # scoring function in indexing.py). query_txt = get_full_name(self.params.given_name, self.params.family_name, self.config) query = TextQuery(query_txt) results_url = self.get_results_url(query_txt, '') # Ensure that required parameters are present. if not self.params.given_name: return self.reject_query(query) if self.config.use_family_name and not self.params.family_name: return self.reject_query(query) if (len(query.query_words) == 0 or max_word_length( query.query_words) < min_query_word_length): return self.reject_query(query) # Look for *similar* names, not prefix matches. # Eyalf: we need to full query string # for key in criteria: # criteria[key] = criteria[key][:3] # "similar" = same first 3 letters results = self.search({'name': query_txt}) # Filter out results with addresses matching part of the query. results = [ result for result in results if not getattr(result, 'is_address_match', False) ] if results: # Perhaps the person you wanted to report has already been # reported? return self.render( 'results.html', results=results, num_results=len(results), has_possible_duplicates=has_possible_duplicates(results), results_url=results_url, create_url=create_url, third_party_search_engines=third_party_search_engines, query_name=self.get_query_value(), query_location=self.params.query_location, ) else: if self.env.ui == 'small': # show a link to a create page. return self.render('small-create.html', create_url=create_url) else: # No matches; proceed to create a new record. return self.redirect(create_url) if self.params.role == 'seek': # The query_name parameter was previously called "query", and we # continue to support it for third-parties that link directly to # search results pages. query_name = self.get_query_value() query_dict = { 'name': query_name, 'location': self.params.query_location } query = TextQuery(" ".join(q for q in query_dict.values() if q)) results_based_on_input = True # If a query looks like a phone number, show the user a result # of looking up the number in the carriers-provided BBS system. if self.config.jp_mobile_carrier_redirect: try: if jp_mobile_carriers.handle_phone_number( self, query.query): return except Exception as e: logging.exception( 'failed to scrape search result for the phone number.') return self.error( # Translators: An error message indicating that we # failed to obtain search result for the phone number # given by the user. 500, _('Failed to obtain search result ' 'for the phone number.')) if is_possible_phone_number(query.query): # If the query looks like a phone number, we show an empty # result page instead of rejecting it. We don't support # search by phone numbers, but third party search engines # may support it. results = [] results_url = None third_party_query_type = 'tel' elif (len(query.query_words) == 0 or max_word_length(query.query_words) < min_query_word_length): logging.info('rejecting %s' % query.query) return self.reject_query(query) else: # Look for prefix matches. results = self.search(query_dict) results_url = self.get_results_url(query_name, self.params.query_location) third_party_query_type = '' # If there is no results match for both name and location # Check if there have results match for name if not results: if self.params.query_location: query_dict = {'name': query_name, 'location': ''} results = self.search(query_dict) # search result not based on the user input results_based_on_input = False concatenated_query = (( '%s %s' % (query_name, self.params.query_location)).strip()) # Show the (possibly empty) matches. return self.render( 'results.html', results=results, num_results=len(results), has_possible_duplicates=has_possible_duplicates(results), results_url=results_url, create_url=create_url, third_party_search_engines=third_party_search_engines, query_name=query_name, query=concatenated_query, third_party_query_type=third_party_query_type, results_based_on_input=results_based_on_input)
def get(self): params = { 'role': self.params.role, 'given_name': self.params.given_name, 'family_name': self.params.family_name, } # Links to the default UI from the small UI. Otherwise preserves "ui" # param of the current page. Note that get_url() preserves "ui" param # by default (i.e., when it's not specified in +params+). if self.env.ui == 'small': params['ui'] = None create_url = self.get_url('/create', **params) min_query_word_length = self.config.min_query_word_length third_party_search_engines = [] for i, search_engine in enumerate( self.config.third_party_search_engines or []): third_party_search_engines.append( {'id': i, 'name': search_engine.get('name', '')}) if self.params.role == 'provide': # The order of family name and given name does matter (see the # scoring function in indexing.py). query_txt = get_full_name( self.params.given_name, self.params.family_name, self.config) query = TextQuery(query_txt) results_url = self.get_results_url(query_txt, '') # Ensure that required parameters are present. if not self.params.given_name: return self.reject_query(query) if self.config.use_family_name and not self.params.family_name: return self.reject_query(query) if (len(query.query_words) == 0 or max_word_length(query.query_words) < min_query_word_length): return self.reject_query(query) # Look for *similar* names, not prefix matches. # Eyalf: we need to full query string # for key in criteria: # criteria[key] = criteria[key][:3] # "similar" = same first 3 letters results = self.search({'name':query_txt}) # Filter out results with addresses matching part of the query. results = [result for result in results if not getattr(result, 'is_address_match', False)] if results: # Perhaps the person you wanted to report has already been # reported? return self.render( 'results.html', results=results, num_results=len(results), has_possible_duplicates= has_possible_duplicates(results), results_url=results_url, create_url=create_url, third_party_search_engines= third_party_search_engines, query_name=self.get_query_value(), query_location=self.params.query_location,) else: if self.env.ui == 'small': # show a link to a create page. return self.render('small-create.html', create_url=create_url) else: # No matches; proceed to create a new record. return self.redirect(create_url) if self.params.role == 'seek': # The query_name parameter was previously called "query", and we # continue to support it for third-parties that link directly to # search results pages. query_name = self.get_query_value() query_dict = {'name': query_name, 'location': self.params.query_location} query = TextQuery(" ".join(q for q in query_dict.values() if q)) results_based_on_input = True # If a query looks like a phone number, show the user a result # of looking up the number in the carriers-provided BBS system. if self.config.jp_mobile_carrier_redirect: try: if jp_mobile_carriers.handle_phone_number( self, query.query): return except Exception as e: logging.exception( 'failed to scrape search result for the phone number.') return self.error( # Translators: An error message indicating that we # failed to obtain search result for the phone number # given by the user. 500, _('Failed to obtain search result ' 'for the phone number.')) if is_possible_phone_number(query.query): # If the query looks like a phone number, we show an empty # result page instead of rejecting it. We don't support # search by phone numbers, but third party search engines # may support it. results = [] results_url = None third_party_query_type = 'tel' elif (len(query.query_words) == 0 or max_word_length(query.query_words) < min_query_word_length): logging.info('rejecting %s' % query.query) return self.reject_query(query) else: # Look for prefix matches. results = self.search(query_dict) results_url = self.get_results_url(query_name, self.params.query_location) third_party_query_type = '' # If there is no results match for both name and location # Check if there have results match for name if not results: if self.params.query_location: query_dict = {'name': query_name, 'location': ''} results = self.search(query_dict) # search result not based on the user input results_based_on_input = False concatenated_query = ( ('%s %s' % (query_name, self.params.query_location)) .strip()) # Show the (possibly empty) matches. return self.render('results.html', results=results, num_results=len(results), has_possible_duplicates= has_possible_duplicates(results), results_url=results_url, create_url=create_url, third_party_search_engines= third_party_search_engines, query_name=query_name, query=concatenated_query, third_party_query_type=third_party_query_type, results_based_on_input=results_based_on_input)