Marcel
Marcel

Reputation: 3825

How to do car search like autoscout24.de with / without SQL?

I am interested in the implementation of the search engine in autoscout24.de. It is a platform where you can sell/buy cars. Every car advert has properties: make, price, kilometers, color, etc. (in sum over 50 different properties) that can be searched for.

I am specifically interested in the detail search that works like this: every possible property is displayed on the page. In brackets behind each property there is the number of cars that will match the new search if the property is selected.

Example: I'll start with empty search criterias.

Property make:

Property color:

and so on for the other properties.

I'd like to know:

Update:

The numbers in brackets show the number of results after the addition of the search criteria. So it changes each time a property is added / removed...

So a naive algorithm would work like this:

This algorithm is naive because it would execute 1 + N queries (N=#properties). Nobody wants to do that ;-)

Upvotes: 2

Views: 3558

Answers (3)

bokan
bokan

Reputation: 3692

It's a basic code

  • Create a result object with one counter for each property that the cars have
  • Check all cars one by one, if the car match the filter then add one to each of the numbers

...But it's blasting fast !

I think they do it on several computers, shreading data across them. Each computer compute 5% of the data and send the result to the front computer wich sum all counts.

There are tools for that : look for "map reduce", "elastic search", "strom"...

Upvotes: 0

Ken Keenan
Ken Keenan

Reputation: 10568

I believe that this is referred to as "faceted search". The Apache Solr project might be worth looking at.

Upvotes: 2

Ofir Baruch
Ofir Baruch

Reputation: 10346

Have a properties table:

+Properties

  • id
  • title
  • value
  • count

The count field allows you to "earn" an extra query , so instead of checking how much cars have a certain property , you can just update this field when adding new cars.

Example of rows in this table:

1 'color' 'white' 1000

2 'color' 'black' 122

3 'km' '5000' 1233

4 'km' '30000' 54

And for the cars table , for each property add a field.

+Cars

  • id
  • color
  • km

and the color and km fields will hold the ID's of the property's row in the Properies table.

EDIT: if you're planning not to use mysql db , you might consider using XML files to contain the properties data. But once again, you should update its count value anytime you add / remove or update a car.

<Properties>
 <Property>
  <Type>Color</Type>
  <Value>White</Value>
  <Count>1000</Count>
 </Property>
</Properties>

Upvotes: -1

Related Questions