├── Generic_Problem_ReadME ├── Generic_Solution_README ├── README.md ├── Generic_Problem.txt ├── Mini_Search_Engine.cpp └── Generic_Solution.txt /Generic_Problem_ReadME: -------------------------------------------------------------------------------- 1 | This text file is similar to have all the webpages in the Internet. 2 | Whenever a search is made, it searches through the Generic_Problem.txt 3 | and finds the most relevant sentence based on our search and sorting 4 | technique. 5 | -------------------------------------------------------------------------------- /Generic_Solution_README: -------------------------------------------------------------------------------- 1 | This is the file where the flow of our code goes after the most relevant search is made 2 | and it pass the control to a mapped Specific Url which is available in "Generic_Solution.txt". 3 | And it opens the URL in the default browser. 4 | 5 | # I am using XCode so to Open the Browser we need to import to Frameworks - Core Foundation and ApplicationServices. 6 | # Windows User can use and Shell commands to open the URL in Windows Machine 7 | 8 | NOTE: Many URL's provided in the file are dummy and repeated URL's as it has been put in for Testing 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cplusplus-Project 2 | # Understanding Search Engine with C++ Program 3 | ## Search Engine: 4 | 5 | A general search engine is an Internet portal through which a person can search numerous compiled resources for topic-related information. Common general search engines include Google, Yahoo!, Alta Vista and Bing. To perform a search, the user enters a word or phrase. 6 | 7 | ## About: 8 | 9 | What a Search Engine basically does is, it finds a particular "Sentence and its related content" on a click and then it goes on backside, it searches each word in the query and its nearest related and relevant contents that is available in Internet among millions of Web Pages. Search Engines uses **Web crawling, Indexing and Searching** to find the particular "search" in Internet. Though the search is far more complex, 10 | 11 | [How Search works](https://www.google.com/search/howsearchworks/#!#jump-link) 12 | 13 | 14 | ## What to Learn: 15 | 16 | We will Understand the methods in C++ and how we have applied all the relevant topics from c++ in our code to make our "Mini Search Engine" of two Text File and how it searches through the hundreds of search elements for every "search" we make and gives our result. 17 | 18 | ## Analogy between "Search Engine" vs "Mini Search Engine": 19 | 20 | * Millions of Webpages == Two Text Documents 21 | * Input Field == Input stream of your IDE 22 | * Page Rank searching == Linear Searching 23 | * Sorting == Sorting most relevant at top 24 | * UnFound Match in WebPage == Add the Unfound Search into one text document 25 | * Found match - it opens all Relevant WebPages in Browser == Found Match - it Opens One Webpage in Browser 26 | 27 | 28 | ## Searching & Indexing Technique : 29 | 30 | ### GOOGLE SEARCH ENGINE: 31 | PageRank is technique used by Google Search Engine to Rank the Website based on the Number of incoming links to the website.Google Bot is used for Indexing the New Webpages and the process used is Crawling. 32 | 33 | ### MINI SEARCH ENGINE: 34 | Linear Search Technique is used to search through text files where more than 100 elements are available to search. Each of the Element is indexed and stored. When a search is made, all the relevant words searched through each element(a line) and gives out INDEX when maximum match of words in an element occurs.A match is not found then the particular is search is indexed and then added to the text file. 35 | 36 | ## Prerequisite : 37 | 38 | + XCode - Mac OS 39 | 40 | + Microsoft Visual Studio - Editor (optional) 41 | 42 | + Understanding of C++ and STL 43 | 44 | + Text-Editor 45 | 46 | ## NOTE : 47 | 48 | Code is expected to Return Exception and the Work is in Progress respectively 49 | 50 | 51 | -------------------------------------------------------------------------------- /Generic_Problem.txt: -------------------------------------------------------------------------------- 1 | 1. Problem with People 2 | 2. Money problems. 3 | 3. Roommates suck. 4 | 4. Credit card debt. 5 | 5. Other debt we didn't know existed until we had it. 6 | 6. Parents who don't understand us. 7 | 7. Friends who don't support us. 8 | 8. Having rent to pay every month. 9 | 9. Hating our jobs. 10 | 10. …Being unable to find a better job. 11 | 11. Deciding whether or not to go back to school because we can't find jobs. 12 | 12. Hangovers. 13 | 13. Trying to stay trendy. 14 | 14. Not realizing that being trendy is pointless… and expensive. 15 | 15. Not knowing what's going on in the world. 16 | 16. …Knowing Kanye's shoe size despite not knowing what’s going on in the world. 17 | 17. Not being able to eat healthy because it's too expensive. 18 | 18. Finding a soul mate. 19 | 19. Thinking that finding a soul mate is the best use of our time. 20 | 20. Not knowing ourselves well enough. 21 | 21. All our bad habits. (You know you have them.) 22 | 22. Thinking we know it all. 23 | 23. Not understanding that in the grand scheme of things, we don't know sh*t. 24 | 24. Spending too much time on Facebook. 25 | 25. Not getting enough exercise. 26 | 26. Playing video games until we literally can't see. 27 | 27. Pulling an all-nighter and then regretting it in the morning. 28 | 28. Using beer goggles to make poor decisions. 29 | 29. The walk of shame. 30 | 30. Deciding which tattoo to get — aka which one we will regret the least in 20 years. 31 | 31. Not listening to others. 32 | 32. Feeling privileged. 33 | 33. Being unable to empathize. 34 | 34. Using sympathy as a way to insult people. 35 | 35. Being opinionated on subjects we know nothing about. 36 | 36. Trolling everyone who speaks their mind. 37 | 37. Not realizing that most EDM music and Dubstep are complete crap. 38 | 38. Not reading enough. 39 | 39. Watching reality TV (while ignoring reality). 40 | 40. Complaining about everything and anything. 41 | 41. Being too picky. 42 | 42. Being too stubborn. 43 | 43. Being close-minded, but thinking we’re open-minded. 44 | 44. Having to tell a partner it's not going to work out. 45 | 45. Trying to figure out if we should be the first to say “I love you.” 46 | 46. Having to tell a partner we don't love him or her anymore. 47 | 47. Keeping it in our pants — generally speaking for both genders. 48 | 48. Music festivals. 49 | 49. Tanning beds. 50 | 50. Paying for the label. 51 | 51. Buying sh*t we don't need. 52 | 52. Not donating. (If you don't have money, you surely have time.) 53 | 53. Bringing the wrong people into our lives. 54 | 54. …Allowing those wrong people to remain part of our lives. 55 | 55. Allowing others to make decisions for us. 56 | 56. Not speaking up. 57 | 57. Being afraid of greatness. 58 | 58. Pretending like we're braver than we are, and believing it. 59 | 59. Being too proud to ask for help when we need it. 60 | 60. Not being considerate of others. 61 | 61. Thinking the world revolves around us. 62 | 62. Lying for the hell of it. 63 | 63. Having sex with all the wrong people. 64 | 64. Not being able to find a suitable mentor or role model. 65 | 65. Not being in love with learning. 66 | 66. Not bothering to educate ourselves after snatching that diploma. 67 | 67. Thinking “YOLO” is short for “do something crazy and hope you don't die.” 68 | 68. Thinking molly is a great drug. 69 | 69. Thinking too highly of ourselves. 70 | 70. Letting the opinions of others influence us deeply. 71 | 71. Allowing ourselves to be wounded by careless, hurtful people. 72 | 72. …Expecting those people to change their ways. 73 | 73. Not accepting the fact that manipulation is important if we wish to succeed. 74 | 74. Spending our time foolishly. 75 | 75. Never slowing down… Because we’re afraid life itself is boring? 76 | 76. Not traveling enough and experiencing other cultures. 77 | 77. Not giving a damn — about anything. 78 | 78. Being environmentally friendly as a fad. 79 | 79. Posting stupid sh*t on YouTube. (Most of us already know you're stupid; don't need to prove yourself again.) 80 | 80. Smoking too much. 81 | 81. Bullying people. We all do it, even if we don't realize it. 82 | 82. Not saving money because we think there is no way possible that we can. 83 | 83. Not dancing enough. I'm not talking about raving. I mean actually dancing. 84 | 84. Forgetting about the concept of courtship. 85 | 85. Most one-night stands. 86 | 86. Doing things without a purpose. 87 | 87. Not thinking before acting. 88 | 88. Not spending more time with our families. 89 | 89. Not telling those that we love, that we love them. 90 | 90. Not appreciating the little things. 91 | 91. Not appreciating the individuals who are most important in our lives. 92 | 92. Not spending enough time outdoors. 93 | 93. Not living life. Most of us are fooling ourselves into believing we are. 94 | 94. Giving up on dreams when the going gets tough. 95 | 95. Being very good at coming up with excuses. 96 | 96. Being too overloaded with unimportant information to remember the important information. 97 | 97. Not writing. 98 | 98. Thinking there will always be a tomorrow. 99 | 99. Not spending every hour of every day improving ourselves, making ourselves better, stronger, smarter people. 100 | 100.why will god exists 101 | 101.sucks to be part of this stupid world 102 | 102.complicated job loss 103 | 103.why i look so weird 104 | 104.All girls are beautiful true or not 105 | 105.Is weather a problem in today's world 106 | 106.cool stuff never ever works 107 | 107.Why do girls menstruate 108 | 108.are people in america racist 109 | 109.Is India Racist country -------------------------------------------------------------------------------- /Mini_Search_Engine.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // Mini Search Engine of Problems 4 | // 5 | // Created by Mayur Jain on 2/4/17. 6 | // Copyright © 2017 Mayur Jain. All rights reserved. 7 | // 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | using namespace std; 23 | 24 | map getFileToMap; 25 | map getUrlForSolution; 26 | class Problems{ 27 | public: 28 | string differentProblems(); 29 | std::pair SearchProblemExist(int,string,int); // pair 30 | 31 | }getProblem; 32 | 33 | class Solutions: public Problems{ // Inheritance 34 | 35 | public: 36 | // Public Access Specifier - members declared under can be accessible from outside the s class 37 | vector filter_search[10]; 38 | long Life_solution(string,int); 39 | void subSearch(int,int,string); 40 | void printQuestions(int fetchQuestion){ 41 | 42 | cout<<"Question less Proabable"<(++y,line)); // Assigning Number to a Line or Question ! 78 | } 79 | // Moved the file to MAP CONTAINER 80 | 81 | for(map::iterator itr = getFileToMap.begin();itr!=getFileToMap.end();++itr){ 82 | try{ 83 | std::regex e ("\\b" + wordSearch +"\\b",regex_constants::icase); 84 | if(std::regex_search (itr->second,m,e)) 85 | { 86 | filter_search[pushKey].push_back(itr->first); // Array Vector (filter_search) holds the occurrence of each word with its key value 87 | } 88 | }catch(const std::regex_error& oor) { 89 | std::cerr << "Regex error: " << oor.code() << '\n'; 90 | break; 91 | } 92 | } 93 | 94 | if(filter_search[pushKey].empty()){ 95 | cout<<"NO matches found "< 0){ 121 | try{ 122 | for(int i=0;i<10;i++){ 123 | if(!filter_search[i].empty()){ 124 | for(int j=1;j<10;j++){ 125 | filter_search[0].insert(filter_search[0].end(),filter_search[j].begin(), filter_search[j].end()); 126 | filter_search[j].erase(filter_search[j].begin(), filter_search[j].end()); 127 | freq[j-1] = -1; 128 | } 129 | } 130 | else{ 131 | continue; 132 | } 133 | } 134 | 135 | sort(filter_search[0].begin(),filter_search[0].end()); 136 | for(int q=0; q(++x,line)); // Assigning Number to a Line or Question ! 173 | } 174 | 175 | } 176 | soln.close(); 177 | string str(getUrlForSolution.at(filter_search[0].at(max_elements))); 178 | openURL(str); 179 | 180 | } 181 | catch(const std::out_of_range& oor) { 182 | std::cerr << "Out of Range error: " << oor.what() << '\n'; 183 | } 184 | } 185 | else 186 | { 187 | cout<<"Unable to find the solution"< problemStatement; 211 | string questionSearched = getProblem.differentProblems(); 212 | string arr[20]; 213 | int i = 0; 214 | int q = 0; 215 | int wordPresent = 0; 216 | // Forming array format of string 217 | 218 | stringstream ssin(questionSearched); 219 | while (ssin.good() && i < 20){ 220 | ssin >> arr[i]; 221 | ++i; 222 | } 223 | 224 | // check entered string is empty or not and then inserting & mapping the string with key and value in problemStatement Map 225 | 226 | int noOfwords = i; 227 | 228 | for(int x=0;x<20;x++){ 229 | 230 | if(arr[x]==""){ 231 | break; 232 | } 233 | 234 | else 235 | { 236 | problemStatement.insert(std::pair(x+1,arr[x])); 237 | } 238 | } 239 | 240 | 241 | 242 | for(map::iterator it = problemStatement.begin();it!=problemStatement.end();++it) 243 | { 244 | q +=1; 245 | long wordFound = solution.Life_solution(problemStatement.at(q),q-1); 246 | if(wordFound>0){ 247 | ++wordPresent; 248 | } 249 | else{ 250 | cout<