Exemplo n.º 1
0
void SearchEng::add_parse_page(std::string filename, 
		      PageParser* parser) {
				  
				MySetString currentWords;
				MySetString currentLinks_strings;
			  	parser->parse(filename, currentWords, currentLinks_strings);
				  std::cout << "Just ran parse" << std::endl;
				WebPage* currentPage = new WebPage;
						 
				currentPage->filename( filename );
				currentPage->all_words(currentWords);
				for( MySetString::iterator it = currentLinks_strings.begin(); it != currentLinks_strings.end(); ++it) {
					currentPage->add_outgoing_link(looks_for_webpage(*it));
					
					//Need to deal with links still
					
					/*MySetString::iterator it2 = allPages.find(*it);
					if(it2 != allPages.end() ) {
						currentPage->add_outgoing_link(it);
					}*/
				}
				allPages.insert(currentPage); 
				 // std::cout << "inserted page" << std::endl; //debug
				  MySetString::iterator it;
				for( it = currentWords.begin(); it != currentWords.end(); ++it ) { // makes wordMap;
					std::string word = *it;
					makeLower(word);
					std::map<std::string, MySetWebPage>::iterator it2 = wordMap.find(word);
					//std::cout << "trying to insert: " << word << std::endl; //debug
					if(it2 != wordMap.end()) {
						it2->second.insert(currentPage);
						//std::cout << "added page to " << it2->first << std::endl; //debug
					} else {
						MySetWebPage newSet;
						newSet.insert( currentPage );
						wordMap.insert( make_pair(word, newSet));
						//std::cout << "inserted: " << word << std::endl; //debug
					}
					//std::cout << "went through for loop" << std::endl; //debug
				}  
				
				//deals with all incoming links;
				MySetWebPage::iterator it3;
				for( it3 = allPages.begin(); it3!= allPages.end(); ++it3) {
					WebPage* outgoingPage = *it3;
					MySetWebPage outgoingLinks = outgoingPage->outgoing_links();
					
					MySetWebPage::iterator it4;
					for( it4 = outgoingLinks.begin(); it4 != outgoingLinks.end(); ++it4) {
						WebPage* incomingPage = *it4;
						incomingPage->add_incoming_link(outgoingPage);
					}
				}
				
				//delete currentPage;
				return;
			  }