Commit 0c11cdcc authored by Alain Takoudjou's avatar Alain Takoudjou

Mynij Search: description in search result hax maximum 250 characters

Fix search form also
parent 8f574152
......@@ -13,9 +13,11 @@
</div>
<div id="search_div">
<form id="search_bar">
<input type="search" id="search_input" required>
</form>
<input type="search" id="search_input" name="search" value>
<select id="select_index"></select>
<button class="search-button ui-btn-icon-notext ui-icon-search" type="submit">
</button>
</form>
</div>
<div id="gadget_result" data-gadget-url="gadget_mynij_result.html"
data-gadget-scope="result" data-gadget-sandbox="public"></div>
......
......@@ -88,8 +88,13 @@
})
.declareJob("clear", function () {
var gadget = this;
this.element.querySelector("#search_input").value = "";
return this.state.result_gadget.clear();
return this.state.result_gadget.clear()
.push(function () {
document.getElementById("logo-search").classList.remove('hide');
return gadget.state.result_gadget.hideResultBox();
});
})
.declareJob("defer_search", function (search_text, index, limit) {
......@@ -97,7 +102,7 @@
top = document.getElementById("logo-search");
if(top) {
gadget.element.removeChild(top);
top.classList.add("hide");
}
return gadget.state.result_gadget.startLoading()
.push(function () {
......@@ -175,7 +180,7 @@
var error_html;
error_html = document.createElement("p");
error_html.className = "no-result";
error_html.textContent = "AN error occured, please try again. " +
error_html.textContent = "An error occured, please try again. " +
error.message || '';
return gadget.state.result_gadget.show_searx_result(error_html);
})
......
......@@ -98,7 +98,7 @@
index_id = "index-" + index_name,
new_index;
new_index = FlexSearch.create("memory", {stemmer : "en", filter : "en"});
new_index = FlexSearch.create("memory", {stemmer : "en", filter : "en", encode: "icase"});
return gadget.state.db.getAttachment(index_id, "ids", {"format": "text"})
.push(function (result) {
ids = result;
......
......@@ -13,6 +13,13 @@
box.classList.remove("hide");
}
})
.declareMethod("hideResultBox", function () {
var box = document.getElementById("results");
if (!box.classList.contains("hide")) {
box.classList.add("hide");
}
})
.declareMethod("startLoading", function () {
var loader;
......@@ -143,23 +150,62 @@
key_list = key.split(' '),
search_key = key;
function extract_description(description) {
var regex,
max_length = 250,
start,
end,
count = 0,
i;
description = description.replace(/[\t\r\n]+/g, '')
.replace(/ +(?= )/g, '');
if (description.length <= max_length)
return description;
regex = new RegExp('(' + search_key + ')', 'i').exec(description);
if (regex !== null) {
start = regex.index;
end = start + regex[0].length;
i = start;
while (i > 0 && count < 10) {
if (description[i] === ' ') {
count += 1;
start = i + 1;
}
i -= 1;
}
if (i === 0)
start = 0;
end = max_length + start;
if (end > description.length)
end = description.length;
return description.slice(start, end) + "...";
}
return description;
}
if (key_list.length > 0)
search_key = [key].concat(key_list).join("|");
result = new RegExp(
'[^;?.?!]*\s?(' + search_key + ')\s?[^.?!]*[.?!]', 'i').exec(body);
'[^;?.?!]*\\s?(' + search_key + ')\\s?[^.?!]*[.?!]', 'i').exec(body);
if (result === null) {
//if (description !== "") return description; else....
result = new RegExp('[^.?!]*[.?!]').exec(body);
if (result === null) return "";
else return result[0];
if (result === null)
return "";
else
return result[0];
}
else return result[0];
else
return extract_description(result[0]);
})
.declareMethod("cut_link", function (link) {
if (link === undefined) return "";
if (link.length > 70) return link.slice(0, 70) + "...";
else return link;
if (link === undefined)
return "";
if (link.length > 70)
return link.slice(0, 70) + "...";
else
return link;
});
}(window, RSVP, rJS, document, DOMParser));
\ No newline at end of file
......@@ -6,10 +6,16 @@
#search_bar {
width: 100%;
padding-right: 1%;
display: inline-flex;
}
.search-button {
margin-left: 10px;
}
#select_index {
width: 20%;
max-width: 20%;
margin-left: 5px;
}
.search {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment