Skip to content
Permalink
Browse files

Support for search result switch buttons with JavaScript disabled

  • Loading branch information...
luccioman committed Mar 9, 2019
1 parent ebc583c commit 74fd2f30faa60a94ca87244807fe60a943625439
Showing with 161 additions and 31 deletions.
  1. +108 −31 htroot/yacysearchtrailer.html
  2. +53 −0 htroot/yacysearchtrailer.java
@@ -43,40 +43,117 @@
#(/resource-select)#

<p class="navbutton"></p>
<div id="rankingButtons" class="btn-group btn-group-justified" data-nav-generation="#[nav-generation]#">
<!-- data-nav-generation attribute helps the browser know whether the search navigators have to be refreshed -->
<div class="btn-group btn-group-xs">
<button type="button" id="sort_button_context" class="btn btn-default" title="Use the default ranking profile (customizable), ordering results by score."
onclick="document.getElementById('search').value=document.getElementById('search').value.replace(' /date','');document.searchform.submit();">Context Ranking</button>
</div>
<div class="btn-group btn-group-xs">
<button type="button" id="sort_button_date" class="btn btn-default" title="Use the 'Date' ranking profile, ordering results by default on each document last modification date."
onclick="document.getElementById('search').value=document.getElementById('search').value + ' /date';document.searchform.submit();">Sort by Date</button>
</div>
</div>
<script>
if (document.getElementById('search').value.indexOf(" /date") == -1) {
document.getElementById("sort_button_context").setAttribute("class","btn btn-default active");
document.getElementById("sort_button_context").setAttribute("onclick","");
} else {
document.getElementById("sort_button_date").setAttribute("class","btn btn-default active");
document.getElementById("sort_button_date").setAttribute("onclick","");
}
</script>
<form action="yacysearch.html" method="get" accept-charset="UTF-8" name="rankingSwitchForm">
#(authSearch)#::
<input type="hidden" name="auth" value=""/>
#(/authSearch)#
<input type="hidden" name="contentdom" value="#[contentdom]#" />
<input type="hidden" name="strictContentDom" value="#[strictContentDom]#" />
<input type="hidden" name="former" value="#[former]#" />
<input type="hidden" name="maximumRecords" value="#[maximumRecords]#" />
<input type="hidden" name="startRecord" value="#[startRecord]#" />
<input type="hidden" name="verify" value="#[search.verify]#" />
<input type="hidden" name="resource" value="#[resource]#" />
<input type="hidden" name="nav" value="#[search.navigation]#" />
<input type="hidden" name="prefermaskfilter" value="#[prefermaskfilter]#" />
<input type="hidden" name="depth" value="#[depth]#" />
<input type="hidden" name="constraint" value="#[constraint]#" />
<input type="hidden" name="meanCount" value="#[meanCount]#" />
<input id="contentDomTimezoneOffset" type="hidden" name="timezoneOffset" value=""><script>document.getElementById("contentDomTimezoneOffset").value = new Date().getTimezoneOffset();</script>
<div id="rankingButtons" class="btn-group btn-group-justified" data-nav-generation="#[nav-generation]#">
<!-- data-nav-generation attribute helps the browser know whether the search navigators have to be refreshed -->
<div class="btn-group btn-group-xs">
<button type="#(contextRanking)#submit::button#(/contextRanking)#" class="btn btn-default#(contextRanking)#:: active#(/contextRanking)#"
title="Use the default ranking profile (customizable), ordering results by score."
#(contextRanking)#name="query" value="#[formerWithoutDate]#" onclick="this.value=document.getElementById('search').value.replace(' /date','');"::#(/contextRanking)#>Context Ranking</button>
</div>
<div class="btn-group btn-group-xs">
<button type=#(dateRanking)#submit::button#(/dateRanking)# class="btn btn-default#(dateRanking)#:: active#(/dateRanking)#"
title="Use the 'Date' ranking profile, ordering results by default on each document last modification date."
#(dateRanking)#name="query" value="#[former]# /date" onclick="this.value=document.getElementById('search').value + ' /date';"::#(/dateRanking)#>Sort by Date</button>
</div>
</div>
</form>

