Пример #1
0
def search():
    """
    Renders the search results page.
    """
    context = helpers.get_context(request)
    dbconnection = database.DatabaseConnection()
    dbconnection.connect()
    if context.get('query'):
        query_index = database.build_mongo_index_query(input=context['query'])
        #flash('query: '+str(mongo_query), category='text-info')
        context['query_index'] = query_index
        if query_index != None:
            cursor, cursor_count = database.query_mongo(query=query_index, collection=settings.COLLECTION_INDEX, db=dbconnection)
            context['cursor'] = cursor
            context['cursor_count'] = cursor_count
            query_pages, query_pages_hits = database.build_mongo_pages_query(input=cursor)
            if (query_pages_hits != {}):
                context['query_pages'] = query_pages
                context['query_pages_hits'] = query_pages_hits
                documents, documents_count = database.query_mongo(query=query_pages, collection=settings.COLLECTION_DOCUMENTS, db=dbconnection, sort=context['sort'], number_of_results=context['results'], order=context['order'])
                context['documents'] = documents
                context['documents_count'] = documents_count
                if(context['documents_count'] == 0):
                    no_results()
            else:
                no_results()
        else:
            no_results()
    return render_template("search.html", context=context)
Пример #2
0
 def test_building_a_one_word_mongo_pages_query(self):
     """
     Tests if a one word search will build the proper mongo pages query.
     """
     self.test_input_cursor = {'word1': {'url1':[9], 'url2':[1], 'url3':[1,3,4], 'url4':[6]}}
     self.expected_output = {'$or':[{'url':'url4'},{'url':'url1'},{'url':'url3'},{'url':'url2'}]}
     self.expected_hits = {'url1':[9], 'url2':[1], 'url3':[1,3,4], 'url4':[6]}
     self.result, self.hits = database.build_mongo_pages_query(input=self.test_input_cursor)
     self.assertEqual(self.result, self.expected_output), "Building a page query for a one word search is broken."
     self.assertEqual(self.hits, self.expected_hits), "Building a page word hits list for a one word search is broken."