- Search Term a: black small rock
- Search Term b: black rock small
- Search Term c: small rock black
I want to design a query that will take the order in which the terms are written into account. Now I’d like the above three terms to produce the same results, but I want order of the results to reflect the sequence of the terms.
I only hope this makes sense; please let me know if it doesn’t.
The only way I can see this working is if you are separating the search terms as attributes, in the database table, in those specific order.
In which case, the query for your first search term “black small rock” would match “black” in Attributes 1, 2, or 3 and then perform the same logical-or operation for the other two fields in the search term.
Your query, would actually be rather simple:
At which point, you rely on the logic in the programming language you are issuing this query from to order the displayed data by search term, where you test the first attribute (Python-like pseudocode):