Repository navigation
Expand file tree
/
Copy pathSearcher.cpp
More file actions
61 lines (57 loc) · 1.37 KB
/
Copy pathSearcher.cpp
File metadata and controls
61 lines (57 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <string>
#include "Searcher.h"
using std::string;
using std::cout;
using std::endl;
using std::cin;
using std::stringstream;
using std::istream;
using std::ifstream;
Searcher::Searcher(const string& inFile, List* aList,Mode* aMode){
anIndexList = aList;
this->fileName=inFile;
this->openMode=aMode;
}
int Searcher::search()const{
string word,line;
ifstream inputFile;
istream* in = &cin;
int numberOfWords;
//bool needToCloseFile=false;
//Si tengo un archivo intento abrirlo
if (this->fileName!=""){
inputFile.open(this->fileName.c_str());
//Si no lo pude abrir
if (!inputFile.good()){
return 1;
}else{
in = &inputFile;
//needToCloseFile=true;
}
}
//Leo archivo linea por linea
while ( (getline(*in,line)) && (line!="") ){
numberOfWords=0;
stringstream ss(line);
//para cada palabra
while ( ss >>word ){
numberOfWords++;
//marco las palabras en la lista que matchean a la busqueda
this->anIndexList->markWord(word);
}
List aList;
if (numberOfWords>1){
cout<<"busqueda:\""<<line<<"\""<<endl;
List inList;
this->anIndexList->fillList(&inList);
this->anIndexList->intersect(numberOfWords,&inList,&aList);
this->openMode->print(&aList);
this->anIndexList->unmarkAll();
}else{
cout << "busqueda:\""<<word<<"\""<<endl;
this->anIndexList->fill(word,&aList);
this->openMode->print(&aList);
}
}
return 0;
}