documentcloud/visualsearch — pull request #136 by golubev (2014-05-15 10:48:44+00:00)
Title: Refactored and fixed SearchInput view - added `addFacet` method.

__Added `addFacet` method to the `SearchInput`__ (see a comment above the function definition):
https://github.com/golubev/visualsearch/blob/master/lib/js/views/search_input.js#L94

__Fixed colon (`:`) logic.__ See:
https://github.com/golubev/visualsearch/blob/master/lib/js/views/search_input.js#L357
E.g. try to type "qwerty filter" using the current master (http://documentcloud.github.io/visualsearch/demo.html) and then type the colon - nothing happens. The fix that is proposed allows VisualSearch to add "qwerty" as a remainder and "filter" - as a facet in this case.

__Fixed tab logic.__ See:
https://github.com/golubev/visualsearch/blob/master/lib/js/views/search_input.js#L393
Current master allows to add any facet that is not in the list of facets, provided in the `facetMatches` callback. E.g. type "qwerty" and then press the tab button - a new facet with a category "qwerty" will be added, but "qwerty" is not in the list of available facets.
Or another strange behaviour is observed: type "qwerty city", then press the "down arrow" button (to deselect autocomplete menu - to fire exactly this event, but not the autocomplete's `select` callback) and then press the tab button - "TEXT: qwerty city" will be added.
Proposed fix adds the same logic to this event as when typing the colon. Providing the same input in this fixed version will lead to the same logic as described above: "qwerty" as a remainder and a category "locality" (`value` for "city" - there are some details in the next paragraph) - as a facet.

__Fixed facets `value` and `label` autocomplete items properties usage.__ To see search "label" through the https://github.com/golubev/visualsearch/blob/master/lib/js/views/search_input.js. The main point is that:
- when we add a new facet we use `facetToAdd.value || facetToAdd.label || facetToAdd` for the category - as the jQuery's autocomplete puts `value` into the input when selected something;
- when user types we match his input against `facetToAdd.label || facetToAdd.value || facetToAdd` - as the `label` is the text that one can see in the autocomplete's dropdown menu. So it seems to me that user will try to input smth. like the label. See: https://github.com/golubev/visualsearch/blob/master/demo.html#L446