1 package org.paneris.bibliomania.fti; 2 3 class WordTextSearchResults extends TextSearchResultsBase { 4 5 private byte[] data = null; 6 private int dataLength = 0; 7 private int pointer = -1; 8 private int currentWordIndex, currentOffset; 9 private Packer wordIndexPacker; 10 private Packer offsetPacker; 11 12 public int hitWordsCount() { 13 return 1; 14 } 15 16 public void init() { 17 pointer = 0; 18 wordIndexPacker = OnePacker.it; 19 offsetPacker = OnePacker.it; 20 skipToNextHit(); 21 } 22 23 public void init(byte[] dataP, int dataLengthP) { 24 this.data = dataP; 25 this.dataLength = dataLengthP; 26 init(); 27 } 28 29 public void skipToNextHit() { 30 for (;;) { 31 if (pointer + wordIndexPacker.numberLength() > dataLength) { 32 pointer = -1; 33 return; 34 } 35 36 currentWordIndex = wordIndexPacker.number(data, pointer); 37 pointer += wordIndexPacker.numberLength(); 38 39 if (currentWordIndex == wordIndexPacker.numberMax()) 40 wordIndexPacker = wordIndexPacker.bigger(); 41 else 42 break; 43 } 44 45 for (;;) { 46 if (pointer + offsetPacker.numberLength() > dataLength) { 47 pointer = -1; 48 return; 49 } 50 51 currentOffset = offsetPacker.number(data, pointer); 52 pointer += offsetPacker.numberLength(); 53 54 if (currentOffset == offsetPacker.numberMax()) 55 offsetPacker = offsetPacker.bigger(); 56 else 57 break; 58 } 59 } 60 61 public int currentWordIndex() { 62 return pointer == -1 ? -1 : currentWordIndex; 63 } 64 65 public int currentOffset() { 66 return pointer == -1 ? -1 : currentOffset; 67 } 68 69 public void close() { 70 } 71 }