def build_mongo_pages_query(input=None): """ Builds a mongo query to look up documents from the given cursor. """ result, hits = {}, {} result['$or'] = [] if len(input) > 1: for word in input: for url in input[word]: result['$or'].append({'url':url}) for word_number in input[word][url]: if hits.get(url): hits[url].append(word_number) else: hits[url] = [word_number] for key in hits: hits[key] = helpers.remove_duplicate_numbers(hits[key]) result['$or'] = helpers.remove_duplicate_dictionaries(result['$or']) else: for search_word in input: for url in input[search_word]: hits[url] = input[search_word][url] result['$or'].append({'url':url}) return result, hits
def test_remove_duplicate_numbers(self): """ Compares list with duplicate numbers to a known list of the distinct numbers values in the former list. """ self.input = [1,6,2,7,3,4,5,1,6,7,7,7,8] self.expected_output = [1,2,3,4,5,6,7,8] self.result = helpers.remove_duplicate_numbers(self.input) self.assertEqual(self.result, self.expected_output), "helpers.remove_duplicate_numbers is not removing duplicate numbers."