Skip to content

Commit

Permalink
Merge pull request #674 from d7919/major/switch_from_tipue_to_lunr_fo…
Browse files Browse the repository at this point in the history
…r_search

Switch from tipue to lunr for search
  • Loading branch information
ZedThree authored Dec 18, 2024
2 parents 93e4c24 + 7335e3b commit 410011b
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 691 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Current features include:
arguments, derived types, programs, and modules from the source code.
- the ability to extract documentation from comments in the source code.
- LaTeX support in documentation using [MathJax](https://www.mathjax.org/).
- searchable documentation, using Tipue Search.
- searchable documentation, using [Lunr Search](https://lunrjs.com).
- author description and social media (including Github!) links.
- links to download the source code.
- links to individual files, both in their raw form or in HTML with syntax
Expand Down
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Current features include:
code,
- LaTeX support in documentation using `MathJax
<https://www.mathjax.org/>`__,
- searchable documentation, using `Tipue Search
<http://www.tipue.com/search/>`__,
- searchable documentation, using `Lunr Search
<https://lunrjs.com>`__,
- author description and social media (including Github!) links,
- links to download the source code,
- links to individual files, both in their raw form or in HTML with
Expand Down
2 changes: 1 addition & 1 deletion ford/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def writeout(self) -> None:
if self.data["graph"]:
self.graphs.output_graphs(self.njobs)
if self.data["search"]:
copytree(loc / "tipuesearch", out_dir / "tipuesearch")
copytree(loc / "search", out_dir / "search")
self.tipue.print_output()

try:
Expand Down
62 changes: 62 additions & 0 deletions ford/search/load_search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var items = tipuesearch['pages'];
var documents = tipuesearch["pages"]
var counter = 0

for (item in documents){
documents[item]['id'] = counter;
counter = counter +1;
}

var idx = lunr(function () {
this.ref('id')
this.field('title')
this.field('url')
this.field('text', { boost: 10 })
this.field('tags')

items.forEach(function (doc) {
this.add(doc)
}, this)
})

function lunr_search(term) {
document.getElementById('lunrsearchresults').innerHTML = '<ul></ul>';
if(term) {
document.getElementById('lunrsearchresults').innerHTML = "<p>Search results for '" + term + "'</p>" + document.getElementById('lunrsearchresults').innerHTML;
//put results on the screen.
var results = idx.search(term);
if(results.length>0){
//console.log(idx.search(term));
//if results
for (var i = 0; i < results.length; i++) {
// more statements
var ref = results[i]['ref'];
var url = documents[ref]['url'];
var title = documents[ref]['title'];
var body = documents[ref]['text'].substring(0,160)+'...';
document.querySelectorAll('#lunrsearchresults ul')[0].innerHTML = document.querySelectorAll('#lunrsearchresults ul')[0].innerHTML + "<li class='lunrsearchresult'><a href='" + url + "'><span class='title'>" + title + "</span></a><br /><span class='body'>"+ body +"</span><br /><span class='url'>"+ url +"</span></li>";
}
} else {
document.querySelectorAll('#lunrsearchresults ul')[0].innerHTML = "<li class='lunrsearchresult'>No results found...</li>";
}
}
return false;
}

function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split('&');

for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');

if (pair[0] === variable) {
return decodeURIComponent(pair[1].replace(/\+/g, '%20'));
}
}
}

var searchTerm = getQueryVariable('q');
if (searchTerm) {
lunr_search(searchTerm)
}
12 changes: 0 additions & 12 deletions ford/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@
<link href="{{ project_url }}/css/pygments.css" rel="stylesheet">
<link href="{{ project_url }}/css/font-awesome.min.css" rel="stylesheet">
<link href="{{ project_url }}/css/local.css" rel="stylesheet">
{% if search|lower == 'true' %}
<link href="{{ project_url }}/tipuesearch/tipuesearch.css" rel="stylesheet">
{% endif %}
{% if css %}
<link href="{{ project_url }}/css/user.css" rel="stylesheet">
{% endif %}

<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script src="{{ project_url }}/js/svg-pan-zoom.min.js"></script>
</head>

Expand Down Expand Up @@ -170,12 +165,5 @@
<script src="{{ project_url }}/js/MathJax-config/{{ path.basename(mathjax_config) }}"></script>
{% endif %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

{% if search|lower == 'true' %}
<script src="{{ project_url }}/tipuesearch/tipuesearch_content.js"></script>
<script src="{{ project_url }}/tipuesearch/tipuesearch_set.js"></script>
<script src="{{ project_url }}/tipuesearch/tipuesearch.js"></script>
{% endif %}

</body>
</html>
37 changes: 14 additions & 23 deletions ford/templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,19 @@
Search Results &ndash; {{ project }}
{% endblock %}
{% block body %}
<div class="row">
<div class="col-lg-12">
<h1>Search Results</h1>
<div id="tipue_search_content"><div id="tipue_search_loading"></div></div>
</div>
</div>
<!--
<script>
$(document).ready(function() {
$('#tipue_search_input').tipuesearch({
'mode' : 'static',
'show': 10,
'newWindow': false,
'descriptiveWords': 35,
});
});
</script>
-->
<script>
$(document).ready(function() {
$('#tipue_search_input').tipuesearch();
});
</script>
<div class="row">
<div class="col-lg-12">
<h1>Search Results</h1>
<div id="lunrsearchresults">
<ul></ul>
</div>
</div>
</div>

{% if search|lower == 'true' %}
<script src="https://unpkg.com/lunr/lunr.js"></script>
<script src="{{ project_url }}/search/search_database.json"></script>
<script src="{{ project_url }}/search/load_search.js"></script>
{% endif %}
{% endblock %}

5 changes: 2 additions & 3 deletions ford/tipue_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

from ford.settings import EntitySettings


class Tipue_Search_JSON_Generator:
def __init__(self, output_path: os.PathLike, project_url: str):
self.output_path = pathlib.Path(output_path)
Expand Down Expand Up @@ -89,13 +88,13 @@ def create_node(self, html, loc, meta: EntitySettings):
"title": page_title,
"text": page_text,
"tags": page_category,
"loc": str(page_url),
"url": str(page_url),
}

self.json_nodes.append(node)

def print_output(self):
path = self.output_path / "tipuesearch" / "tipuesearch_content.js"
path = self.output_path / "search" / "search_database.json"

root_node = {"pages": self.json_nodes}
output = json.dumps(root_node, separators=(",", ":"), ensure_ascii=False)
Expand Down
Binary file removed ford/tipuesearch/img/loader.gif
Binary file not shown.
Binary file removed ford/tipuesearch/img/search.png
Binary file not shown.
158 changes: 0 additions & 158 deletions ford/tipuesearch/tipuesearch.css

This file was deleted.

Loading

0 comments on commit 410011b

Please sign in to comment.