Today:

16/06/2021

WhatJobs.com Tips – How to build your own job search engine

Share this article

A while ago, a friend of mine asked me if I can help him on a small PHP project. The project was about turning his static website into a place that people can search for jobs. He was looking for a solution to let his visitors search for job content and see the results within the pages of his website.

I thought it would take a long time to implement such a system because it was about storing the jobs in a database, then showing them to the users based on their search criteria. With this in mind, I prepared myself for a project which I needed to be involved with for a long while.

He asked me to look at a third-party website offering an API letting people have their own job search engine. They claimed there would be no hassle in dealing with their jobs, configuring a database, or any other technical issues. The API was letting websites access the latest vacancies and show them to their visitors. In return, the website that was serving these jobs to the visitors could make money every time a user clicked on any job search results.

After reading and playing with the sample codes, I found no need to search for the user’s keyword in the local database. Moreover, I did not need to have any database to store the jobs at all! Actually, the only thing that I had to do was get the user’s request and send it to the API. After receiving data from API, I was able to show them to the user.

I know it sounds crazy to have a job search engine without having any database, but these days you see even stranger things! The project was something cool, so I decided to accept the challenge and see the outcome!

The first thing I did was preparing an API URL to see the result. There were two options: first, returning the result in XML format and the second, returning the same result in JSON format.

I opened the URL in my browser and set the search keyword to sales:

https://whatjobs.com/api/v1/jobs.xml?publisher=1&keyword=sales

Also tried the JSON URL and changed the keyword and set a location:

https://whatjobs.com/api/v1/jobs.json?publisher=1&keyword=manager&location=london

It could not be easier than this. I had the search result, and the only other thing I had to do was format them with the look and feel of my friend’s website and then show them to the user!

But I was too excited to realise that before showing any result to the users, I should have asked them what they wanted to search for! So I decided to start with a straightforward page with a search button for two input boxes: One for keyword and the other for location.

<form>

    <input name=”keyword”>

    <input name=”location”>

    <input type=”submit” value=”Search”>

</form>

As such, when a user hit the search button I would receive the user’s keyword and location in the $_GET variable, and by having these two values, I was able to create the URL to call the API. According to the documentation I should have sent additional information like publisher ID, user IP and user agent otherwise, the tracking system wouldn’t work, and my friend wouldn’t make any money 😉

The final code to generate the API URL was:

$data = array(

    ‘publisher’ => 1,

    ‘user_ip’ => $_SERVER[‘REMOTE_ADDR’],

    ‘user_agent’ => $_SERVER[‘HTTP_USER_AGENT’],

    ‘keyword’ => $_GET[‘keyword’],

    ‘location’ => $_GET[‘location’],

);

$api_url = “https://whatjobs.com/api/v1/jobs.json?” . http_build_query($data);

The rest was easy, calling the API and converting JSON to an array and storing the result in the $result variable:

$result = json_decode(file_get_contents($api_url), true);

Now I had everything I was looking for, and I would format the result and show them to the user. It was only matter of the colours and the styles that could make the result suitable for the user. To make my life easy and create a responsive page for mobile users, I used Bootstrap to show the result to the user by including Bootstrap CSS file and adding some classes to the tags. Then I used a table to show each job in a row.

<table class=”table table-condensed”>

<?php foreach ($result[‘data’] as $job): ?>

    <tr>

        <td>

            <div class=”col-sm-6 h2″>

                <a href=”<?php echo $job[‘url’]; ?>” target=”_NEW” rel=”nofollow”><?php echo $job[‘title’]; ?></a>

            </div>

            <br>

            <?php if (! empty($job[‘salary’])): ?>

            <div class=”col-sm-6 text-right” style=”color: #888;”><strong><?php echo $job[‘salary’]; ?></strong></div>

            <?php endif; ?>

            <?php if (! empty($job[‘location’])): ?>

            <div class=”col-sm-6 text-right” style=”color: #888;”>Location: <strong><?php echo $job[‘location’]; ?></strong></div>

            <?php endif; ?>

            <div class=”col-sm-10″><?php echo $job[‘snippet’]; ?></div>

            <div class=”col-sm-2″>

                <?php if (! empty($job[‘logo’])): ?>

                <a href=”?<?php echo generateURL(array(‘keyword’ => $job[‘company’])); ?>”><img align=”right” src=”<?php echo $job[‘logo’]; ?>”></a>

                <?php endif; ?>

            </div>

            <div class=”col-sm-12″ style=”color: #999;”>

                <?php if (! empty($job[‘company’])): ?>

                Company: <strong><?php echo $job[‘company’]; ?></strong>

                <?php endif; ?>

                <?php if (! empty($job[‘job_type’])): ?>

                Job type: <strong><?php echo $job[‘job_type’]; ?></strong>

                <?php endif; ?>

                (<span><?php echo $job[‘age’]; ?></span>)

            </div>

        </td>

    </tr>

<?php endforeach; ?>

</table>

Also, according to the API tracking document I had to place the tracking code near the results. It was a script tag to include the JavaScript tracking code. I placed it after the table tag.

