added search suggestions for interactive search: is only shown if there are no search results

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7411 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent a4c9d27287
commit 0769f4caa6

@ -76,11 +76,11 @@ public class Crawler_p {
prop.put("loaderSize", 0);
prop.put("loaderMax", 0);
prop.put("list-loader", 0);
prop.put("localCrawlSize", 0);
prop.put("localCrawlSize", sb.crawlQueues.coreCrawlJobSize());
prop.put("localCrawlState", "");
prop.put("limitCrawlSize", 0);
prop.put("limitCrawlSize", sb.crawlQueues.limitCrawlJobSize());
prop.put("limitCrawlState", "");
prop.put("remoteCrawlSize", 0);
prop.put("remoteCrawlSize", sb.crawlQueues.limitCrawlJobSize());
prop.put("remoteCrawlState", "");
prop.put("list-remote", 0);
prop.put("forwardToCrawlStart", "0");

@ -23,6 +23,7 @@ import java.util.Iterator;
import net.yacy.cora.protocol.HeaderFramework;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.cora.protocol.ResponseHeader;
import net.yacy.kelondro.data.word.Word;
import de.anomic.data.DidYouMean;
import de.anomic.search.Segment;
@ -56,6 +57,7 @@ public class suggest {
final String ext = header.get("EXT", "");
final boolean json = ext.equals("json");
final boolean xml = ext.equals("xml");
final boolean more = post != null && post.containsKey("more");
// get query
String originalquerystring = (post == null) ? "" : post.get("query", post.get("q", "")).trim();
@ -75,19 +77,22 @@ public class suggest {
indexSegment = sb.indexSegments.segment(Segments.Process.PUBLIC);
}
DidYouMean didYouMean = new DidYouMean(indexSegment.termIndex(), querystring);
Iterator<String> meanIt = didYouMean.getSuggestions(timeout, count).iterator();
int c = 0;
String suggestion;
//[#[query]#,[#{suggestions}##[text]##(eol)#,::#(/eol)##{/suggestions}#]]
while (c < meanMax && meanIt.hasNext()) {
suggestion = meanIt.next();
if (json) prop.putJSON("suggestions_" + c + "_text", suggestion);
else if (xml) prop.putXML("suggestions_" + c + "_text", suggestion);
else prop.putHTML("suggestions_" + c + "_text", suggestion);
prop.put("suggestions_" + c + "_eol", 0);
c++;
if (more || !indexSegment.termIndex().has(Word.word2hash(querystring))) {
DidYouMean didYouMean = new DidYouMean(indexSegment.termIndex(), querystring);
Iterator<String> meanIt = didYouMean.getSuggestions(timeout, count).iterator();
String suggestion;
//[#[query]#,[#{suggestions}##[text]##(eol)#,::#(/eol)##{/suggestions}#]]
while (c < meanMax && meanIt.hasNext()) {
suggestion = meanIt.next();
if (json) prop.putJSON("suggestions_" + c + "_text", suggestion);
else if (xml) prop.putXML("suggestions_" + c + "_text", suggestion);
else prop.putHTML("suggestions_" + c + "_text", suggestion);
prop.put("suggestions_" + c + "_eol", 0);
c++;
}
}
if (c > 0) prop.put("suggestions_" + (c - 1) + "_eol", 1);
prop.put("suggestions", c);
if (json) prop.putJSON("query", originalquerystring);

@ -3,10 +3,33 @@
<head>
<title>YaCy Interactive Search</title>
#%env/templates/metas.template%#
<script src="/yacy/ui/js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript" src="/js/yacyinteractive.js"></script>
<script type="text/javascript" src="/js/sorttable.js"></script>
<link media="screen" type="text/css" href="/yacy/ui/css/autocomplete.css" rel="stylesheet" />
</head>
<body>
<script type="text/javascript" src="/yacy/ui/js/jquery.autocomplete.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#search').autocomplete('/suggest.json', {parse: opensearch, delay: 0, selectFirst: false, scroll: false, max: 30});
function opensearch(data) {
var parsed = [];
data = eval('({"suggest":' + data + '})');
for (var i = 0; i < data.suggest[1].length; i++) {
var row = data.suggest[1][i];
if (row) {
parsed[parsed.length] = {
data: [row],
value: row,
result: row
};
};
};
return parsed;
};
});
</script>
<script type="text/javascript">
//<![CDATA[
var q = "#[query]#";
@ -30,19 +53,22 @@ To see a list of all APIs, please visit the <a href="http://www.yacy-websuche.de
</div>
#%env/templates/simpleheader.template%#
#(/topmenu)#
<div style="float:left">
<div>
<form class="search small" id="searchform" action="yacyinteractive.html" method="get" onkeyup="xmlhttpPost(); return false;">
<h2>#[promoteSearchPageGreeting]#</h2>
<div class="yacylogo">
<a href="#[promoteSearchPageGreeting.homepage]#" class="yacylogo"><img src="#[promoteSearchPageGreeting.smallImage]#" alt="yacysearch"/></a>
</div>
<fieldset class="yacys"><input id="query" name="query" type="text" value="#[query]#" size="50" maxlength="80" /></fieldset>
<fieldset class="yacys">
<input id="search" name="query" type="text" value="#[query]#" size="50" maxlength="80" />
</fieldset>
<!--<pre>Raw JSON String: <div id="raw"></div></pre>-->
</form>
<div id="searchnavigation"></div>
</div>
<div id="downloadscript" style="float:left"></div>
<div id="searchresults" style="float:left"></div>
<!-- <div><img src="PerformanceGraph.png" id="graph" alt="PerformanceGraph" width="660" height="240"/></div> -->
<div id="downloadscript"></div>
<div id="searchresults"></div>
<script type="text/javascript">
//<![CDATA[
document.getElementById("query").focus();

@ -190,7 +190,7 @@ public class CrawlQueues {
}
public int coreCrawlJobSize() {
return noticeURL.stackSize(NoticedURL.StackType.CORE);
return noticeURL.stackSize(NoticedURL.StackType.CORE) + noticeURL.stackSize(NoticedURL.StackType.NOLOAD);
}
public boolean coreCrawlJob() {

@ -21,9 +21,19 @@
package de.anomic.search;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import net.yacy.kelondro.logging.Log;
import net.yacy.kelondro.util.DateFormatter;
import de.anomic.data.LibraryProvider;
public class AccessTracker {
public static final int minSize = 1000;
@ -34,6 +44,7 @@ public class AccessTracker {
private static LinkedList<QueryParams> localSearches = new LinkedList<QueryParams>();
private static LinkedList<QueryParams> remoteSearches = new LinkedList<QueryParams>();
private static ArrayList<String> log = new ArrayList<String>();
public static void add(Location location, QueryParams query) {
if (location == Location.local) synchronized (localSearches) {add(localSearches, query);}
@ -42,7 +53,9 @@ public class AccessTracker {
private static void add(LinkedList<QueryParams> list, QueryParams query) {
list.add(query);
while (list.size() > maxSize) list.removeFirst();
while (list.size() > maxSize) {
addToDump(list.removeFirst());
}
if (list.size() <= minSize) {
return;
}
@ -50,8 +63,10 @@ public class AccessTracker {
while (list.size() > 0) {
QueryParams q = list.getFirst();
if (q.time.longValue() > timeout) break;
list.removeFirst();
addToDump(list.removeFirst());
}
// learn that this word can be a word completion for the DidYouMeanLibrary
if (query.resultcount > 0 && query.queryString != null && query.queryString.length() > 0) LibraryProvider.dymLib.learn(query.queryString);
}
public static Iterator<QueryParams> get(Location location) {
@ -65,4 +80,36 @@ public class AccessTracker {
if (location == Location.remote) synchronized (remoteSearches) {return remoteSearches.size();}
return 0;
}
private static void addToDump(QueryParams query) {
//if (query.resultcount == 0) return;
if (query.queryString == null || query.queryString.length() == 0) return;
StringBuilder sb = new StringBuilder(40);
sb.append(DateFormatter.formatShortSecond());
sb.append(' ');
sb.append(Integer.toString(query.resultcount));
sb.append(' ');
sb.append(query.queryString);
log.add(sb.toString());
}
public static void dumpLog(File file) {
while (localSearches.size() > 0) {
addToDump(localSearches.removeFirst());
}
try {
RandomAccessFile raf = new RandomAccessFile(file, "rw");
raf.seek(raf.length());
for (String s: log) {
raf.write(s.getBytes("UTF-8"));
raf.writeByte(10);
}
log.clear();
} catch (FileNotFoundException e) {
Log.logException(e);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

@ -1195,6 +1195,7 @@ public final class Switchboard extends serverSwitch {
peers.close();
Cache.close();
tables.close();
AccessTracker.dumpLog(new File("DATA/LOG/queries.log"));
UPnP.deletePortMapping();
Tray.removeTray();
try {

Loading…
Cancel
Save