#(searchdomswitches)#::<p class="navbutton"></p>
<div class="btn-group btn-group-justified">
#(searchtext)#::<div class="btn-group btn-group-xs"><button type="button" class="btn btn-default#(check)#:: active#(/check)#"#(check)# onclick="document.getElementById('contentdom').value='text';document.searchform.submit();"::#(/check)#>Documents</button></div>#(/searchtext)#
#(searchimage)#::<div class="btn-group btn-group-xs"><button type="button" class="btn btn-default#(check)#:: active#(/check)#"#(check)# onclick="document.getElementById('contentdom').value='image';document.searchform.submit();"::#(/check)#>Images</button></div>#(/searchimage)#
#(searchaudio)#::<div class="btn-group btn-group-xs"><button type="button" class="btn btn-default#(check)#:: active#(/check)#"#(check)# onclick="document.getElementById('contentdom').value='audio';document.searchform.submit();"::#(/check)#>Audio</button></div>#(/searchaudio)#
#(searchvideo)#::<div class="btn-group btn-group-xs"><button type="button" class="btn btn-default#(check)#:: active#(/check)#"#(check)# onclick="document.getElementById('contentdom').value='video';document.searchform.submit();"::#(/check)#>Video</button></div>#(/searchvideo)#
#(searchapp)#::<div class="btn-group btn-group-xs"><button type="button" class="btn btn-default#(check)#:: active#(/check)#"#(check)# onclick="document.getElementById('contentdom').value='app';document.searchform.submit();"::#(/check)#>Apps</button></div>#(/searchapp)#
</div>
<form action="yacysearch.html" method="get" accept-charset="UTF-8" name="contentdomSwitchForm"
onsubmit="document.getElementById('contentdomSwitchFormQuery').value = document.getElementById('search').value;">
<input type="hidden" id="contentdomSwitchFormQuery" name="query" value="#[former]#"/>
#(authSearch)#::
<input type="hidden" name="auth" value=""/>
#(/authSearch)#
<input type="hidden" name="strictContentDom" value="#[strictContentDom]#" />
<input type="hidden" name="former" value="#[former]#" />
<input type="hidden" name="maximumRecords" value="#[maximumRecords]#" />
<input type="hidden" name="startRecord" value="#[startRecord]#" />
<input type="hidden" name="verify" value="#[search.verify]#" />
<input type="hidden" name="resource" value="#[resource]#" />
<input type="hidden" name="nav" value="#[search.navigation]#" />
<input type="hidden" name="prefermaskfilter" value="#[prefermaskfilter]#" />
<input type="hidden" name="depth" value="#[depth]#" />
<input type="hidden" name="constraint" value="#[constraint]#" />
<input type="hidden" name="meanCount" value="#[meanCount]#" />
<input id="contentDomTimezoneOffset" type="hidden" name="timezoneOffset" value=""><script>document.getElementById("contentDomTimezoneOffset").value = new Date().getTimezoneOffset();</script>
<div class="btn-group btn-group-justified">
#(searchtext)#::<div class="btn-group btn-group-xs">
<button type="#(check)#submit::button#(/check)#" name="contentdom" value="text"
class="btn btn-default#(check)#:: active#(/check)#">Documents</button>
</div>
#(/searchtext)#
#(searchimage)#::<div class="btn-group btn-group-xs">
<button type="#(check)#submit::button#(/check)#" name="contentdom" value="image"
class="btn btn-default#(check)#:: active#(/check)#">Images</button>
</div>
#(/searchimage)#
#(searchaudio)#::<div class="btn-group btn-group-xs">
<button type="#(check)#submit::button#(/check)#" name="contentdom" value="audio"
class="btn btn-default#(check)#:: active#(/check)#">Audio</button>
</div>
#(/searchaudio)#
#(searchvideo)#::<div class="btn-group btn-group-xs">
<button type="#(check)#submit::button#(/check)#" name="contentdom" value="video"
class="btn btn-default#(check)#:: active#(/check)#">Video</button>
</div>
#(/searchvideo)#
#(searchapp)#::<div class="btn-group btn-group-xs">
<button type="#(check)#submit::button#(/check)#" name="contentdom" value="app"
class="btn btn-default#(check)#:: active#(/check)#">Apps</button>
</div>
#(/searchapp)#
</div>
</form>
#(strictContentDomSwitch)#::
<div class="btn-group btn-group-justified">
<div class="btn-group btn-group-xs"><button type="button" title="Extend media search results to pages including such medias (provides generally more results, but eventually less relevant)" class="btn btn-default#(strictContentDom)# active::#(/strictContentDom)#" #(strictContentDom)#::onclick="document.getElementById('strictContentDom').value='false';document.searchform.submit();"#(/strictContentDom)#>Extended</button></div>
<div class="btn-group btn-group-xs"><button type="button" title="Strictly limit media search results to indexed documents matching exactly the desired content domain." class="btn btn-default#(strictContentDom)#:: active#(/strictContentDom)#" #(strictContentDom)#onclick="document.getElementById('strictContentDom').value='true';document.searchform.submit();"::#(/strictContentDom)#>Strict</button></div>
</div>
<form action="yacysearch.html" method="get" accept-charset="UTF-8" name="strictContentdomSwitchForm"
onsubmit="document.getElementById('strictContentdomSwitchFormQuery').value = document.getElementById('search').value;">
<input type="hidden" id="strictContentdomSwitchFormQuery" name="query" value="#[former]#"/>
#(authSearch)#::
<input type="hidden" name="auth" value=""/>
#(/authSearch)#
<input type="hidden" name="contentdom" value="#[contentdom]#" />
<input type="hidden" name="former" value="#[former]#" />
<input type="hidden" name="maximumRecords" value="#[maximumRecords]#" />
<input type="hidden" name="startRecord" value="#[startRecord]#" />
<input type="hidden" name="verify" value="#[search.verify]#" />
<input type="hidden" name="resource" value="#[resource]#" />
<input type="hidden" name="nav" value="#[search.navigation]#" />
<input type="hidden" name="prefermaskfilter" value="#[prefermaskfilter]#" />
<input type="hidden" name="depth" value="#[depth]#" />
<input type="hidden" name="constraint" value="#[constraint]#" />
<input type="hidden" name="meanCount" value="#[meanCount]#" />
<input id="contentDomTimezoneOffset" type="hidden" name="timezoneOffset" value=""><script>document.getElementById("contentDomTimezoneOffset").value = new Date().getTimezoneOffset();</script>
<div class="btn-group btn-group-justified">
<div class="btn-group btn-group-xs">
<button type="#(strictContentDom)#button::submit#(/strictContentDom)#" name="strictContentDom" value="false"
title="Extend media search results to pages including such medias (provides generally more results, but eventually less relevant)"
class="btn btn-default#(strictContentDom)# active::#(/strictContentDom)#">Extended</button>
</div>
<div class="btn-group btn-group-xs">
<button type="#(strictContentDom)#submit::button#(/strictContentDom)#" name="strictContentDom" value="true"
title="Strictly limit media search results to indexed documents matching exactly the desired content domain."
class="btn btn-default#(strictContentDom)#:: active#(/strictContentDom)#">Strict</button>
</div>
</div>
</form>
#(/strictContentDomSwitch)#
#(/searchdomswitches)#

