From af25c98306c8887fc599d9ceb5314cfb7368f8c4 Mon Sep 17 00:00:00 2001 From: orbiter Date: Fri, 28 Sep 2007 01:36:22 +0000 Subject: [PATCH] enhanced local search performance in case of a remote search: there is no waiting until the local search terminates to show the result page. the local search appear like all other results from remote peers using a separated thread. This has especially a stron effect, if the local index for a specific word is large. git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4114 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- .../de/anomic/plasma/plasmaSearchEvent.java | 102 ++++++++++-------- 1 file changed, 58 insertions(+), 44 deletions(-) diff --git a/source/de/anomic/plasma/plasmaSearchEvent.java b/source/de/anomic/plasma/plasmaSearchEvent.java index 6acef49a7..d3267a919 100644 --- a/source/de/anomic/plasma/plasmaSearchEvent.java +++ b/source/de/anomic/plasma/plasmaSearchEvent.java @@ -64,6 +64,7 @@ public final class plasmaSearchEvent { private Map rcAbstracts; // cache for index abstracts; word:TreeMap mapping where the embedded TreeMap is a urlhash:peerlist relation private plasmaSearchProcessing process; private yacySearch[] primarySearchThreads, secondarySearchThreads; + private Thread localSearchThread; private TreeMap preselectedPeerHashes; //private Object[] references; public TreeMap IAResults, IACount; @@ -145,50 +146,8 @@ public final class plasmaSearchEvent { process.yield("remote search thread start", this.primarySearchThreads.length); // meanwhile do a local search - Map[] searchContainerMaps = process.localSearchContainers(query, wordIndex, null); - - // use the search containers to fill up rcAbstracts locally - /* - if ((rcAbstracts != null) && (searchContainerMap != null)) { - Iterator i, ci = searchContainerMap.entrySet().iterator(); - Map.Entry entry; - String wordhash; - indexContainer container; - TreeMap singleAbstract; - String mypeerhash = yacyCore.seedDB.mySeed.hash; - while (ci.hasNext()) { - entry = (Map.Entry) ci.next(); - wordhash = (String) entry.getKey(); - container = (indexContainer) entry.getValue(); - // collect all urlhashes from the container - synchronized (rcAbstracts) { - singleAbstract = (TreeMap) rcAbstracts.get(wordhash); // a mapping from url-hashes to a string of peer-hashes - if (singleAbstract == null) singleAbstract = new TreeMap(); - i = container.entries(); - while (i.hasNext()) singleAbstract.put(((indexEntry) i.next()).urlHash(), mypeerhash); - rcAbstracts.put(wordhash, singleAbstract); - } - } - } - */ - - // join and exlcude the local result - indexContainer rcLocal = - (searchContainerMaps == null) ? - plasmaWordIndex.emptyContainer(null, 0) : - process.localSearchJoinExclude( - searchContainerMaps[0].values(), - searchContainerMaps[1].values(), - query.maxDistance); - this.localcount = rcLocal.size(); - - // sort the local containers and truncate it to a limited count, - // so following sortings together with the global results will be fast - plasmaSearchPreOrder firstsort = new plasmaSearchPreOrder(query, process, ranking, rcLocal); - rcLocal = firstsort.strippedContainer(200); - synchronized (rankedCache) { - this.rankedCache.insert(rcLocal, true, true); - } + localSearchThread = new localSearchProcess(); + localSearchThread.start(); // finished searching serverLog.logFine("SEARCH_EVENT", "SEARCH TIME AFTER GLOBAL-TRIGGER TO " + primarySearchThreads.length + " PEERS: " + ((System.currentTimeMillis() - start) / 1000) + " seconds"); @@ -289,6 +248,61 @@ public final class plasmaSearchEvent { lastEvents.put(query.id(), this); lastEventID = query.id(); } + + + private class localSearchProcess extends Thread { + + public localSearchProcess() { + } + + public void run() { + // do a local search + Map[] searchContainerMaps = process.localSearchContainers(query, wordIndex, null); + + // use the search containers to fill up rcAbstracts locally + /* + if ((rcAbstracts != null) && (searchContainerMap != null)) { + Iterator i, ci = searchContainerMap.entrySet().iterator(); + Map.Entry entry; + String wordhash; + indexContainer container; + TreeMap singleAbstract; + String mypeerhash = yacyCore.seedDB.mySeed.hash; + while (ci.hasNext()) { + entry = (Map.Entry) ci.next(); + wordhash = (String) entry.getKey(); + container = (indexContainer) entry.getValue(); + // collect all urlhashes from the container + synchronized (rcAbstracts) { + singleAbstract = (TreeMap) rcAbstracts.get(wordhash); // a mapping from url-hashes to a string of peer-hashes + if (singleAbstract == null) singleAbstract = new TreeMap(); + i = container.entries(); + while (i.hasNext()) singleAbstract.put(((indexEntry) i.next()).urlHash(), mypeerhash); + rcAbstracts.put(wordhash, singleAbstract); + } + } + } + */ + + // join and exlcude the local result + indexContainer rcLocal = + (searchContainerMaps == null) ? + plasmaWordIndex.emptyContainer(null, 0) : + process.localSearchJoinExclude( + searchContainerMaps[0].values(), + searchContainerMaps[1].values(), + query.maxDistance); + localcount = rcLocal.size(); + + // sort the local containers and truncate it to a limited count, + // so following sortings together with the global results will be fast + plasmaSearchPreOrder firstsort = new plasmaSearchPreOrder(query, process, ranking, rcLocal); + rcLocal = firstsort.strippedContainer(200); + synchronized (rankedCache) { + rankedCache.insert(rcLocal, true, true); + } + } + } private static void cleanupEvents() { // remove old events in the event cache