Jump to content

Simple 5 Attribute Matching Algorithm


amavadia

Recommended Posts

Hey Guys

 

I am currently working on a project where people use a php based website to post adverts. Each advert has 5 attributes assocated with it that describe it, and each attribute has a scale of 1-5

 

so for eg. advert 1 will be rated 1 for attribute 1, 3 for attribute 2 and so on

 

I have implemented a simple search for exact matches of the attributes, but am now looking for a simple way of finding similar results based on the attributes where there is just 1 value off in a couple of the attributes for example.

 

Anybody have any ideas of how to do this in a simple way?

 

Thanks

Link to comment
Share on other sites

Hey Guys

 

I am currently working on a project where people use a php based website to post adverts. Each advert has 5 attributes assocated with it that describe it, and each attribute has a scale of 1-5

 

so for eg. advert 1 will be rated 1 for attribute 1, 3 for attribute 2 and so on

 

I have implemented a simple search for exact matches of the attributes, but am now looking for a simple way of finding similar results based on the attributes where there is just 1 value off in a couple of the attributes for example.

 

Anybody have any ideas of how to do this in a simple way?

 

Thanks

 

If 5 is the best rating, and 1 the worst then you could apply an algorithm. Weight the importance of each attribute.

 

$totalRating = $firstAttributeRating * $firstWeight + $secondAttributeRating * $secondWeight....etc.

 

If you give a concrete example then it might be easier to help you.

Link to comment
Share on other sites

Hey Guys

 

I am currently working on a project where people use a php based website to post adverts. Each advert has 5 attributes assocated with it that describe it, and each attribute has a scale of 1-5

 

so for eg. advert 1 will be rated 1 for attribute 1, 3 for attribute 2 and so on

 

I have implemented a simple search for exact matches of the attributes, but am now looking for a simple way of finding similar results based on the attributes where there is just 1 value off in a couple of the attributes for example.

 

Anybody have any ideas of how to do this in a simple way?

 

Thanks

 

If 5 is the best rating, and 1 the worst then you could apply an algorithm. Weight the importance of each attribute.

 

$totalRating = $firstAttributeRating * $firstWeight + $secondAttributeRating * $secondWeight....etc.

 

If you give a concrete example then it might be easier to help you.

 

Thanks for your reply.

 

Basically it is a website to compare and search for computing degree courses

 

so a record would be a particular course, which would have 5 attributes

 

an attribute would be for example how much programming, or maths, or analysis would be involved, and this would be rated from 1 to 5 where 1 would be none of the attribute would be included in the course, and 5 would be a lot.

 

At the moment ive implemented a simple search via a database query, so the user select he wants a course with a lot of programming, no analysis etc, and it will return exact matches

 

But I also want to add a way of recommending similar courses to the person, so for the user above I would like to recommend a course with very little programming but still no analysis.

Link to comment
Share on other sites

  • 2 weeks later...

Guys, ive progressed a little here, but would really like a bit of help to finish it off

 

As explained, I have a table of courses with 5 attributes for each (called attribute_1, attribute_2, attribute_3 etc...)

 

On the search page, the user will select a value of 1-5 from drop down menus which will then be sent to the results page via $_POST.

 

When I pick the $_POST values up, at the top of the results page I want to show all the courses that match the search criteria EXACTLY, which is quite simple... I just concatenated the $_POST values directly into the SQL query. Then below this I am looking to post SIMILAR matches, so I have written a query which looks for each attribute +/- 1. But to get this to work, I had to also include the original criteria because if someone selects criteria with say 1 for the first attribute and 2 for the second, and in the DB there is a course which has 1 for the first and 3 for the second, it wont come up unless it is searching for 1 in the first attribute also.

 

This means when there is an exact match, it shows up in both the top exact match section (where it should) and also the similar match section (dont want it here)

 

Is there any way to exclude the exact match combination from the similar match query?

 

Sorry for the long and confusing explanation. Below are my queries:

 

EXACT Match:

 

select * 
FROM advert, attributes
WHERE attributes.attribute_1 = ' . $_POST['searchatt1'] . '
AND attributes.attribute_2 = ' . $_POST['searchatt2'] . '
AND attributes.attribute_3 = ' . $_POST['searchatt3'] . '
AND attributes.attribute_4 = ' . $_POST['searchatt4'] . '
AND attributes.attribute_5 = ' . $_POST['searchatt5'] . '
AND advert.advert_id = attributes.advert_id
ORDER BY role_title';

 

SIMILAR match:

 

select * 
FROM advert, attributes
WHERE (attributes.attribute_1 = ' . (($_POST['searchatt1'])+1) . ' OR attributes.attribute_1 = ' . $_POST['searchatt1'] . ' OR attributes.attribute_1 = ' . (($_POST['searchatt1'])-1) . ')
AND (attributes.attribute_2 = ' . (($_POST['searchatt2'])+1) . ' OR attributes.attribute_2 = ' . $_POST['searchatt2'] . ' OR attributes.attribute_2 = ' . (($_POST['searchatt2'])-1) . ')
AND (attributes.attribute_3 = ' . (($_POST['searchatt3'])+1) . ' OR attributes.attribute_3 = ' . $_POST['searchatt3'] . ' OR attributes.attribute_3 = ' . (($_POST['searchatt3'])-1) . ')
AND (attributes.attribute_4 = ' . (($_POST['searchatt4'])+1) . ' OR attributes.attribute_4 = ' . $_POST['searchatt4'] . ' OR attributes.attribute_4 = ' . (($_POST['searchatt4'])-1) . ')
AND (attributes.attribute_5 = ' . (($_POST['searchatt5'])+1) . ' OR attributes.attribute_5 = ' . $_POST['searchatt5'] . ' OR attributes.attribute_5 = ' . (($_POST['searchatt5'])-1) . ')
AND advert.advert_id = attributes.advert_id 
ORDER BY role_title';

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.