From e3e4f06be42e64b0d17930fa6b2e0471a073c6dd Mon Sep 17 00:00:00 2001 From: orbiter Date: Wed, 12 Dec 2007 14:18:42 +0000 Subject: [PATCH] enhanced search result preparation in the case that no result is found (fast abandon of search) git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4273 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- .../de/anomic/plasma/plasmaSearchEvent.java | 60 +++++++++++-------- .../de/anomic/plasma/plasmaSearchQuery.java | 4 +- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/source/de/anomic/plasma/plasmaSearchEvent.java b/source/de/anomic/plasma/plasmaSearchEvent.java index 80a91ac5a..4da48ab65 100644 --- a/source/de/anomic/plasma/plasmaSearchEvent.java +++ b/source/de/anomic/plasma/plasmaSearchEvent.java @@ -210,7 +210,7 @@ public final class plasmaSearchEvent { while ((rankedCache.size() > 0) && ((uentry = rankedCache.bestURL(true)) != null) && (resultList.size() < (query.neededResults()))) { url = uentry.comp().url(); if (url == null) continue; - System.out.println("***DEBUG*** SEARCH RESULT URL=" + url.toNormalform(false, false)); + //System.out.println("***DEBUG*** SEARCH RESULT URL=" + url.toNormalform(false, false)); resultEntry = obtainResultEntry(uentry, (snippetComputationAllTime < 300) ? 1 : 0); if (resultEntry == null) continue; // the entry had some problems, cannot be used @@ -389,7 +389,9 @@ public final class plasmaSearchEvent { private boolean anyWorkerAlive() { if (this.workerThreads == null) return false; for (int i = 0; i < workerThreadCount; i++) { - if ((this.workerThreads[i] != null) && (this.workerThreads[i].isAlive())) return true; + if ((this.workerThreads[i] != null) && + (this.workerThreads[i].isAlive()) && + (this.workerThreads[i].busytime() < 3000)) return true; } return false; } @@ -401,7 +403,7 @@ public final class plasmaSearchEvent { if ((this.primarySearchThreads[i] != null) && (this.primarySearchThreads[i].isAlive())) return true; } } - // maybe a secondary search thread is alivem check this + // maybe a secondary search thread is alive, check this if ((this.secondarySearchThreads != null) && (this.secondarySearchThreads.length != 0)) { for (int i = 0; i < this.secondarySearchThreads.length; i++) { if ((this.secondarySearchThreads[i] != null) && (this.secondarySearchThreads[i].isAlive())) return true; @@ -494,26 +496,29 @@ public final class plasmaSearchEvent { private long timeout; // the date until this thread should try to work private long sleeptime; // the sleeptime of this thread at the beginning of its life + private long lastLifeSign; // when the last time the run()-loop was executed private int id; - public resultWorker(int id, long lifetime) { + public resultWorker(int id, long maxlifetime) { this.id = id; - this.timeout = System.currentTimeMillis() + lifetime; - this.sleeptime = lifetime / 10 * id; + this.lastLifeSign = System.currentTimeMillis(); + this.timeout = System.currentTimeMillis() + maxlifetime; + this.sleeptime = Math.min(300, maxlifetime / 10 * id); } public void run() { - // sleep first to give remote loading threads a chance to fetch entries - if (anyRemoteSearchAlive()) try {Thread.sleep(this.sleeptime);} catch (InterruptedException e1) {} - // start fetching urls and snippets indexURLEntry page; while (System.currentTimeMillis() < this.timeout) { - + this.lastLifeSign = System.currentTimeMillis(); + + if (resultList.size() >= query.neededResults() + query.displayResults()) break; // we have enough + // get next entry page = rankedCache.bestURL(true); if (page == null) { + if (!anyRemoteSearchAlive()) break; // we cannot expect more results // if we did not get another entry, sleep some time and try again try {Thread.sleep(100);} catch (InterruptedException e1) {} continue; @@ -542,6 +547,9 @@ public final class plasmaSearchEvent { //System.out.println("DEBUG SNIPPET_LOADING: thread " + id + " got " + resultEntry.url()); if (resultList.size() >= query.neededResults() + query.displayResults()) break; // we have enough + + // sleep first to give remote loading threads a chance to fetch entries + if (anyRemoteSearchAlive()) try {Thread.sleep(this.sleeptime);} catch (InterruptedException e1) {} } serverLog.logInfo("SEARCH", "resultWorker thread " + id + " terminated"); } @@ -556,6 +564,10 @@ public final class plasmaSearchEvent { private boolean anyFailureWith(String urlhash) { return (failedURLs.get(urlhash) != null); } + + public long busytime() { + return System.currentTimeMillis() - this.lastLifeSign; + } } private void registerFailure(String urlhash, String reason) { @@ -565,23 +577,19 @@ public final class plasmaSearchEvent { public ResultEntry oneResult(int item) { // first sleep a while to give accumulation threads a chance to work - long sleeptime = this.eventTime + (this.query.maximumTime / this.query.displayResults() * ((item % this.query.displayResults()) + 1)) - System.currentTimeMillis(); - if ((anyWorkerAlive()) && (sleeptime > 0)) { - try {Thread.sleep(sleeptime);} catch (InterruptedException e) {} - //System.out.println("+++DEBUG-oneResult+++ (1) sleeping " + sleeptime); - } - - // if there are less than 10 more results available, sleep some extra time to get a chance that the "common sense" ranking algorithm can work - if ((this.resultList.size() <= item + 10) && (anyWorkerAlive())) { - try {Thread.sleep(300);} catch (InterruptedException e) {} - //System.out.println("+++DEBUG-oneResult+++ (2) sleeping " + 300); - } - // then sleep until any result is available (that should not happen) - while ((this.resultList.size() <= item) && (anyWorkerAlive())) { - try {Thread.sleep(100);} catch (InterruptedException e) {} - //System.out.println("+++DEBUG-oneResult+++ (3) sleeping " + 100); + if (anyWorkerAlive()) { + long sleeptime = Math.min(600, this.eventTime + (this.query.maximumTime / this.query.displayResults() * ((item % this.query.displayResults()) + 1)) - System.currentTimeMillis()); + if (this.resultList.size() <= item + 10) sleeptime = Math.min(sleeptime + 300, 600); + if (sleeptime > 0) try {Thread.sleep(sleeptime);} catch (InterruptedException e) {} + System.out.println("+++DEBUG-oneResult+++ (1) sleeping " + sleeptime); + + // then sleep until any result is available (that should not happen) + while ((this.resultList.size() <= item) && (anyWorkerAlive())) { + try {Thread.sleep(100);} catch (InterruptedException e) {} + System.out.println("+++DEBUG-oneResult+++ (2) sleeping " + 100); + } + } - // finally, if there is something, return the result synchronized (this.resultList) { // check if we have enough entries diff --git a/source/de/anomic/plasma/plasmaSearchQuery.java b/source/de/anomic/plasma/plasmaSearchQuery.java index a19fbc8a0..e0fad1858 100644 --- a/source/de/anomic/plasma/plasmaSearchQuery.java +++ b/source/de/anomic/plasma/plasmaSearchQuery.java @@ -105,7 +105,7 @@ public final class plasmaSearchQuery { this.contentdom = CONTENTDOM_ALL; this.linesPerPage = lines; this.offset = 0; - this.maximumTime = 10000; + this.maximumTime = 3000; this.urlMask = ".*"; this.domType = SEARCHDOM_LOCAL; this.domGroupName = ""; @@ -128,7 +128,7 @@ public plasmaSearchQuery(String queryString, TreeSet queryHashes, TreeSet exclud this.contentdom = contentdom; this.linesPerPage = lines; this.offset = offset; - this.maximumTime = maximumTime; + this.maximumTime = Math.min(6000, maximumTime); this.urlMask = urlMask; this.domType = domType; this.domGroupName = domGroupName;