@@ -32,6 +32,7 @@
import net.yacy.cora.date.AbstractFormatter;
import net.yacy.cora.document.analysis.Classification.ContentDomain;
import net.yacy.cora.document.id.MultiProtocolURL;
import net.yacy.cora.federate.yacy.CacheStrategy;
import net.yacy.cora.lod.vocabulary.Tagging;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.sorting.ScoreMap;
@@ -43,6 +44,7 @@
import net.yacy.search.EventTracker;
import net.yacy.search.Switchboard;
import net.yacy.search.SwitchboardConstants;
import net.yacy.search.index.Segment;
import net.yacy.search.navigator.Navigator;
import net.yacy.search.navigator.NavigatorSortDirection;
import net.yacy.search.navigator.NavigatorSortType;
@@ -112,6 +114,25 @@ public static serverObjects respond(final RequestHeader header, final serverObje
|| sb.getConfigBool("search.video", true)
|| sb.getConfigBool("search.image", true)
|| sb.getConfigBool("search.app", true) ? 1 : 0);

final String originalquerystring = post.get("query", post.get("search", "")).trim();
final String former = originalquerystring.replaceAll(Segment.catchallString, "*");
final CacheStrategy snippetFetchStrategy = CacheStrategy.parse(post.get("verify", sb.getConfig("search.verify", "")));
final String snippetFetchStrategyName = snippetFetchStrategy == null
? sb.getConfig("search.verify", CacheStrategy.IFFRESH.toName())
: snippetFetchStrategy.toName();
final int startRecord = post.getInt("startRecord", post.getInt("offset", post.getInt("start", 0)));
/* Maximum number of suggestions to display in the first results page */
final int meanMax = post.getInt("meanCount", 0);

appendSearchFormValues("", post, prop, global, theSearch, former, snippetFetchStrategyName, startRecord, meanMax);
prop.put("contextRanking", !former.contains(" /date"));
prop.put("contextRanking_formerWithoutDate", former.replace(" /date", ""));
prop.put("dateRanking", former.contains(" /date"));
prop.put("dateRanking_former", former);

