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

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7176 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 15 years ago
parent ee3820c9cc
commit 97ee278931

@ -402,7 +402,7 @@ public class IndexControlRWIs_p {
URIMetadataRow entry; URIMetadataRow entry;
String us; String us;
long rn = -1; 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; if ((entry == null) || (entry.metadata() == null)) continue;
url = entry.metadata().url(); url = entry.metadata().url();
if (url == null) continue; if (url == null) continue;

@ -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 * do a full-text search of a given string and return a specific number of results
* @param querystring * @param querystring
* @param pos
* @param count * @param count
* @return a list of files that contain the given string * @return a list of files that contain the given string
*/ */
public ArrayList<DigestURI> find(String querystring, int pos, int count) { public ArrayList<DigestURI> find(String querystring, int count) {
ArrayList<URIMetadataRow> result = findMetadata(querystring, this); // 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>(); ArrayList<DigestURI> files = new ArrayList<DigestURI>();
Components metadata; Components metadata;
for (URIMetadataRow row : result) { while ((row = rankedCache.takeURL(false, 1000)) != null) {
metadata = row.metadata(); metadata = row.metadata();
if (metadata == null) continue; if (metadata == null) continue;
files.add(metadata.url()); files.add(metadata.url());
@ -196,35 +202,6 @@ public class DocumentIndex extends Segment {
return files; 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. * close the index.
* This terminates all worker threads and then closes the segment. * This terminates all worker threads and then closes the segment.
@ -282,7 +259,7 @@ public class DocumentIndex extends Segment {
for (int i = 2; i < args.length; i++) query += args[i]; for (int i = 2; i < args.length; i++) query += args[i];
query.trim(); query.trim();
DocumentIndex di = new DocumentIndex(segmentPath, callback, 100000); DocumentIndex di = new DocumentIndex(segmentPath, callback, 100000);
ArrayList<DigestURI> results = di.find(query); ArrayList<DigestURI> results = di.find(query, 100);
for (DigestURI f: results) { for (DigestURI f: results) {
if (f != null) System.out.println(f.toString()); if (f != null) System.out.println(f.toString());
} }

@ -283,7 +283,8 @@ public final class RankingProcess extends Thread {
WeakPriorityBlockingQueue<ReverseElement<WordReferenceVars>> m; WeakPriorityBlockingQueue<ReverseElement<WordReferenceVars>> m;
ReverseElement<WordReferenceVars> rwi; ReverseElement<WordReferenceVars> rwi;
try { 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; if (!skipDoubleDom) return rwi;
// check doubledom // check doubledom

@ -154,7 +154,7 @@ public final class SearchEvent {
this.results = new ResultFetcher(loader, rankedCache, query, peers, 3000); this.results = new ResultFetcher(loader, rankedCache, query, peers, 3000);
} else { } else {
// do a local search // 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! this.rankedCache.run(); // this is not started concurrently here on purpose!
if (generateAbstracts) { if (generateAbstracts) {

@ -207,6 +207,8 @@ public class Segment {
final int outlinksOther, final int outlinksOther,
final SearchEvent searchEvent, final SearchEvent searchEvent,
final String sourceName) { final String sourceName) {
RankingProcess rankingProcess = (searchEvent == null) ? null : searchEvent.getRankingResult();
if (rankingProcess != null) rankingProcess.moreFeeders(1);
int wordCount = 0; int wordCount = 0;
final int urlLength = url.toNormalform(true, true).length(); final int urlLength = url.toNormalform(true, true).length();
final int urlComps = MultiProtocolURI.urlComps(url.toString()).length; final int urlComps = MultiProtocolURI.urlComps(url.toString()).length;
@ -248,10 +250,10 @@ public class Segment {
} catch (RowSpaceExceededException e) { } catch (RowSpaceExceededException e) {
continue; continue;
} }
searchEvent.getRankingResult().add(container, false, sourceName, -1); rankingProcess.add(container, false, sourceName, -1);
} }
} }
if (rankingProcess != null) rankingProcess.oneFeederTerminated();
return wordCount; return wordCount;
} }

@ -127,11 +127,13 @@ public class WeakPriorityBlockingQueue<E> {
* return the element with the smallest weight and remove it from the stack * 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 * @return null if no element is on the queue or the head of the queue
*/ */
public synchronized E poll() { public E poll() {
if (this.queue.isEmpty()) return null; boolean a = this.enqueued.tryAcquire();
this.enqueued.tryAcquire(); if (!a) return null;
synchronized (this) {
return takeUnsafe(); return takeUnsafe();
} }
}
/** /**
* Retrieves and removes the head of this queue, waiting if necessary * Retrieves and removes the head of this queue, waiting if necessary
@ -141,7 +143,7 @@ public class WeakPriorityBlockingQueue<E> {
* @throws InterruptedException * @throws InterruptedException
*/ */
public E poll(long timeout) 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; if (!a) return null;
synchronized (this) { synchronized (this) {
return takeUnsafe(); return takeUnsafe();

@ -363,16 +363,16 @@ public class SplitTable implements Index, Iterable<Row.Entry> {
*/ */
public boolean put(final Row.Entry row) throws IOException, RowSpaceExceededException { public boolean put(final Row.Entry row) throws IOException, RowSpaceExceededException {
assert row.objectsize() <= this.rowdef.objectsize; assert row.objectsize() <= this.rowdef.objectsize;
synchronized (this.tables) {
Index keeper = keeperOf(row.getColBytes(0, true)); Index keeper = keeperOf(row.getColBytes(0, true));
if (keeper != null) return keeper.put(row); if (keeper != null) return keeper.put(row);
synchronized (this.tables) {
assert this.current == null || this.tables.get(this.current) != null : "this.current = " + this.current; 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)); keeper = (this.current == null) ? newTable() : checkTable(this.tables.get(this.current));
}
boolean b = keeper.put(row); boolean b = keeper.put(row);
assert b; assert b;
return b; return b;
} }
}
private Index keeperOf(final byte[] key) { private Index keeperOf(final byte[] key) {

Loading…
Cancel
Save