-2

I am in the middle of creating an app that allows users to apply for job positions and upload their CVs. I`m currently stuck on trying to make a search box for the admin to be able to search for Keywords. The app will than look through all the CVs and if it finds such keywords it will show up a list of Cvs that contain the keyword. I am fairly new to Gui design and app creation so not sure how to go about doing it. I wish to have it done via java and am using the Eclipse Window builder to help me design it. Any help will be greatly appreciated, hints, advice anything. Thank You.

2 Answers2

0

Well, this not right design approach as real time search of words in all files of given folder will be slow and not sustainable in long run. Ideally you should have indexed all CV's for keywords. The search should run on index and then get the associated CV for that index ( think of indexes similar to tags). There are many options for indexing - simples DB indexing or using Apache Lucene or follow these steps to create a index using Maps and refer this index for search.

  • Create a map Map<String, List<File>> for keeping the association of keywords to files

  • iterate through all files, and for each word in each file, add that file to the list corresponding to that word in your index map

here is the java code which will work for you but I would still suggest to change your design approach and use indexes.

File dir = new File("Folder for CV's"); 
if(dir.exists()) 
{ 
  Pattern p = Pattern.compile("Java"); 
  ArrayList<String> list = new ArrayList<String>(); // list of CV's

  for(File f : dir.listFiles())
  {
    if(!f.isFile()) continue;
    try
    {
      FileInputStream fis = new FileInputStream(f);
      byte[] data = new byte[fis.available()];
      fis.read(data);
      String text = new String(data);
      Matcher m = p.matcher(text);
      if(m.find())
      {
        list.add(f.getName()); // add file to found-keyword list.
      }
      fis.close();
    } 
    catch(Exception e)
    {
      System.out.print("\n\t Error processing file : "+f.getName());
    }

  }
  System.out.print("\n\t List : "+list); // list of files containing keyword.
} // IF directory exists then only process.
else
{
  System.out.print("\n Directory doesn't exist.");
}

Here you get the files list to show now for "Java". As I said use indexes :)

Sheetal Mohan Sharma
  • 2,908
  • 1
  • 23
  • 24
0

Thanks for taking your time to look into my problem. I have actually come up with a solution of my own. It is probably very amateur like but it works for me.

    JButton btnSearch = new JButton("Search");
    btnSearch.addActionListener(new ActionListener() 
    {
        public void actionPerformed(ActionEvent arg0) 
        {
            list.clear();
            String s  = SearchBox.getText();
            int i = 0,present = 0;
            int id;
            try
            {
                Class.forName(driver).newInstance();
                Connection conn = DriverManager.getConnection(url+dbName,userName,password);
                Statement st = conn.createStatement();
                ResultSet res = st.executeQuery("SELECT * FROM javaapp.test");
                while(res.next())
                {
                    i = 0;
                    present = 0;
                    while(i < 9)
                    {
                        String out = res.getString(search[i]);
                        if(out.toLowerCase().contains(s.toLowerCase()))
                        {
                            present = 1;
                            break;
                        }
                        i++;
                    }
                    if(tglbtnNormalshortlist.isSelected())
                    {
                        if(present == 1 && res.getInt("Shortlist") == 1)
                        {
                            id = res.getInt("Candidate");
                            String print = res.getString("Name");
                            list.addElement(print+" "+id);
                        }
                    }
                    else
                    {
                        if(present == 1 && res.getInt("Shortlist") == 0)
                        {
                            id = res.getInt("Candidate");
                            String print = res.getString("Name");
                            list.addElement(print+" "+id);
                        }
                    }
                }
            }
            catch (Exception e) 
            {
                e.printStackTrace();
            }
        }
    });