You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
175 lines
6.0 KiB
175 lines
6.0 KiB
16 years ago
|
// ReverseIndex.java
|
||
|
// -----------------------------
|
||
|
// (C) 2005 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany
|
||
|
// first published 6.5.2005 on http://www.anomic.de
|
||
|
//
|
||
|
// This is a part of YaCy, a peer-to-peer based web search engine
|
||
|
//
|
||
15 years ago
|
// $LastChangedDate: 2009-10-10 01:22:22 +0200 (Sa, 10 Okt 2009) $
|
||
|
// $LastChangedRevision: 6392 $
|
||
|
// $LastChangedBy: orbiter $
|
||
16 years ago
|
//
|
||
|
// 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
|
||
|
|
||
|
|
||
15 years ago
|
package net.yacy.kelondro.rwi;
|
||
16 years ago
|
|
||
|
import java.io.IOException;
|
||
16 years ago
|
import java.util.HashMap;
|
||
16 years ago
|
import java.util.Set;
|
||
|
import java.util.TreeSet;
|
||
|
|
||
15 years ago
|
import net.yacy.kelondro.order.ByteOrder;
|
||
|
import net.yacy.kelondro.order.CloneableIterator;
|
||
|
|
||
16 years ago
|
|
||
16 years ago
|
public interface Index <ReferenceType extends Reference> {
|
||
16 years ago
|
|
||
|
/**
|
||
|
* add references to the reverse index
|
||
|
* if no references to the word are stored, the new Entries are added,
|
||
|
* if there are already references to the word that is denoted with the
|
||
|
* reference to be stored, then the old and the new references are merged
|
||
|
* @param newEntries the References to be merged with existing references
|
||
|
* @throws IOException
|
||
|
*/
|
||
16 years ago
|
public void add(ReferenceContainer<ReferenceType> newEntries) throws IOException;
|
||
16 years ago
|
|
||
|
/**
|
||
|
* add a single reference to the reverse index
|
||
|
* if no references to the word are stored, the a new entry is added,
|
||
|
* if there are already references to the word hash stored,
|
||
|
* then the old and the new references are merged
|
||
16 years ago
|
* @param termHash
|
||
16 years ago
|
* @param entry
|
||
|
* @throws IOException
|
||
|
*/
|
||
16 years ago
|
public void add(final byte[] termHash, final ReferenceType entry) throws IOException;
|
||
16 years ago
|
|
||
|
/**
|
||
|
* check if there are references stored to the given word hash
|
||
16 years ago
|
* @param termHash
|
||
16 years ago
|
* @return true if references exist, false if not
|
||
|
*/
|
||
16 years ago
|
public boolean has(final byte[] termHash); // should only be used if in case that true is returned the getContainer is NOT called
|
||
16 years ago
|
|
||
|
/**
|
||
|
* count the number of references for the given word
|
||
|
* do not use this method to check the existence of a reference by comparing
|
||
|
* the result with zero, use hasReferences instead.
|
||
16 years ago
|
* @param termHash
|
||
16 years ago
|
* @return the number of references to the given word
|
||
|
*/
|
||
16 years ago
|
public int count(final byte[] termHash);
|
||
16 years ago
|
|
||
|
/**
|
||
|
* get the references to a given word.
|
||
|
* if referenceselection is not null, then all url references which are not
|
||
|
* in referenceselection are removed from the container
|
||
16 years ago
|
* @param termHash
|
||
16 years ago
|
* @param referenceselection
|
||
|
* @return the references
|
||
|
* @throws IOException
|
||
|
*/
|
||
16 years ago
|
public ReferenceContainer<ReferenceType> get(byte[] termHash, Set<String> referenceselection) throws IOException;
|
||
16 years ago
|
|
||
|
/**
|
||
|
* delete all references for a word
|
||
16 years ago
|
* @param termHash
|
||
16 years ago
|
* @return the deleted references
|
||
|
* @throws IOException
|
||
|
*/
|
||
16 years ago
|
public ReferenceContainer<ReferenceType> delete(byte[] termHash) throws IOException;
|
||
16 years ago
|
|
||
|
/**
|
||
|
* remove a specific reference entry
|
||
16 years ago
|
* @param termHash
|
||
16 years ago
|
* @param referenceHash the key for the reference entry to be removed
|
||
|
* @return
|
||
|
* @throws IOException
|
||
|
*/
|
||
16 years ago
|
public boolean remove(byte[] termHash, String referenceHash) throws IOException;
|
||
16 years ago
|
|
||
|
/**
|
||
|
* remove a set of reference entries for a given word
|
||
16 years ago
|
* @param termHash the key for the references
|
||
16 years ago
|
* @param referenceHash the reference entry keys
|
||
|
* @return
|
||
|
* @throws IOException
|
||
|
*/
|
||
16 years ago
|
public int remove(final byte[] termHash, Set<String> referenceHashes) throws IOException;
|
||
|
public int remove(final TreeSet<byte[]> termHashes, final String urlHash) throws IOException;
|
||
16 years ago
|
|
||
|
/**
|
||
|
* iterate all references from the beginning of a specific word hash
|
||
16 years ago
|
* @param startHash
|
||
16 years ago
|
* @param rot if true, then rotate at the end to the beginning
|
||
|
* @param ram
|
||
|
* @return
|
||
|
* @throws IOException
|
||
|
*/
|
||
16 years ago
|
public CloneableIterator<ReferenceContainer<ReferenceType>> references(
|
||
16 years ago
|
byte[] startHash,
|
||
16 years ago
|
boolean rot
|
||
|
) throws IOException;
|
||
|
|
||
|
|
||
16 years ago
|
public TreeSet<ReferenceContainer<ReferenceType>> references(
|
||
16 years ago
|
byte[] startHash,
|
||
16 years ago
|
boolean rot,
|
||
|
int count
|
||
|
) throws IOException;
|
||
16 years ago
|
|
||
|
/**
|
||
|
* collect containers for given word hashes. This collection stops if a single container does not contain any references.
|
||
|
* In that case only a empty result is returned.
|
||
|
* @param wordHashes
|
||
|
* @param urlselection
|
||
|
* @return map of wordhash:indexContainer
|
||
|
*/
|
||
|
public HashMap<byte[], ReferenceContainer<ReferenceType>> searchConjunction(final TreeSet<byte[]> wordHashes, final Set<String> urlselection);
|
||
|
|
||
16 years ago
|
/**
|
||
|
* delete all references entries
|
||
|
* @throws IOException
|
||
|
*/
|
||
|
public void clear() throws IOException;
|
||
|
|
||
|
/**
|
||
|
* close the reverse index
|
||
|
*/
|
||
|
public void close();
|
||
|
|
||
|
/**
|
||
|
* the number of all references
|
||
|
* @return the nnumber of all references
|
||
|
*/
|
||
|
public int size();
|
||
|
|
||
|
/**
|
||
|
* calculate needed memory
|
||
|
* @return the memory needed to operate the object
|
||
|
*/
|
||
|
public int minMem();
|
||
|
|
||
|
/**
|
||
|
* return the order that is used for the storage of the word hashes
|
||
|
* @return
|
||
|
*/
|
||
|
public ByteOrder ordering();
|
||
|
}
|