private TopDocs searchByVersion(String selfLink,IndexSearcher s,Long version) throws IOException {
  Query tqSelfLink=new TermQuery(new Term(ServiceDocument.FIELD_NAME_SELF_LINK,selfLink));
  BooleanQuery.Builder builder=new BooleanQuery.Builder();
  builder.add(tqSelfLink,Occur.MUST);
  if (version != null) {
    Query versionQuery=LongPoint.newRangeQuery(ServiceDocument.FIELD_NAME_VERSION,version,version);
    builder.add(versionQuery,Occur.MUST);
  }
  TopDocs hits=s.search(builder.build(),1,this.versionSort,false,false);
  return hits;
}

private TopDocs searchByVersion ( String selfLink , IndexSearcher s , Long version ) throws IOException { Query tqSelfLink = new TermQuery ( new Term ( ServiceDocument . FIELD_NAME_SELF_LINK , selfLink ) ) ; BooleanQuery . Builder builder = new BooleanQuery . Builder ( ) ; builder . add ( tqSelfLink , Occur . MUST ) ; if ( version != null ) { Query versionQuery = LongPoint . newRangeQuery ( ServiceDocument . FIELD_NAME_VERSION , version , version ) ; builder . add ( versionQuery , Occur . MUST ) ; } TopDocs hits = s . search ( builder . build ( ) , 1 , this . versionSort , false , false ) ; return hits ; }
find the document given a self link and version number . this function is used for two purposes ; find given version to . . . 1 ) load state if the service state is not yet cached 2 ) filter query results to only include the given version in case ( 1 ) , authorization is applied in the service host ( either against the cached state or freshly loaded state ) . in case ( 2 ) , authorization should not be applied because the original query already included the resource group query per the authorization context . query results will be filtered given the real latest version , not the latest version subject to the resource group query . this means older versions of a document will not appear in the query result if the user is not authorized to see the newer version . if given version is null then function returns the latest version . and if given version is not found then no document is returned .
