Thread: Simple search engine using maps

  1. #16
    Registered User
    Join Date
    Feb 2008
    The error seems to have gone a away but i need some help finding a way to print out the filenames in order from highest relavance to least relevant. I was using a map but I doesnt work because sometimes the value can be the same for 2 files so it won't pring correctly. Heres the code I have now but what would be a good way to print the results? Thanks

    /* Testing Files:
    word.txt: computer server program computer internet internet website internet program program
    word2.txt laptop website website computer internet email website server laptop
    word3.txt (empty file)
    (identical to word.txt)  word4.txt computer server program computer internet internet website internet program program
    word5.txt email email email email email email email email
    word6.txt server server server server server website website laptop email  
    #include <fstream>
    #include <iostream>
    #include <string>
    #include <map>
    #include <list>
    using namespace std;
    int main(int argc, char* argv[])
       map<string, int> info[argc-1];
       map<string, double> result;
       string fileNames[argc-1];
       list<double> value;
       string word;
       string keyword1;
       string keyword2;
       cout<<"Enter first keyword: ";
       cin >> keyword1;
       cout <<"Enter second keyword: ";
       cin >> keyword2;
       cout << "\n";
       for(int i=1; i < argc; i++)
          fileNames[i-1] = argv[i];
          ifstream fin(argv[i]);
          if(!fin) exit(1);
         // while(!fin.eof())
            // fin>>word;
             if(info[i-1].count(word) <0 ) 
      //This is where I need help
       for(int i=0; i < argc-1; i++)
          value.push_back(info[i][keyword1]*.33 + info[i][keyword2]*.67);
          result[fileNames[i]] = (info[i][keyword1]*.33 + info[i][keyword2]*.67);
       cout << "Results (relevance from highest to lowest): \n";
       int i =0;
       for(int i=0; i < argc-1; i++)
         i =0;
             if(result[fileNames[i]] == value.back())
                cout<< fileNames[i] << ": " << value.back()<< "\n";

  2. #17
    Registered User
    Join Date
    Jan 2005
    If the value can be the same perhaps a multimap is more appropriate? (I didn't look at the code.)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating an AI engine for a simple game
    By cyb3r in forum Game Programming
    Replies: 1
    Last Post: 01-26-2009, 12:19 PM
  2. Search function not working fully
    By tabstop in forum C Programming
    Replies: 7
    Last Post: 12-04-2008, 01:57 AM
  3. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  4. Big help in Astar search code...
    By alvifarooq in forum C++ Programming
    Replies: 6
    Last Post: 09-24-2004, 11:38 AM
  5. Your favourite search engine?
    By ammar in forum A Brief History of
    Replies: 20
    Last Post: 12-03-2002, 11:43 AM
Website Security Test