Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow hotlinking to searches in results page. #141

Open
bmschmidt opened this issue Dec 13, 2021 · 0 comments
Open

Allow hotlinking to searches in results page. #141

bmschmidt opened this issue Dec 13, 2021 · 0 comments

Comments

@bmschmidt
Copy link
Contributor

Issue from code4lib discussions. The idea is that the search UI can look at the hash so that https://minicomp.github.io/wax/search/#Qatar opens up a search directly to items matching the string "#Qatar".

Happy to have this assigned to me if it's desirable.

One question is whether entering a search should also update the hash dynamically as well.

function startSearchUI(fields, indexFile, url) {
  $.getJSON(indexFile, function(store) {
    var index  = new elasticlunr.Index;

    index.saveDocument(false);
    index.setRef('lunr_id');

    for (i in fields) { index.addField(fields[i]); }
    for (i in store)  { index.addDoc(store[i]); }

    function run_search(terms) {
      var results_div = $('#results');
      var query       = terms
      var results     = index.search(query, { boolean: 'AND', expand: true });

      results_div.empty();
      results_div.append(`<p class="results-info">Displaying ${results.length} results</p>`);

      for (var r in results) {
        var ref    = results[r].ref;
        var item   = store[ref];
        var result = displayResult(item, fields, url);

        results_div.append(result);
      }
    }
    if (window.location.hash) {
      var search = decodeURIComponent(window.location.hash.slice(1);
      $('input#search').val(search) // Is this how you assign in jquery?
      run_search(search)
    }
    $('input#search').on('keyup', function() {
      var query       = $(this).val();
      run_search(query)
      }
    });
  });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

2 participants