Exemplo n.º 1
0
WebPage* SearchEng::looks_for_webpage(std::string filename) {
	for(MySetWebPage::iterator it = allPages.begin();it != allPages.end(); ++it) {
		WebPage* tempPage = *it;
		if( tempPage->filename() == filename) {
			return *it;
		}
	}
		WebPage* newPage = new WebPage;
		newPage->filename(filename);
		allPages.insert(newPage);
		return newPage;
}
Exemplo n.º 2
0
bool
WebPage::operator== (const WebPage & web)
{

  return fname == web.filename ();	//check if they have the same filename

}
Exemplo n.º 3
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;
			  }
Exemplo n.º 4
0
WebPage
WebPage::operator< (const WebPage & w)
{

  if (filename () < w.filename ())	//compare webpages by their filenames
    return *this;
  else
    return w;


}
Exemplo n.º 5
0
void MainWin::search(){
	results->clear();

	string input =  txtSearch->text().toStdString();

    for(int j = 0; input[j]; j++){    //converts to lower case and checks for valid input
    	if(input[j] != ' ' && !isalnum(input[j])){
			QMessageBox *message = new QMessageBox;
			message->setWindowTitle("Error!");
			message->setText("Invalid search. \nIs your input alphanumeric?");
			message->show();
			return void();
		}
		else
    	input[j] = tolower(input[j]);
    }
    try{
    	Set<WebPage*> result;
    	char cinput[input.size()+1];
        strcpy(cinput, input.c_str());	//convert to char* to tokenize
        char* cword1 = strtok(cinput," ");	//extract first word
        string word1(cword1);		//convert char* to string to trim and input into set
        trim(word1);
        Set<WebPage*> and1 = words.at(word1);
        result = and1; 

    	if(btnAnd->isChecked()){
        	cword1 = strtok(NULL," ");	//could just do ", " to get rid of leading white space
        	while(cword1!=NULL){		//but i already made the trim function so too bad
        		string word2(cword1);	//essentially doing what I did above
        		trim(word2);
        		Set<WebPage*> and2 = words.at(word2);
        		result = and1.setIntersection(and2);	//check for intersections
        		Set<WebPage*> and1 = result;		//*** resets and1 to be result thus and2 will check for 
        		cword1 = strtok(NULL," ");		//an intersection of previous words
        	}
    	}

    	else if (btnOr->isChecked()){
			cword1 = strtok(NULL," ");	//could just do ", " to get rid of leading white space
        	while(cword1!=NULL){		//but i already made the trim function so too bad
        		string word2(cword1);
        		trim(word2);
        		Set<WebPage*> and2 = words.at(word2);
        		result = and1.setUnion(and2);
        		Set<WebPage*> and1 = result;
        		cword1 = strtok(NULL," ");	
    		}
    	}

    	if(result.size() == 0){
			QMessageBox *message = new QMessageBox;
			message->setWindowTitle("Error!");
			message->setText("No search results.");
			message->show();
    	}
   	 	else{
    		for(Set<WebPage*>::iterator it = result.begin(); it != result.end(); ++it){
    			WebPage* wp = *it;
    			results->addItem(QString::fromStdString(wp->filename()));
    		}
    	}
	}
	catch(logic_error &e){
		QMessageBox *message = new QMessageBox;
		message->setWindowTitle("Error!");
		message->setText("No search results.");
		message->show();
	}
}