1 17 package org.alfresco.repo.search.impl.lucene.query; 18 19 import java.io.IOException ; 20 21 26 public class AbsoluteStructuredFieldPosition extends AbstractStructuredFieldPosition 27 { 28 29 int requiredPosition; 30 31 34 35 public AbsoluteStructuredFieldPosition(String termText, int position) 36 { 37 super(termText, true, true); 38 this.requiredPosition = position; 39 } 40 41 47 public int matches(int start, int end, int offset) throws IOException 48 { 49 if (offset >= requiredPosition) 50 { 51 return -1; 52 } 53 54 if (getCachingTermPositions() != null) 55 { 56 getCachingTermPositions().reset(); 58 int count = getCachingTermPositions().freq(); 59 int realPosition = 0; 60 int adjustedPosition = 0; 61 for (int i = 0; i < count; i++) 62 { 63 realPosition = getCachingTermPositions().nextPosition(); 64 adjustedPosition = realPosition - start; 65 if ((end != -1) && (realPosition > end)) 66 { 67 return -1; 68 } 69 if (adjustedPosition > requiredPosition) 70 { 71 return -1; 72 } 73 if (adjustedPosition == requiredPosition) 74 { 75 return adjustedPosition; 76 } 77 78 } 79 } 80 else 81 { 82 if ((offset + 1) == requiredPosition) 84 { 85 return offset + 1; 86 } 87 } 88 return -1; 89 90 } 91 92 97 public int getPosition() 98 { 99 return requiredPosition; 100 } 101 102 public String getDescription() 103 { 104 return "Absolute Named child"; 105 } 106 } | Popular Tags |