Exemple #1
0
int _tmain(int argc, _TCHAR* argv[])
{ 
	welcomeMessage();
	
	SearchInput SearchObject;
	vector <string> SearchValues = SearchObject.processSearchInput();

	setVerbose();
	cout << endl;

	DirExplorer explore; // Open the directory
	cout << endl;
	cout << " Opening the directory... " << endl;
	vector<string> FileList = explore.getFilePaths(); // Get the names of the files from the directory 
	if (verbose) // Verbose used to indicate whether to show the next piece of code or not 
	{
		cout << "Printing the list of files found.. " << endl;
		Print(FileList);
	}

	std::vector<FileReader*> p; 
	FileReader* file;
	vector<Word> SplittedWords;
	vector<Word*> Results; 
	vector<Line> Sentences;
	Search mySearch;
	myLine.clear();
	MatchedResults.clear();
	int results = 0;
	int totalresult = 0;
	cout << " Reading and storing the matching results... " << endl;
	for ( size_t n = 0; n < FileList.size(); n++ ) // loop through the list of files in the directory 
    {
		string filename = FileList[ n ]; 
		file = new FileReader(filename);
		if ( (file->open()) != true ) // open a single file 
		{
			return false;
		}
		else
		{
			file->split(SearchValues); // split the file's content into words and store in a vector of objects 
			file->clearFile(); // clear the file's EOF flag once done with reading 
		}

	   // create Search object
		
		mySearch.SearchForMatch(SearchValues);
		results = mySearch.getResults();
		totalresult = totalresult + results;

	   p.push_back( file );		
    }
		
	if( SearchValues.size() == 1 ) // simple query
	{
		cout << " Scoring.. " << endl;
		mySearch.scoreByFrequency();
		sortData();
		cout << "/**                               RESULTS                               **/\n";
		cout << "/*----------------------------------------------------------------------**/\n";
		cout << "  Total Results: " << totalresult << "\n" << endl;
		displayResults1(); //Display the sorted array
	}
	else // composed query
	{
		cout << " Scoring.. " << endl;
		string st1 = "and";
		string st2 = "or";
		string stype = searchType;
		if ( st1.compare(stype) == 0 )
		{
			if(verbose)
			cout << "Search is of type AND" << endl;
			mySearch.scoreByDistance();
			sortData();
			cout << "/**                               RESULTS                               **/\n";
			cout << "/*----------------------------------------------------------------------**/\n";
			cout << "/**  Total Results: " << totalresult << "\n" << endl;
			displayResults2(); 
		}
		if ( st2.compare(stype) == 0 )
		{
			if(verbose)
			cout << "Search is of type OR" << endl;

			mySearch.scoreByFrequency();
			sortData();
			cout << "/**                               RESULTS                               **/\n";
			cout << "/*----------------------------------------------------------------------**/\n";
			cout << "  Total Results: " << totalresult << "\n" << endl;
			displayResults1(); //Display the sorted array
		}
		//score by frequency plus distance
	}
	

	MatchedResults.clear();
	/* Close all files */
	for ( size_t i = 0; i < p.size(); i++ )
    {
		p[i]->close();
    }
	/* Close the directory */
	cout << endl;
	explore.closeDir();


    _getch();
	return 0;
}