Everything was almost ready, and I could finish this project very quickly by putting the pagination at the bottom of the page. Building the pagination was easy enough because there were some other values in the API result to show the current page and the last page. By having these values and doing some calculation, I managed to create the pagination index. So on each API call, I was able to send the page number to receive the related result.

function getPaginationIndex($current_page, $last_page, $index_count)

{

    $low_index = $current_page – round($index_count / 2) + 1;

    $high_index = max($low_index, 1) + $index_count – 1;

    if ($high_index > $last_page)

    {

        $high_index = $last_page;

        $low_index = $high_index – $index_count + 1;

    }

    $low_index = max($low_index, 1);

    return array($low_index, $high_index);

}

I was done and my coffee was still on the table, so I still had time to add some other options to make it look like a professional website. I decided to add a list of categories and locations to the home page. That was a very useful option for the users so they could just click and browse jobs relevant to them. The only challenge was building the lists, then I could create a URL for each of these items.

function getLocations()

{

    return array(

        ‘Basingstoke’, ‘Exeter’, ‘Nottingham’, ‘Birmingham’, ‘Gloucester’, ‘Oxford’, ‘Bradford’, ‘Guildford’, ‘Oxfordshire’,

        ‘Brighton’, ‘Hampshire’, ‘Peterborough’, ‘Bristol’, ‘Hertfordshire’, ‘Preston’, ‘Buckinghamshire’, ‘Kent’, ‘Reading’,

        ‘Cambridge’, ‘Leeds’, ‘Sheffield’, ‘Cambridgeshire’, ‘Leicester’, ‘Slough’, ‘Chelmsford’, ‘Leicestershire’,

        ‘Southampton’, ‘Cheshire’, ‘Liverpool’, ‘Stockport’, ‘Chester’, ‘London’, ‘Surrey’, ‘Coventry’, ‘Maidstone’, ‘Swindon’,

        ‘Croydon’, ‘Manchester’, ‘Wakefield’, ‘Derby’, ‘Milton Keynes’, ‘Warrington’, ‘Derbyshire’, ‘Newcastle upon Tyne’,

        ‘West Yorkshire’, ‘Doncaster’, ‘Northampton’, ‘York’,

    );

}

function getCategories()

{

    return array(

        ‘Accounting’, ‘Finance’, ‘Pharmaceutical’, ‘Administrative’, ‘Food Service’, ‘PR’, ‘Advertising’, ‘Healthcare’,

        ‘Publishing’, ‘Agriculture’, ‘Hospitality’, ‘Real Estate’, ‘Architecture’, ‘Human Resources’, ‘Restaurant’, ‘Arts’,

        ‘Insurance’, ‘Retail’, ‘Banking’, ‘IT’, ‘Sales’, ‘Computer’, ‘Law Enforcement’, ‘Scientific’, ‘Construction’, ‘Legal’,

        ‘Security’, ‘Consulting’, ‘Loans’, ‘Social Care’, ‘Customer Service’, ‘Logistics’, ‘Telecommunications’, ‘Education’,

        ‘Management’, ‘Training’, ‘Energy’, ‘Manufacturing’, ‘Transportation’, ‘Engineering’, ‘Marketing’, ‘Travel’, ‘Facilities’,

        ‘Mechanical’, ‘Volunteering’,

    );

}

When I placed all the pieces together, I was really pleased with the final result! It was the first time that I had finished a project so quickly.

Similar Articles

Don't Miss

Jobs available in Croydon

The main employment sectors in Central Croydon are retail and enterprise. Also the area 'Purley Way' has many retail parks, outlet and malls making it a destination for shoppers looking for stores that carry the full range of products. Here there are many opportunities for sales assistants, consultants and store managers. IKEA Croydon brought many non-skilled jobs to Croydon and is the fifth biggest employer in Croydon.

Morris Leslie plant hire company rises from losing millions to investing £70m

Perthshire plant hire giant Morris Leslie was hit hard by the Covid 19 pandemic, however the company was struggling before that because of Brexit. Six months before Covid 19 shut down building sites and locked down the UK the company Morris Leslie has already experienced tough times. Uncertainty because of Brexit had already caused building projects to be shut down or paused causing a much lower demand for plant hires and sales. This slowdown had caused an oversupply of construction equipment meaning more competition and so reduced prices. Then Covid 19 hit and the group’s vehicle auctions and Sunday car boot market were shut down.

Jobs available in Lambeth

Lambeth is a borough in Central London that is quickly developing into a business and cultural hub. Along the River Thames is a pedestrianised area running next to the river Thames called the 'South Bank' which is a great destination for tourists and locals alike. This area includes cultural draws such as the Southbank Centre and National Theatre where actors, singers, lighting technicians and set designers can all find opportunities. Other tourist attractions such as the London Eye, London Dungeons and London Aquarium are also found along the Southbank providing lots of employment. There is a great range of restaurants as well, taking advantage of the high footfall of people enjoying the great views of the city of London along this walkway. Cultural events, Street performs and the annual Christmas market all make the Southbank a destination for tourists and locals throughout the year and provide employment oppertunities. The Oval cricket ground is located in Kennington and is home to the Surrey County Cricket team as well as international matches. These events draw huge crowds and offer employment for security staff, chefs and waiting staff.