Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

enhanced search speed: - better control of number of running search threads - no time-out waiting time when no ranking feeding takes place - local search queries by a remote peer may be faster up to 300 milliseconds - a local search may even be faster

orbiter97ee2789317a
diff --git a/htroot/IndexControlRWIs_p.java b/htroot/IndexControlRWIs_p.java
index dc28051db..36c31f1f9 100644
--- a/htroot/IndexControlRWIs_p.java
+++ b/htroot/IndexControlRWIs_p.java
@@ -402,7 +402,7 @@ public class IndexControlRWIs_p {
URIMetadataRow entry;
String us;
long rn = -1;
- while (!ranked.isEmpty() && (entry = ranked.takeURL(false, 60000)) != null) {
+ while (!ranked.isEmpty() && (entry = ranked.takeURL(false, 1000)) != null) {
if ((entry == null) || (entry.metadata() == null)) continue;
url = entry.metadata().url();
if (url == null) continue;
diff --git a/source/de/anomic/search/DocumentIndex.java b/source/de/anomic/search/DocumentIndex.java
index 4658b7993..7ccd754c0 100644
--- a/source/de/anomic/search/DocumentIndex.java
+++ b/source/de/anomic/search/DocumentIndex.java
@@ -178,15 +178,21 @@ public class DocumentIndex extends Segment {
/**
* do a full-text search of a given string and return a specific number of results
* @param querystring
- * @param pos
* @param count
* @return a list of files that contain the given string
*/
- public ArrayList<DigestURI> find(String querystring, int pos, int count) {
- ArrayList<URIMetadataRow> result = findMetadata(querystring, this);
+ public ArrayList<DigestURI> find(String querystring, int count) {
+ // make a query and start a search
+ QueryParams query = new QueryParams(querystring, count, null, this, textRankingDefault);
+ ReferenceOrder order = new ReferenceOrder(query.ranking, query.targetlang);
+ RankingProcess rankedCache = new RankingProcess(query, order, SearchEvent.max_results_preparation, 1);
+ rankedCache.start();
+
+ // search is running; retrieve results
+ URIMetadataRow row;
ArrayList<DigestURI> files = new ArrayList<DigestURI>();
Components metadata;
- for (URIMetadataRow row : result) {
+ while ((row = rankedCache.takeURL(false, 1000)) != null) {
metadata = row.metadata();
if (metadata == null) continue;
files.add(metadata.url());
@@ -195,35 +201,6 @@ public class DocumentIndex extends Segment {
}
return files;
}
-
- public static final ArrayList<URIMetadataRow> findMetadata(
- final String querystring,
- final Segment indexSegment) {
- QueryParams query = new QueryParams(querystring, 100, null, indexSegment, textRankingDefault);
- ReferenceOrder order = new ReferenceOrder(query.ranking, query.targetlang);
- return findMetadata(query, order);
- }
-
- public static final ArrayList<URIMetadataRow> findMetadata(final QueryParams query, final ReferenceOrder order) {
-
- RankingProcess rankedCache = new RankingProcess(query, order, SearchEvent.max_results_preparation, 2);
- rankedCache.run();
-
- ArrayList<URIMetadataRow> result = new ArrayList<URIMetadataRow>();
- URIMetadataRow r;
- while ((r = rankedCache.takeURL(false, 100)) != null) result.add(r);
-
- return result;
- }
-
- /**
- * find the given string and return 20 hits
- * @param querystring
- * @return a list of files that contain the word
- */
- public ArrayList<DigestURI> find(String querystring) {
- return find(querystring, 0, 100);
- }
/**
* close the index.
@@ -282,7 +259,7 @@ public class DocumentIndex extends Segment {
for (int i = 2; i < args.length; i++) query += args[i];
query.trim();
DocumentIndex di = new DocumentIndex(segmentPath, callback, 100000);
- ArrayList<DigestURI> results = di.find(query);
+ ArrayList<DigestURI> results = di.find(query, 100);
for (DigestURI f: results) {
if (f != null) System.out.println(f.toString());
}
diff --git a/source/de/anomic/search/RankingProcess.java b/source/de/anomic/search/RankingProcess.java
index 0eb9c1e88..fc692cd4b 100644
--- a/source/de/anomic/search/RankingProcess.java
+++ b/source/de/anomic/search/RankingProcess.java
@@ -283,7 +283,8 @@ public final class RankingProcess extends Thread {
WeakPriorityBlockingQueue<ReverseElement<WordReferenceVars>> m;
ReverseElement<WordReferenceVars> rwi;
try {
- while ((rwi = stack.poll(timeout)) != null) {
+ //System.out.println("feeders = " + this.feeders);
+ while ((rwi = stack.poll((this.feedingIsFinished()) ? 0 : timeout)) != null) {
if (!skipDoubleDom) return rwi;
// check doubledom
diff --git a/source/de/anomic/search/SearchEvent.java b/source/de/anomic/search/SearchEvent.java
index 91dcf95fa..5fa072f50 100644
--- a/source/de/anomic/search/SearchEvent.java
+++ b/source/de/anomic/search/SearchEvent.java
@@ -154,7 +154,7 @@ public final class SearchEvent {
this.results = new ResultFetcher(loader, rankedCache, query, peers, 3000);
} else {
// do a local search
- this.rankedCache = new RankingProcess(this.query, this.order, max_results_preparation, 2);
+ this.rankedCache = new RankingProcess(this.query, this.order, max_results_preparation, 1);
this.rankedCache.run(); // this is not started concurrently here on purpose!
if (generateAbstracts) {
diff --git a/source/de/anomic/search/Segment.java b/source/de/anomic/search/Segment.java
index 4622b2225..5e6409379 100644
--- a/source/de/anomic/search/Segment.java
+++ b/source/de/anomic/search/Segment.java
@@ -207,6 +207,8 @@ public class Segment {
final int outlinksOther,
final SearchEvent searchEvent,
final String sourceName) {
+ RankingProcess rankingProcess = (searchEvent == null) ? null : searchEvent.getRankingResult();
+ if (rankingProcess != null) rankingProcess.moreFeeders(1);
int wordCount = 0;
final int urlLength = url.toNormalform(true, true).length();
final int urlComps = MultiProtocolURI.urlComps(url.toString()).length;
@@ -248,10 +250,10 @@ public class Segment {
} catch (RowSpaceExceededException e) {
continue;
}
- searchEvent.getRankingResult().add(container, false, sourceName, -1);
+ rankingProcess.add(container, false, sourceName, -1);
}
}
-
+ if (rankingProcess != null) rankingProcess.oneFeederTerminated();
return wordCount;
}
diff --git a/source/net/yacy/cora/storage/WeakPriorityBlockingQueue.java b/source/net/yacy/cora/storage/WeakPriorityBlockingQueue.java
index e637c24c9..e50db77d2 100644
--- a/source/net/yacy/cora/storage/WeakPriorityBlockingQueue.java
+++ b/source/net/yacy/cora/storage/WeakPriorityBlockingQueue.java
@@ -127,10 +127,12 @@ public class WeakPriorityBlockingQueue<E> {
* return the element with the smallest weight and remove it from the stack
* @return null if no element is on the queue or the head of the queue
*/
- public synchronized E poll() {
- if (this.queue.isEmpty()) return null;
- this.enqueued.tryAcquire();
- return takeUnsafe();
+ public E poll() {
+ boolean a = this.enqueued.tryAcquire();
+ if (!a) return null;
+ synchronized (this) {
+ return takeUnsafe();
+ }
}
/**
@@ -141,7 +143,7 @@ public class WeakPriorityBlockingQueue<E> {
* @throws InterruptedException
*/
public E poll(long timeout) throws InterruptedException {
- boolean a = this.enqueued.tryAcquire(timeout, TimeUnit.MILLISECONDS);
+ boolean a = (timeout <= 0) ? this.enqueued.tryAcquire() : this.enqueued.tryAcquire(timeout, TimeUnit.MILLISECONDS);
if (!a) return null;
synchronized (this) {
return takeUnsafe();
diff --git a/source/net/yacy/kelondro/table/SplitTable.java b/source/net/yacy/kelondro/table/SplitTable.java
index 6eac4e067..540681cb8 100644
--- a/source/net/yacy/kelondro/table/SplitTable.java
+++ b/source/net/yacy/kelondro/table/SplitTable.java
@@ -363,15 +363,15 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
*/
public boolean put(final Row.Entry row) throws IOException, RowSpaceExceededException {
assert row.objectsize() <= this.rowdef.objectsize;
- Index keeper = keeperOf(row.getColBytes(0, true));
- if (keeper != null) return keeper.put(row);
synchronized (this.tables) {
+ Index keeper = keeperOf(row.getColBytes(0, true));
+ if (keeper != null) return keeper.put(row);
assert this.current == null || this.tables.get(this.current) != null : "this.current = " + this.current;
keeper = (this.current == null) ? newTable() : checkTable(this.tables.get(this.current));
+ boolean b = keeper.put(row);
+ assert b;
+ return b;
}
- boolean b = keeper.put(row);
- assert b;
- return b;
}