amavadia Posted January 16, 2010 Share Posted January 16, 2010 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 Quote Link to comment Share on other sites More sharing options...
phonydream Posted January 16, 2010 Share Posted January 16, 2010 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. Quote Link to comment Share on other sites More sharing options...
amavadia Posted January 16, 2010 Author Share Posted January 16, 2010 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. Quote Link to comment Share on other sites More sharing options...
amavadia Posted January 20, 2010 Author Share Posted January 20, 2010 any other ideas anyone? Quote Link to comment Share on other sites More sharing options...
amavadia Posted January 30, 2010 Author Share Posted January 30, 2010 Any other ideas please? Quote Link to comment Share on other sites More sharing options...
amavadia Posted February 3, 2010 Author Share Posted February 3, 2010 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'; Quote Link to comment Share on other sites More sharing options...
amavadia Posted February 3, 2010 Author Share Posted February 3, 2010 Solved! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.