// =================================================== // FUNCTION: cleanup() // =================================================== function cleanup( today ) { // CONSTANTS are in ALL CAPS var CLEANAFTER = 10; // Set this entry higher to clean less often, lower to clean more often var TIMER = 5; var cleanFlag = true; // Delete current user's entries to start a new query database.execute("delete from matchquery where clientid = '" + client.queryname + "'"); // Clean up entries older than one hour. project.lock(); if ((project.cleanup + "") == "null") { project.cleanup = 1; // if it's null, initialize it. cleanFlag = false; } else if (project.cleanup < CLEANAFTER) { project.cleanup = parseInt(project.cleanup) + 1; cleanFlag = false; } project.unlock(); if (cleanFlag) { // Clean up all entries older than one TIMER cursor = database.cursor("select * from matchquery", true); while (cursor.next()) { debug("diff is " + Math.abs(today.getMinutes() - cursor.timestamp.getMinutes())); // Delete records older than one hour if ( Math.abs(today.getMinutes() - cursor.timestamp.getMinutes()) > TIMER ) cursor.deleteRow("MATCHQUERY"); } // END while loop cursor.close(); } // END if } // END cleanup() // =================================================== // FUNCTION: calcScore() // =================================================== function calcScore(jobcursor) { var score = 0; /* Below is a section of rules and search parameters. Any rule may be modified and deleted easily in this one section since this is the only place that the rules checking takes place. New rules can be added very simply by adding an if statement patterned after the ones below. The score for each job parameter which matches a seeker parameter is incremented by one. Ultimately, we will show the job seeker a list of jobs that match their search parameters, starting with the jobs that scored the highest, i.e. the jobs that had the most parameters match. We will not show any jobs that had a final score of 0, since this indicates no job parameters matched any seeker parameters. This scoring scheme can be altered in many ways. For example, we could weight each score so that attributes which may be more important score higher if they match. */ if ( (request.salarylow == "") || (jobcursor.salaryhigh >= parseInt(request.salarylow)) ) score += 1; if ( (request.education == "") || (jobcursor.mineduc == request.education)) score += 1; if ( (request.yearsexp == "") || (jobcursor.minyearsexp <= parseInt(request.yearsexp)) ) score += 1; if ( (request.lcity == "") || (jobcursor.lcity == request.lcity) ) score += 1; if ( (request.lstate == "") || (jobcursor.lstate == request.lstate) ) score += 1; if ( (request.lcountry == "") || (jobcursor.lcountry == request.lcountry) ) score += 1; debug("score = ", score); return score; } // END calcScore() // =============================================================== // BEGIN "Main" function // =============================================================== var score = 0; var hits = 0; // Number of matches var today = new Date(); // make sure the connection is still active and reconnect if it is not. if (!dbCheck()) { redirect("../error.htm?error=dbfail"); } securityCheck(client.valid, client.usertype, "seeker", "../login.htm?type=seeker"); /* Create a temporary table with a unique name generated by s (for seeker) + their userid. We add an "s" to the front of the userID since employers may search for employees also, and in the process, temporary tables may be created based on employer id's. Since employer id's and seeker id's are not guaranteed to be unique between the two fields, we must add an "s" to the id to ensure that a seeker id that matches an employer id does not result in generating tables with identical names. */ client.queryname = "s" + client.userID; /* Below, we perform a check on the client variable "searchcount" which keeps track of how many searches the client has conducted. If it is the first search (i.e. if client.searchcount is null), then we create the temporary table. Otherwise, the temporary table has already been created, and we must simply empty the table to prepare it for new entries. */ cleanup(today); /* if (client.searchcount == null) { database.execute("create table " + client.queryname + " ( " + "userid varchar(20,0)," + "jobid integer," + "score integer );"); client.searchcount = 1; } else { client.searchcount += 1; database.execute("delete from " + client.queryname); } // END if-else */ // Get the list of jobs jobcursor = database.cursor("select * from jobs"); // Loop through each job and score it. while(jobcursor.next()) { score = calcScore(jobcursor); // if at least one parameter matched, insert the job into the temp. table if (score > 0) { /* database.execute("insert into matchquery values (" + "'" + client.queryname + "'," + "'" + jobcursor.jobid + "'," + "'" + score + "'," + "'" + today + "')"); */ qcursor = database.cursor("select * from matchquery where clientid = '" + client.queryname + "'", true); qcursor.next(); qcursor.clientid = client.queryname; qcursor.jobid = jobcursor.jobid; qcursor.score = score; qcursor.timestamp = today; qcursor.insertRow("MATCHQUERY"); qcursor.close(); hits += 1; } } // End while loop redirectstr = "joblist.htm?hits=" + hits + "&queryname=" + client.queryname; jobcursor.close(); redirect(redirectstr);