public boolean hasNext() { try { if (leaf) return rover < n; while (i == null || i.hasNext() == false) { int c = (int) c(rover++); i = getPage(c).iterator(); } return i.hasNext(); } catch (IOException e) { throw new RuntimeException(e); } }
QueryOptions options = QueryOptions.newBuilder().setOffset(0).setLimit(50); IndexSpec indexSpec = IndexSpec.newBuilder().setName("Beneficiaries").build(); Index index = SearchServiceFactory.getSearchService().getIndex(indexSpec); Results<ScoredDocument>results = index.search(query);
import java.util.HashMap; import java.util.Map; import com.flaptor.indextank.apiclient.Index; import com.flaptor.indextank.apiclient.IndexTankClient; import com.flaptor.indextank.apiclient.IndexTankClient.Query; import com.flaptor.indextank.apiclient.IndexTankClient.SearchResults; public class IndexTankExample { public static void main(String[] args) throws Exception { IndexTankClient client = new IndexTankClient("<PRIVATE URL>"); Index index = client.getIndex("test"); Map<String, String> fields = new HashMap<String, String>(); fields.put("text", "foo bar baz"); index.addDocument("1", fields); SearchResults results = index.search(Query.forString("bar")); for (Map<String, Object> document : results.results) { System.out.println("doc id: " + document.get("docid")); } } }
public Index(File file, int keySize) throws IOException { capacity = (pageSize - Page.START_OFFSET) / (keySize + valueSize); RandomAccessFile raf = new RandomAccessFile(file, "rw"); this.file = raf.getChannel(); settings = this.file.map(MapMode.READ_WRITE, 0, pageSize); if (this.file.size() == pageSize) { this.keySize = keySize; settings.putInt(SIGNATURE, MAGIC); settings.putInt(KEYSIZE, keySize); nextPage = 1; root = allocate(true); root.n = 1; root.set(0, new byte[KEYSIZE], 0); root.write(); } else { if (settings.getInt(SIGNATURE) != MAGIC) throw new IllegalStateException("No Index file, magic is not " + MAGIC); this.keySize = settings.getInt(KEYSIZE); if (keySize != 0 && this.keySize != keySize) throw new IllegalStateException("Invalid key size for Index file. The file is " + this.keySize + " and was expected to be " + this.keySize); root = getPage(1); nextPage = (int) (this.file.size() / pageSize); } }
void insert(byte[] k, long v) throws IOException { if (n == capacity) { int t = capacity / 2; Page left = allocate(leaf); Page right = allocate(leaf); left.copyFrom(this, 0, t); left.n = t; right.copyFrom(this, t, capacity - t); right.n = capacity - t; leaf = false; set(0, left.k(0), left.number); set(1, right.k(0), right.number); n = 2; left.write(); right.write(); } insertNonFull(k, v); }
public void close() throws IOException { synchronized (store) { try { store.close(); } finally { index.close(); } } }
index = new Index(new File(home, INDEXFILE), KEYLENGTH); store = new RandomAccessFile(new File(home, STOREFILE), "rw"); channel = store.getChannel();
public Index(File file, int keySize) throws IOException { capacity = (pageSize - Page.START_OFFSET) / (keySize + valueSize); RandomAccessFile raf = new RandomAccessFile(file, "rw"); this.file = raf.getChannel(); settings = this.file.map(MapMode.READ_WRITE, 0, pageSize); if (this.file.size() == pageSize) { this.keySize = keySize; settings.putInt(SIGNATURE, MAGIC); settings.putInt(KEYSIZE, keySize); nextPage = 1; root = allocate(true); root.n = 1; root.set(0, new byte[KEYSIZE], 0); root.write(); } else { if (settings.getInt(SIGNATURE) != MAGIC) throw new IllegalStateException("No Index file, magic is not " + MAGIC); this.keySize = settings.getInt(KEYSIZE); if (keySize != 0 && this.keySize != keySize) throw new IllegalStateException("Invalid key size for Index file. The file is " + this.keySize + " and was expected to be " + this.keySize); root = getPage(1); nextPage = (int) (this.file.size() / pageSize); } }
void insert(byte[] k, long v) throws IOException { if (n == capacity) { int t = capacity / 2; Page left = allocate(leaf); Page right = allocate(leaf); left.copyFrom(this, 0, t); left.n = t; right.copyFrom(this, t, capacity - t); right.n = capacity - t; leaf = false; set(0, left.k(0), left.number); set(1, right.k(0), right.number); n = 2; left.write(); right.write(); } insertNonFull(k, v); }
public Index(File file, int keySize) throws IOException { capacity = (pageSize - Page.START_OFFSET) / (keySize + valueSize); @SuppressWarnings("resource") RandomAccessFile raf = new RandomAccessFile(file, "rw"); this.file = raf.getChannel(); settings = this.file.map(MapMode.READ_WRITE, 0, pageSize); if (this.file.size() == pageSize) { this.keySize = keySize; settings.putInt(SIGNATURE, MAGIC); settings.putInt(KEYSIZE, keySize); nextPage = 1; root = allocate(true); root.n = 1; root.set(0, new byte[KEYSIZE], 0); root.write(); } else { if (settings.getInt(SIGNATURE) != MAGIC) throw new IllegalStateException("No Index file, magic is not " + MAGIC); this.keySize = settings.getInt(KEYSIZE); if (keySize != 0 && this.keySize != keySize) throw new IllegalStateException("Invalid key size for Index file. The file is " + this.keySize + " and was expected to be " + this.keySize); root = getPage(1); nextPage = (int) (this.file.size() / pageSize); } }
public boolean hasNext() { try { if (leaf) return rover < n; while (i == null || i.hasNext() == false) { int c = (int) c(rover++); i = getPage(c).iterator(); } return i.hasNext(); } catch (IOException e) { throw new RuntimeException(e); } }
void insert(byte[] k, long v) throws IOException { if (n == capacity) { int t = capacity / 2; Page left = allocate(leaf); Page right = allocate(leaf); left.copyFrom(this, 0, t); left.n = t; right.copyFrom(this, t, capacity - t); right.n = capacity - t; leaf = false; set(0, left.k(0), left.number); set(1, right.k(0), right.number); n = 2; left.write(); right.write(); } insertNonFull(k, v); }
public boolean exists(byte[] sha1) throws Exception { return index.search(sha1) >= 0; }
public boolean hasNext() { try { if (leaf) return rover < n; else { while (i == null || i.hasNext() == false) { int c = (int) c(rover++); i = getPage(c).iterator(); } return i.hasNext(); } } catch (IOException e) { throw new RuntimeException(e); } }
Query query = Query.newBuilder().build("Display_Name" + "=" + searchText); Index userDocIndex = getUserDocIndex(); Results<ScoredDocument> matchingUsers = userDocIndex.search(query);
public void toString(StringBuilder sb, String indent) throws IOException { for (int i = 0; i < n; i++) { sb.append(String.format("%s %02d:%02d %20s %s %d%n", indent, number, i, hex(k(i), 0, 4), leaf ? "==" : "->", c(i))); if (!leaf) { long c = c(i); Page sub = getPage((int) c); sub.toString(sb, indent + " "); } } }