ivaynberg/select2 — pull request #1465 by geophree (2013-06-26 21:38:20+00:00)
Title: Always call createSearchChoice and tokenizer with the Select2 object as this.

Giving ```createSearchChoice``` access to the Select2 object allows me to filter my created search choices based on both the results from a query and from the currently selected choices (the current selection isn't easily accessed when ```createSearchChoice``` is called to generate a search query result):
```javascript
function createTagSearchChoice(term, results) {
var lowerTerm = term.toLowerCase();
var data = this.data();
if (data && data.length) {
results = results.concat(data);
}
var $matchingdata = $(results).filter(function() {
return 0 === this.id.toLowerCase().localeCompare(lowerTerm);
});

if (0 !== $matchingdata.length) {
return null;
}

return {id: term, count: 0};
}
```

One other thing to consider is that ```createSearchChoice``` is called somewhat inconsistently currently. It is sometimes passed ```.data()``` and sometimes the result of a query. It would probably break old code, but it might be worth passing the query results and the current ```.data()``` as separate parameters: ```createSearchChoice(term, queryResults, currentSelections)```