title: Jquery UI autocomplete selecting closest match
body: <p>I have an input field connected with Jquery ui autocomplete.
  This field is used for user to enter catalog number of device.
  He can do it in two ways:</p>
  
  <ul>
  <li>First. By writing it by hand and select one from autocomplete list </li>
  <li>or use barcode scanner for entering the catalog number</li>
  </ul>
  
  <p>Unfortunatelly Barcodes not always gives same answer as its printed on the device eq. There is printed : </p>
  
  <ul>
  <li><p>100-ENT/A but barcode returns 100-ENT/OA</p></li>
  <li><p>printed 156-CNR/B and barcode returns 156-CNR B</p></li>
  </ul>
  
  <p>So I want to select closest match from autocomplete.</p>
  
  <p>I know I can use this plugin for selecting the first one: <a href="http://dev.nemikor.com/jquery-ui-extensions/autocomplete/selectFirst.html" rel="nofollow">CLICK</a>
  but how to make it select the closest match?</p>
  
  <p>At this moment I'm stuck at clean code for loading autocomplete:</p>
  
  <pre><code>function GetNames() {
      var availableTags;
      var jsonData
      $.ajax({
          url: "/DeviceInstance/GetDeviceNames",
          type: "GET",
          dataType: "json",
          error: function (data) {
              alert("wystąpił nieokreślony błąd " + data);
          },
          success: function (data) {
              availableTags = data;
              $(".deviceCatalog").autocomplete({
                  source: availableTags,
                  change: function (event, ui) 
                  { 
                      viewModel.DeviceTemp(ui.item.id);
                  } 
              });
          }
      })
  
  };
  </code></pre>