Schwad / PorkCasts-Montana

http://www.porkcast.com/
0 stars 0 forks source link

Fix Autosuggest #24

Open Schwad opened 8 years ago

Schwad commented 8 years ago

Under Queries/New View there is this chunk of Javascript in a JS tag:

<%= javascript_tag do %>
  $("body .animation-while-load").click(function(){
    $(".page-wrap").append("<div class='load-animation'><img src='/assets/ajax-loader-b98f0466a81ba5642c9bafbc00964f0e559945a4ec996a165d2179d03bd5e8ca.gif' alt='Ajax loader b98f0466a81ba5642c9bafbc00964f0e559945a4ec996a165d2179d03bd5e8ca' /></div>");
    console.log("click!");
  });

  $(window).keyup(function() {
    $(".match-big").html("");
    var myData = $("#query_content").val();
    $.ajax( {
      url: "http://www.porkcast.com/tags.json",
      data: { value: myData },
      type: "GET",
      dataType : "json",
      success: function( json ) {
        if($("#query_content").val().length > 2) {
        var myIterator = 1;
          json.forEach(function(tag){
            if(myIterator < 11){
              $(".match-big").append("<div class=" + "'possible-match'" + ">" + tag + "</div>");
              myIterator++;
              console.log(myIterator);
            }
          });
          $("body .possible-match").click(function(){
            $this = this;
            console.log($this.textContent);
            $("#query_content").val($this.textContent);
            console.log("click!");
          });
        }
       },
      error: function( xhr, status, errorThrown ) { console.log("error!"); },
      complete: function( xhr, status ) { console.log("complete!"); }
    });
  });

<% end %>

There's a few issues here. First, the JS UI Autocomplete would normally work here but it only works for activerecord objects. One solution could include turning the tags json file into a DB of Tags; now that I have 10,000,000 room I could save 100-200k "tag"s as objects, which would make it easier to upgrade as well.

Autosuggest uses a database of bulk payees from 6 months ago which needs occasional updates.

Schwad commented 8 years ago

Oh yeah baby, now that we have 10,000,000 rows we can TOTALLY do it like this. http://www.sitepoint.com/awesome-autocomplete-trigram-search-in-rails-and-postgresql/