mirror of https://github.com/perkeep/perkeep.git
Merge "search UI: find all roots"
This commit is contained in:
commit
fca3f33449
|
@ -337,6 +337,7 @@ func (x *Index) PermanodeOfSignerAttrValue(signer *blobref.BlobRef, attr, val st
|
|||
}
|
||||
|
||||
// This is just like PermanodeOfSignerAttrValue except we return multiple and dup-suppress.
|
||||
// If request.Query is "", it is not used in the prefix search.
|
||||
func (x *Index) SearchPermanodesWithAttr(dest chan<- *blobref.BlobRef, request *search.PermanodeByAttrRequest) (err error) {
|
||||
defer close(dest)
|
||||
if request.FuzzyMatch {
|
||||
|
@ -355,7 +356,13 @@ func (x *Index) SearchPermanodesWithAttr(dest chan<- *blobref.BlobRef, request *
|
|||
return err
|
||||
}
|
||||
seen := make(map[string]bool)
|
||||
it := x.queryPrefix(keySignerAttrValue, keyId, request.Attribute, request.Query)
|
||||
var it *prefixIter
|
||||
// TODO(mpl): test this case in particular when making a test for that method.
|
||||
if request.Query == "" {
|
||||
it = x.queryPrefix(keySignerAttrValue, keyId, request.Attribute)
|
||||
} else {
|
||||
it = x.queryPrefix(keySignerAttrValue, keyId, request.Attribute, request.Query)
|
||||
}
|
||||
defer closeIterator(it, &err)
|
||||
for it.Next() {
|
||||
pn := blobref.Parse(it.Value())
|
||||
|
|
|
@ -195,7 +195,7 @@ func (sh *Handler) servePermanodesWithAttr(rw http.ResponseWriter, req *http.Req
|
|||
defer setPanicError(ret)
|
||||
|
||||
signer := blobref.MustParse(mustGet(req, "signer"))
|
||||
value := mustGet(req, "value")
|
||||
value := req.FormValue("value")
|
||||
fuzzy := req.FormValue("fuzzy") // exact match if empty
|
||||
fuzzyMatch := false
|
||||
if fuzzy != "" {
|
||||
|
|
|
@ -119,6 +119,8 @@ type PermanodeByAttrRequest struct {
|
|||
|
||||
// The attribute value to find exactly (or roughly, if
|
||||
// FuzzyMatch is set)
|
||||
// If blank, the permanodes with Attribute as an attribute
|
||||
// (set to any value) are searched.
|
||||
Query string
|
||||
|
||||
FuzzyMatch bool // by default, an exact match is required
|
||||
|
@ -153,6 +155,9 @@ type Index interface {
|
|||
// In particular, if request.FuzzyMatch is true, a fulltext
|
||||
// search is performed (if supported by the attribute(s))
|
||||
// instead of an exact match search.
|
||||
// If request.Query is blank, the permanodes which have
|
||||
// request.Attribute as an attribute (regardless of its value)
|
||||
// are searched.
|
||||
// Additionally, if request.Attribute is blank, all attributes
|
||||
// are searched (as fulltext), otherwise the search is
|
||||
// restricted to the named attribute.
|
||||
|
|
|
@ -13,6 +13,11 @@
|
|||
|
||||
<h1>Search</h1>
|
||||
|
||||
<h2>Find all roots</h2>
|
||||
<form id="formRoots">
|
||||
<input type="submit" id="btnRoots" value="Search">
|
||||
</form>
|
||||
|
||||
<h2>In all attributes</h2>
|
||||
<form id="formAnyAttr">
|
||||
<input id="inputAnyAttr" placeholder="attrValue1">
|
||||
|
|
|
@ -20,15 +20,9 @@ function getSearchParams() {
|
|||
CamliSearch.query = "";
|
||||
CamliSearch.type = "";
|
||||
CamliSearch.fuzzy = "";
|
||||
CamliSearch.query = getQueryParam('q');
|
||||
CamliSearch.type = getQueryParam('t');
|
||||
CamliSearch.fuzzy = getQueryParam('f');
|
||||
if (CamliSearch.type == null) {
|
||||
CamliSearch.type = "";
|
||||
}
|
||||
if (CamliSearch.fuzzy == null) {
|
||||
CamliSearch.fuzzy = "";
|
||||
}
|
||||
CamliSearch.query = getQueryParam('q') || "";
|
||||
CamliSearch.type = getQueryParam('t') || "";
|
||||
CamliSearch.fuzzy = getQueryParam('f') || "";
|
||||
}
|
||||
|
||||
function hideAllResThings() {
|
||||
|
@ -38,6 +32,13 @@ function hideAllResThings() {
|
|||
CamliSearch.formAddToCollec.style.visibility = 'hidden';
|
||||
}
|
||||
|
||||
function handleFormGetRoots(e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
document.location.href = "search.html?&t=camliRoot"
|
||||
}
|
||||
|
||||
function handleFormGetTagged(e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
@ -97,8 +98,13 @@ function doSearch() {
|
|||
case "title":
|
||||
camliGetPermanodesWithAttr(sigconf.publicKeyBlobRef, "title", CamliSearch.query, "true", tagcb);
|
||||
break;
|
||||
case "camliRoot":
|
||||
camliGetPermanodesWithAttr(sigconf.publicKeyBlobRef, "camliRoot", CamliSearch.query, "false", tagcb);
|
||||
break;
|
||||
case "":
|
||||
camliGetPermanodesWithAttr(sigconf.publicKeyBlobRef, "", CamliSearch.query, "true", tagcb);
|
||||
if (CamliSearch.query !== "") {
|
||||
camliGetPermanodesWithAttr(sigconf.publicKeyBlobRef, "", CamliSearch.query, "true", tagcb);
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
@ -146,16 +152,18 @@ function showPermanodes(searchRes, type) {
|
|||
if (results.length > 0) {
|
||||
switch(type) {
|
||||
case "tag":
|
||||
CamliSearch.titleRes.innerHTML = "Tagged with \"";
|
||||
CamliSearch.titleRes.innerHTML = "Tagged with \"" + CamliSearch.query + "\"";
|
||||
break;
|
||||
case "title":
|
||||
CamliSearch.titleRes.innerHTML = "Titled with \"";
|
||||
CamliSearch.titleRes.innerHTML = "Titled with \"" + CamliSearch.query + "\"";
|
||||
break;
|
||||
case "camliRoot":
|
||||
CamliSearch.titleRes.innerHTML = "All roots";
|
||||
break;
|
||||
case "":
|
||||
CamliSearch.titleRes.innerHTML = "General search for \"";
|
||||
CamliSearch.titleRes.innerHTML = "General search for \"" + CamliSearch.query + "\"";
|
||||
break;
|
||||
}
|
||||
CamliSearch.titleRes.innerHTML += CamliSearch.query + "\"";
|
||||
CamliSearch.titleRes.style.visibility = 'visible';
|
||||
CamliSearch.btnNewCollec.disabled = false;
|
||||
CamliSearch.btnNewCollec.style.visibility = 'visible';
|
||||
|
@ -246,6 +254,8 @@ function addToCollection(createNew) {
|
|||
|
||||
function indexOnLoad(e) {
|
||||
|
||||
var formRoots = document.getElementById("formRoots");
|
||||
formRoots.addEventListener("submit", handleFormGetRoots);
|
||||
var formTags = document.getElementById("formTags");
|
||||
formTags.addEventListener("submit", handleFormGetTagged);
|
||||
var formTitles = document.getElementById("formTitles");
|
||||
|
@ -259,9 +269,7 @@ function indexOnLoad(e) {
|
|||
CamliSearch.formAddToCollec.addEventListener("submit", handleAddToCollection);
|
||||
hideAllResThings();
|
||||
getSearchParams();
|
||||
if (CamliSearch.query != "") {
|
||||
doSearch();
|
||||
}
|
||||
doSearch();
|
||||
}
|
||||
|
||||
window.addEventListener("load", indexOnLoad);
|
||||
|
|
|
@ -20,6 +20,11 @@ func init() {
|
|||
"\n"+
|
||||
" <h1>Search</h1>\n"+
|
||||
"\n"+
|
||||
" <h2>Find all roots</h2>\n"+
|
||||
" <form id=\"formRoots\">\n"+
|
||||
" <input type=\"submit\" id=\"btnRoots\" value=\"Search\">\n"+
|
||||
" </form>\n"+
|
||||
"\n"+
|
||||
" <h2>In all attributes</h2>\n"+
|
||||
" <form id=\"formAnyAttr\">\n"+
|
||||
" <input id=\"inputAnyAttr\" placeholder=\"attrValue1\">\n"+
|
||||
|
@ -51,5 +56,5 @@ func init() {
|
|||
"\n"+
|
||||
"</body>\n"+
|
||||
"</html>\n"+
|
||||
"", time.Unix(0, 1330389504169976807))
|
||||
"", time.Unix(0, 1352847761019584970))
|
||||
}
|
||||
|
|
|
@ -27,15 +27,9 @@ func init() {
|
|||
" CamliSearch.query = \"\";\n"+
|
||||
" CamliSearch.type = \"\";\n"+
|
||||
" CamliSearch.fuzzy = \"\";\n"+
|
||||
" CamliSearch.query = getQueryParam('q');\n"+
|
||||
" CamliSearch.type = getQueryParam('t');\n"+
|
||||
" CamliSearch.fuzzy = getQueryParam('f');\n"+
|
||||
" if (CamliSearch.type == null) {\n"+
|
||||
" CamliSearch.type = \"\";\n"+
|
||||
" }\n"+
|
||||
" if (CamliSearch.fuzzy == null) {\n"+
|
||||
" CamliSearch.fuzzy = \"\";\n"+
|
||||
" }\n"+
|
||||
" CamliSearch.query = getQueryParam('q') || \"\";\n"+
|
||||
" CamliSearch.type = getQueryParam('t') || \"\";\n"+
|
||||
" CamliSearch.fuzzy = getQueryParam('f') || \"\";\n"+
|
||||
"}\n"+
|
||||
"\n"+
|
||||
"function hideAllResThings() {\n"+
|
||||
|
@ -45,6 +39,13 @@ func init() {
|
|||
" CamliSearch.formAddToCollec.style.visibility = 'hidden';\n"+
|
||||
"}\n"+
|
||||
"\n"+
|
||||
"function handleFormGetRoots(e) {\n"+
|
||||
" e.stopPropagation();\n"+
|
||||
" e.preventDefault();\n"+
|
||||
"\n"+
|
||||
" document.location.href = \"search.html?&t=camliRoot\"\n"+
|
||||
"}\n"+
|
||||
"\n"+
|
||||
"function handleFormGetTagged(e) {\n"+
|
||||
" e.stopPropagation();\n"+
|
||||
" e.preventDefault();\n"+
|
||||
|
@ -106,9 +107,15 @@ func init() {
|
|||
" camliGetPermanodesWithAttr(sigconf.publicKeyBlobRef, \"title\", CamliSearch.quer"+
|
||||
"y, \"true\", tagcb);\n"+
|
||||
" break;\n"+
|
||||
" case \"camliRoot\":\n"+
|
||||
" camliGetPermanodesWithAttr(sigconf.publicKeyBlobRef, \"camliRoot\", CamliSearch."+
|
||||
"query, \"false\", tagcb);\n"+
|
||||
" break;\n"+
|
||||
" case \"\":\n"+
|
||||
" camliGetPermanodesWithAttr(sigconf.publicKeyBlobRef, \"\", CamliSearch.query, \"t"+
|
||||
"rue\", tagcb);\n"+
|
||||
" if (CamliSearch.query !== \"\") {\n"+
|
||||
" camliGetPermanodesWithAttr(sigconf.publicKeyBlobRef, \"\", CamliSearch.query, \""+
|
||||
"true\", tagcb);\n"+
|
||||
" }\n"+
|
||||
" break;\n"+
|
||||
" }\n"+
|
||||
" };\n"+
|
||||
|
@ -156,16 +163,19 @@ func init() {
|
|||
" if (results.length > 0) {\n"+
|
||||
" switch(type) {\n"+
|
||||
" case \"tag\":\n"+
|
||||
" CamliSearch.titleRes.innerHTML = \"Tagged with \\\"\";\n"+
|
||||
" CamliSearch.titleRes.innerHTML = \"Tagged with \\\"\" + CamliSearch.query + \"\\\"\";\n"+
|
||||
" break;\n"+
|
||||
" case \"title\":\n"+
|
||||
" CamliSearch.titleRes.innerHTML = \"Titled with \\\"\";\n"+
|
||||
" CamliSearch.titleRes.innerHTML = \"Titled with \\\"\" + CamliSearch.query + \"\\\"\";\n"+
|
||||
" break;\n"+
|
||||
" case \"camliRoot\":\n"+
|
||||
" CamliSearch.titleRes.innerHTML = \"All roots\";\n"+
|
||||
" break;\n"+
|
||||
" case \"\":\n"+
|
||||
" CamliSearch.titleRes.innerHTML = \"General search for \\\"\";\n"+
|
||||
" CamliSearch.titleRes.innerHTML = \"General search for \\\"\" + CamliSearch.query +"+
|
||||
" \"\\\"\";\n"+
|
||||
" break;\n"+
|
||||
" }\n"+
|
||||
" CamliSearch.titleRes.innerHTML += CamliSearch.query + \"\\\"\";\n"+
|
||||
" CamliSearch.titleRes.style.visibility = 'visible';\n"+
|
||||
" CamliSearch.btnNewCollec.disabled = false;\n"+
|
||||
" CamliSearch.btnNewCollec.style.visibility = 'visible';\n"+
|
||||
|
@ -257,6 +267,8 @@ func init() {
|
|||
"\n"+
|
||||
"function indexOnLoad(e) {\n"+
|
||||
"\n"+
|
||||
" var formRoots = document.getElementById(\"formRoots\");\n"+
|
||||
" formRoots.addEventListener(\"submit\", handleFormGetRoots);\n"+
|
||||
" var formTags = document.getElementById(\"formTags\");\n"+
|
||||
" formTags.addEventListener(\"submit\", handleFormGetTagged);\n"+
|
||||
" var formTitles = document.getElementById(\"formTitles\");\n"+
|
||||
|
@ -270,11 +282,9 @@ func init() {
|
|||
" CamliSearch.formAddToCollec.addEventListener(\"submit\", handleAddToCollection);\n"+
|
||||
" hideAllResThings();\n"+
|
||||
" getSearchParams();\n"+
|
||||
" if (CamliSearch.query != \"\") {\n"+
|
||||
" doSearch();\n"+
|
||||
" }\n"+
|
||||
" doSearch();\n"+
|
||||
"}\n"+
|
||||
"\n"+
|
||||
"window.addEventListener(\"load\", indexOnLoad);\n"+
|
||||
"", time.Unix(0, 1352107488430325498))
|
||||
"", time.Unix(0, 1352847747010347886))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue