I am using http://jsfiddle.net/dhoerster/BXYpt/ from jQuery UI autocomplete with values as the basis. This does exactly what I need, except that I need to have OR conditions. I created a fiddle as a demo:
http://jsfiddle.net/B8bWX/1/
My problem is this: the demonstration elements are a car, a telephone, and a car with a telephone. Is there a way to make autocomplete handle three cases: the line contains the case (default), followed by the ANDed case, and finally the OR case? Therefore, if I enter the "Car Phone", this will lead to:
1) the first case - 0 results, because Car Phone is not a substring of any of the labels.
2) the second case - 1 result, because βCarβ and βPhoneβ appear in βCar with phoneβ. This is added to the list below 0 previous results.
3) the third case - two more results are displayed, because the labels "Car" and "Phone" contain at least one of the search elements. These results appear below the previous results of steps 1 and 2, so now you should select the selection box below:
Car with telephone
Car
Phone (an order for a car and a phone does not really matter, since they are both equally correct)
Here is the javascript in the question:
$(document).ready(function() { $( "#topics" ).autocomplete({ minLength: 1, source: topics, focus: function( event, ui ) { $( "#topics" ).val( ui.item.label ); return false; }, select: function( event, ui ) { $( "#topics" ).val( ui.item.label ); $("#topicID").val(ui.item.id); $( "#results").text($("#topicID").val()); return false; } }) });
So one could do it in order:
1) string.contains (default)
2) string split -> AND condition
3) string split β OR condition (there is no preference for sorting by the number of contained terms)