mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Revert back to vanilla search for now
This commit is contained in:
parent
aeef23f4d6
commit
3dbc1fa175
4 changed files with 3 additions and 128 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
sphinx==2.4.4
|
||||
sphinx-multiversion==0.1.1
|
||||
lunr==0.5.6
|
||||
# lunr==0.5.6
|
||||
|
||||
# recommonmark custom branch with evennia-specific fixes
|
||||
git+https://github.com/evennia/recommonmark.git@evennia-mods#egg=recommonmark
|
||||
|
|
|
|||
|
|
@ -1,95 +0,0 @@
|
|||
//
|
||||
// Using the pre-generated index file, set up a dynamic
|
||||
// search mechanims that returns quick suggestions of the
|
||||
// best matches you start to enter.
|
||||
//
|
||||
|
||||
var lunrIndex,
|
||||
$results,
|
||||
documents;
|
||||
|
||||
function initLunr() {
|
||||
// retrieve the index file
|
||||
$.getJSON("_static/js/lunr/search_index.json")
|
||||
.done(function(index) {
|
||||
|
||||
lunrIndex = lunr.Index.load(index)
|
||||
|
||||
// documents = index;
|
||||
|
||||
// lunrIndex = lunr(function(){
|
||||
// this.ref('url')
|
||||
// this.field('body')
|
||||
|
||||
// this.field("title", {
|
||||
// boost: 10
|
||||
// });
|
||||
|
||||
// documents.forEach(function(doc) {
|
||||
// try {
|
||||
// this.add(doc)
|
||||
// } catch (e) {}
|
||||
// }, this)
|
||||
// })
|
||||
})
|
||||
.fail(function(jqxhr, textStatus, error) {
|
||||
var err = textStatus + ", " + error;
|
||||
console.error("Error getting Lunr index file:", err);
|
||||
});
|
||||
}
|
||||
|
||||
function search(query) {
|
||||
return lunrIndex.search(query).map(function(result) {
|
||||
return documents.filter(function(page) {
|
||||
try {
|
||||
console.log(page)
|
||||
return page.href === result.ref;
|
||||
} catch (e) {
|
||||
console.log('Error in search. ' + e)
|
||||
}
|
||||
})[0];
|
||||
});
|
||||
}
|
||||
|
||||
function renderResults(results) {
|
||||
if (!results.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// show first ten results
|
||||
results.slice(0, 10).forEach(function(result) {
|
||||
var $result = $("<li>");
|
||||
|
||||
$result.append($("<a>", {
|
||||
href: result.url,
|
||||
text: "» " + result.title
|
||||
}));
|
||||
|
||||
$results.append($result);
|
||||
});
|
||||
}
|
||||
|
||||
function initUI() {
|
||||
$results = $("#lunrsearchresults");
|
||||
|
||||
$("#lunrsearch").keyup(function(){
|
||||
// empty previous results
|
||||
$results.empty();
|
||||
|
||||
// trigger search when at least two chars provided.
|
||||
var query = $(this).val();
|
||||
if (query.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
var results = search(query);
|
||||
|
||||
renderResults(results);
|
||||
});
|
||||
}
|
||||
|
||||
initLunr();
|
||||
|
||||
$(document).ready(function(){
|
||||
initUI();
|
||||
});
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
{#
|
||||
basic/searchbox.html
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Variant for lunrJS search
|
||||
|
||||
#}
|
||||
{%- if pagename != "search" and builder != "singlehtml" %}
|
||||
<div id="searchbox" style="display: none" role="search">
|
||||
<h3 id="searchlabel">{{ _('Quick search') }}</h3>
|
||||
<div class="searchformwrapper">
|
||||
<form class="search" action="{{ pathto('search') }}" method="get">
|
||||
<input type="text" name="q" aria-labelledby="searchlabel" />
|
||||
<input type="submit" value="{{ _('Go') }}" />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script>$('#searchbox').show(0);</script>
|
||||
{%- endif %}
|
||||
|
||||
{#
|
||||
|
||||
Lunr indexed quick search
|
||||
|
||||
#}
|
||||
<p><input id="lunrsearch" type="text" placeholder="type something here"></p>
|
||||
<ul id="lunrsearchresults"></ul>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
|
||||
<script src="https://unpkg.com/lunr/lunr.js"></script>
|
||||
<script src="_static/js/lunr/search.js"></script>
|
||||
|
|
@ -61,7 +61,8 @@ extensions = [
|
|||
"sphinx_multiversion",
|
||||
"sphinx.ext.napoleon",
|
||||
"sphinx.ext.autosectionlabel",
|
||||
"sphinx.ext.viewcode"
|
||||
"sphinx.ext.viewcode",
|
||||
# "sphinxcontrib.lunrsearch",
|
||||
]
|
||||
|
||||
# make sure sectionlabel references can be used as path/to/file:heading
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue