1

I am developing a job site, where I want to search through job ads by relevance, I have fields such as job title, job_text for example. now lets say a person searches for cakephp, I would like to get results for cakephp first, and then after them say php which also matches, but cakephp is obviously the most relevant. how can I do this?

Ross
  • 18,117
  • 7
  • 44
  • 64
louis_coetzee
  • 393
  • 7
  • 14
  • 1
    If a person searches specifically for `cakephp` how would `php` be a match? Just chopping parts off words doesn't make any sense. With that kind of logic, a search for `automobile` would also return mobile phone results. Don't you mean the other way around? – Oldskool Jan 08 '13 at 22:29
  • lets say I enter a search for php, it would get results for job ads with title php and php somewhere in the body, this would be the most relevant, if jobs with php in the body but not in the title, where the tile might be "web developer", this result would be less relevant, if the word php on its own is then not present in the 3rd job ad, lets say it only contains cakephp, this one would be the least relevant. Sorry for the confusion and improper example the 1st time. – louis_coetzee Jan 10 '13 at 10:04

3 Answers3

1

My suggestion is that you should run multiple queries for the sorting purposes.

For example, first you find the jobs where title is say php using order by title desc, then run query to find jobs where 'php' appears in keywords for jobs, and lastly you can run a query to find jobs where description has the word 'php' in it.

Then you can combine the results for these queries.

Josh
  • 1,794
  • 3
  • 17
  • 31
cartina
  • 1,409
  • 13
  • 21
1

The best way I found to do what I was trying to at that stage was to integrate with apache solr or some similar search engine.

louis_coetzee
  • 393
  • 7
  • 14
0

If you want to sort by relevance you will have to come up with some criteria of how relevance is defined for you and calculate it. For example if a certain article got more views it might be more relevant than another article because it was seen by more people. Combine that number with a few other variables (average rating for example if there is a rating functionality), calculate a relevance value based on them, store it in your table and order by the relevance value field. Update it every time one of the vars for the calculation changes or do it via a cron job one time per day, it all depends on your requirements and performance.

floriank
  • 25,546
  • 9
  • 42
  • 66