yacy_search_server/source/net/yacy/kelondro/rwi/AbstractReference.java
orbiter 123375bfba added a new yacy protocol servlet 'idx'. This returns an index to one of the data entities that is stored in YaCy.
This servlet currently only serves for indexes to the web structure hosts. It can be tested by calling
http://localhost:8090/yacy/idx.json?object=host
This yacy protocol servlet is the first one that returns JSON code and that also shows index entries in a readable format. This will make the development of API applications much easier. This is also an example implementation for possible json versions of the other existing YaCy protocol interfaces.

The main purpose of this new feature is to provide a distributed block rank collection feature. Creating a block rank is very difficult if the forward-link data is first collected and then one peer must create a backward-link index. This interface provides already a partial backward index and therefore a collection of all these indexes needs only to be joined which is very easy. The result should be the computation of new block rank tables that all peers can perform.

To reduce load from peers this servlet buffers all data and refreshes it only once in 12 hours. This very slow update cycle is needed because the interface will be called round-robin from all peers once after start-up.

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7724 6c8d7289-2bf4-0310-a012-ef5d649a1542
2011-05-15 22:57:31 +00:00

118 lines
3.7 KiB
Java

// AbstractReference.java
// (C) 2009 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
// first published 14.04.2009 on http://yacy.net
//
// This is a part of YaCy, a peer-to-peer based web search engine
//
// $LastChangedDate$
// $LastChangedRevision$
// $LastChangedBy$
//
// LICENSE
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package net.yacy.kelondro.rwi;
import java.util.Collection;
import java.util.Iterator;
public abstract class AbstractReference implements Reference {
protected static void a(Collection<Integer> a, int i) {
assert a != null;
if (i == Integer.MAX_VALUE || i == Integer.MIN_VALUE) return; // signal for 'do nothing'
a.clear();
a.add(i);
}
protected static int max(Collection<Integer> a, Collection<Integer> b) {
if (a == null || a.size() == 0) return max(b);
if (b == null || b.size() == 0) return max(a);
int ma = max(a);
int mb = max(b);
if (ma == Integer.MIN_VALUE) return mb;
if (mb == Integer.MIN_VALUE) return ma;
return Math.max(ma, mb);
}
protected static int min(Collection<Integer> a, Collection<Integer> b) {
assert a != null;
if (a == null || a.size() == 0) return min(b);
if (b == null || b.size() == 0) return min(a);
int ma = min(a);
int mb = min(b);
if (ma == Integer.MAX_VALUE) return mb;
if (mb == Integer.MAX_VALUE) return ma;
return Math.min(ma, mb);
}
private static int max(Collection<Integer> a) {
if (a == null || a.size() == 0) return Integer.MIN_VALUE;
Iterator<Integer> i = a.iterator();
if (a.size() == 1) return i.next();
if (a.size() == 2) return Math.max(i.next(), i.next());
int r = i.next();
int s;
while (i.hasNext()) {
s = i.next();
if (s > r) r = s;
}
return r;
}
private static int min(Collection<Integer> a) {
if (a == null || a.size() == 0) return Integer.MAX_VALUE;
Iterator<Integer> i = a.iterator();
if (a.size() == 1) return i.next();
if (a.size() == 2) return Math.min(i.next(), i.next());
int r = i.next();
int s;
while (i.hasNext()) {
s = i.next();
if (s < r) r = s;
}
return r;
}
public int maxposition() {
return max(positions());
}
public int minposition() {
return min(positions());
}
public int distance() {
if (positions().size() < 2) return 0;
int d = 0;
Iterator<Integer> i = positions().iterator();
int s0 = i.next(), s1;
while (i.hasNext()) {
s1 = i.next();
d += Math.abs(s0 - s1);
s0 = s1;
}
return d / (positions().size() - 1);
}
public boolean isOlder(final Reference other) {
if (other == null) return false;
if (this.lastModified() < other.lastModified()) return true;
return false;
}
}