appendSearchFormValues("searchdomswitches_", post, prop, global, theSearch, former, snippetFetchStrategyName, startRecord, meanMax);

prop.put("searchdomswitches_searchtext", sb.getConfigBool("search.text", true) ? 1 : 0);
prop.put("searchdomswitches_searchaudio", sb.getConfigBool("search.audio", true) ? 1 : 0);
prop.put("searchdomswitches_searchvideo", sb.getConfigBool("search.video", true) ? 1 : 0);
@@ -122,6 +143,8 @@ public static serverObjects respond(final RequestHeader header, final serverObje
prop.put("searchdomswitches_searchvideo_check", (contentdom == ContentDomain.VIDEO) ? "1" : "0");
prop.put("searchdomswitches_searchimage_check", (contentdom == ContentDomain.IMAGE) ? "1" : "0");
prop.put("searchdomswitches_searchapp_check", (contentdom == ContentDomain.APP) ? "1" : "0");

appendSearchFormValues("searchdomswitches_strictContentDomSwitch_", post, prop, global, theSearch, former, snippetFetchStrategyName, startRecord, meanMax);
prop.put("searchdomswitches_strictContentDomSwitch", (contentdom != ContentDomain.TEXT && contentdom != ContentDomain.ALL) ? 1 : 0);
prop.put("searchdomswitches_strictContentDomSwitch_strictContentDom", theSearch.getQuery().isStrictContentDom() ? 1 : 0);

@@ -448,6 +471,36 @@ public static serverObjects respond(final RequestHeader header, final serverObje
return prop;
}

/**
* Append search input fields values to the prop object. All parameters are required and must not be null.
* @param templatePrefix the template prefix to append before each template key
* @param post request parameters
* @param prop the servlet answer object to be filled
* @param global when true the search scope is blobal (not limited to this peer local index)
* @param theSearch the search object
* @param former the previous search terms
* @param snippetFetchStrategyName the snippet fetching strategy name to apply
* @param startRecord the zero based index of the first record to return
* @param meanMax the maximum number of suggestions ("Did you mean") to propose
*/
private static void appendSearchFormValues(final String templatePrefix, final serverObjects post, final serverObjects prop,
boolean global, final SearchEvent theSearch, final String former, final String snippetFetchStrategyName,
final int startRecord, final int meanMax) {
prop.putHTML(templatePrefix + "former", former);
prop.put(templatePrefix + "authSearch", post.containsKey("auth"));
prop.put(templatePrefix + "contentdom", post.get("contentdom", "text"));
prop.put(templatePrefix + "strictContentDom", String.valueOf(theSearch.getQuery().isStrictContentDom()));
prop.put(templatePrefix + "maximumRecords", theSearch.getQuery().itemsPerPage);
prop.put(templatePrefix + "startRecord", startRecord);
prop.put(templatePrefix + "search.verify", snippetFetchStrategyName);
prop.put(templatePrefix + "resource", global ? "global" : "local");
prop.put(templatePrefix + "search.navigation", post.get("nav", "all"));
prop.putHTML(templatePrefix + "prefermaskfilter", theSearch.getQuery().prefer.pattern());
prop.put(templatePrefix + "depth", "0");
prop.put(templatePrefix + "constraint", (theSearch.getQuery().constraint == null) ? "" : theSearch.getQuery().constraint.exportB64());
prop.put(templatePrefix + "meanCount", meanMax);
}

}
//http://localhost:8090/yacysearch.html?query=java+&amp;maximumRecords=10&amp;resource=local&amp;verify=cacheonly&amp;nav=hosts,authors,namespace,topics,filetype,protocol&amp;urlmaskfilter=ftp://.*&amp;prefermaskfilter=&amp;constraint=&amp;contentdom=text&amp;former=java+%2Fftp&amp;startRecord=0
//http://localhost:8090/yacysearch.html?query=java+&amp;maximumRecords=10&amp;resource=local&amp;verify=cacheonly&amp;nav=hosts,authors,namespace,topics,filetype,protocol&amp;urlmaskfilter=.*&amp;prefermaskfilter=&amp;constraint=&amp;contentdom=text&amp;former=java+%2Fvocabulary%2FGewerke%2FTore&amp;startRecord=0

0 comments on commit 74fd2f3

Please sign in to comment.
You can’t perform that action at this time.