""" This module includes the SearchEngine class.  The heart of JMUahoogling. 

Author: 
Date:
"""

#-------------------------------------------------------------------
# This submission compiles with the JMU Honor Code. All code was written by the
# submitter, and no unauthorized assistance was used while completing this
# assignment.
#
# -YOUR NAME
#-------------------------------------------------------------------

import crawler_util

class SearchResult(object):
    """ This is a simple container class for storing search results 

    Public Attributes: 
       url -   A string containing the URL of an HTML document.
       title - A string containing the title of the HTML page. 
    """
    #YOU SHOULD NOT NEED TO MODIFY THIS CLASS.

    def __init__(self, url, title):
        """ Initialize the search result object. """
        self.url = url
        self.title = title

    def __eq__(self, rhs):
        """ Overide the == operator. 
        Search results are considered equal if they have the same url.
        """
        return type(self) == type(rhs) and self.url == rhs.url

    def __hash__(self):
        """ Return hash of search result. """
        return hash(self.url)


class SearchEngine(object):
    """
    The SearchEngine class is responsible for crawling some collection
    of HTML documents and creating an index that maps from words in
    those documents to SearchResult objects containing URLs and page
    titles.  This class also provides a method for searching the index
    once it is created.
    """

    def __init__(self):
        """ Construct a SearchEngine.  

        At the time of construction the index is empty. 
        """
        # YOUR CODE HERE You will (at least) need someplace to store
        # the search index (I suggest a dictionary) and some way of
        # keeping track of which URLs have already been crawled (I
        # suggest a set).

        pass # pass is a do-nothing instruction. It's just here because
             # it is a syntax error in Python to have an empty code block.
             # Replace it with good code. 
        
    def crawl(self, url, max_depth):
        """  Update the index by crawling a collection of HTML documents. 
        
        The crawl begins at url and will visit all pages within max_depth links.
        For example, if max_depth = 0, only the document located at the 
        indicated url is indexed. If max_depth = 2, the original document is 
        indexed, along with all documents that it links to and all of the 
        documents that THOSE documents link to.  This method tracks which URLs
        have already been visited so that no URL will be processed more than 
        once.
        
        Arguments: 
           url      -    A string containing a valid URL.  For example: 
                        "http://www.jmu.edu" or
                        "file:///home/spragunr/somefile.html"
           max_depth -   The maximum crawl depth.  See explanation above.
        
         No return value. 
        """
        # YOUR CODE HERE 
        pass
    
    def search(self, word):
        """  Return a list of SearchResult objects that match the given word. 
        
        This function returns a (possibly empty) list of SearchResult
        objects.  Each object refers to a document that contains
        the indicated word.  The search is NOT case sensitive.
        
        This method will accept any string, but assumes that the string
        represents a single word.  Since the index only stores individual 
        words, any strings with spaces or punctuation will necessarily 
        have 0 hits.
         
        Arguments:
          word - A string to search for in the search engine index.
          
          Return: A list of SearchResult objects.  The order of the
                  objects in the list is not specified.
        """
        #YOUR CODE HERE. 
        pass
    
    
    
if __name__ == "__main__":
    # TESTING CODE HERE. IF YOU WANT IT.
    pass
