cebe / js-search

A client side search engine for use on static pages.
http://cebe.github.io/js-search/#demo
MIT License
140 stars 25 forks source link

Search results no longer include delimiter pipe #6

Open r0ckarong opened 7 years ago

r0ckarong commented 7 years ago

My page titles are build like

Product Version | Section | Topic

Until some recent change which I can not fathom the search result would look like that. Now the search result is only "Topic".

I'm trying to find out if your indexer does something different.

My implementation looks like this, pretty much the reference from your instructions:

Script insertion in the actual page template

  <!-- JS-Search -->
  <script src="<%= File.join(javascripts_path, "jssearch.js") %>" /></script>
  <script src="<%= File.join(javascripts_path, "jssearch.index.js") %>" /></script>

  <script type="text/javascript">
    $(document).on("keyup", "#searchbox", function() {
      var result = jssearch.search($(this).val());

      $('#query').html(jssearch.queryWords.join(' '));

      $('#results').html('');
      var i = 0;
      result.forEach(function(item) {
        if (i++ > 20) {
          return;
        }

        var div = $('#results');

        var version = "<%= version %>"
        var location = window.location.href;
        var pos = location.substr(0, location.search(version));
        var oerl = item.file.url;
        var clean = oerl.substr(2, oerl.length)

        div.html(div.html() + '<li>' + '<a href="' + pos + version + clean + '">' + item.file.title + '</a>' + '</li>');
      });
    });
  </script>

I've also updated to 0.9.3 and I see the same behavior.

cebe commented 7 years ago

Until some recent change which I can not fathom the search result would look like that.

there have not been significant changes to this package since 2014, are you sure its a problem with the code in this package?

r0ckarong commented 7 years ago

That is what I'm trying to debug. Suddenly the titles recorded into jssearch index no longer contain the longer notation with the pipes. Where does the indexer grab the title from and how is it processed?

cebe commented 7 years ago

https://github.com/cebe/js-search/blob/3756a8b3387f3f7e5c778b964ec681dcf110b098/lib/Indexer.php#L57-L71

cebe commented 7 years ago

have you added <h1> tags that were not present before?

r0ckarong commented 7 years ago

I did actually convert a previously h2 into an h1. So it takes the text from the first h1 it finds over the HTML <title> tag from what I can read? This would explain it.

r0ckarong commented 7 years ago

Ok yeah that was the cause. Ideally could you add an option to pass with the script that allows me to select if the first h1 or the actual tag is used?</p> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/cebe"><img src="https://avatars.githubusercontent.com/u/189796?v=4" />cebe</a> commented <strong> 7 years ago</strong> </div> <div class="markdown-body"> <p>I can add it but I do not have time for it right now. If you want to have it earlier I am happy to accept a pull request.</p> </div> </div> <div class="page-bar-simple"> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>