public void testRanking() throws Exception {
  final int numDocs=atLeast(100);
  final int maxTopN=5;
  final int maxSentenceLength=10;
  final int maxNumSentences=20;
  Directory dir=newDirectory();
  RandomIndexWriter iw=new RandomIndexWriter(random(),dir,new MockAnalyzer(random(),MockTokenizer.SIMPLE,true));
  Document document=new Document();
  Field id=new StringField("id","",Field.Store.NO);
  FieldType offsetsType=new FieldType(TextField.TYPE_STORED);
  offsetsType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
  Field body=new Field("body","",offsetsType);
  document.add(id);
  document.add(body);
  for (int i=0; i < numDocs; i++) {
    StringBuilder bodyText=new StringBuilder();
    int numSentences=TestUtil.nextInt(random(),1,maxNumSentences);
    for (int j=0; j < numSentences; j++) {
      bodyText.append(newSentence(random(),maxSentenceLength));
    }
    body.setStringValue(bodyText.toString());
    id.setStringValue(Integer.toString(i));
    iw.addDocument(document);
  }
  IndexReader ir=iw.getReader();
  IndexSearcher searcher=newSearcher(ir);
  for (int i=0; i < numDocs; i++) {
    checkDocument(searcher,i,maxTopN);
  }
  iw.close();
  ir.close();
  dir.close();
}

public void testRanking ( ) throws Exception { final int numDocs = atLeast ( 100 ) ; final int maxTopN = 5 ; final int maxSentenceLength = 10 ; final int maxNumSentences = 20 ; Directory dir = newDirectory ( ) ; RandomIndexWriter iw = new RandomIndexWriter ( random ( ) , dir , new MockAnalyzer ( random ( ) , MockTokenizer . SIMPLE , true ) ) ; Document document = new Document ( ) ; Field id = new StringField ( "id" , "" , Field . Store . NO ) ; FieldType offsetsType = new FieldType ( TextField . TYPE_STORED ) ; offsetsType . setIndexOptions ( IndexOptions . DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS ) ; Field body = new Field ( "body" , "" , offsetsType ) ; document . add ( id ) ; document . add ( body ) ; for ( int i = 0 ; i < numDocs ; i ++ ) { StringBuilder bodyText = new StringBuilder ( ) ; int numSentences = TestUtil . nextInt ( random ( ) , 1 , maxNumSentences ) ; for ( int j = 0 ; j < numSentences ; j ++ ) { bodyText . append ( newSentence ( random ( ) , maxSentenceLength ) ) ; } body . setStringValue ( bodyText . toString ( ) ) ; id . setStringValue ( Integer . toString ( i ) ) ; iw . addDocument ( document ) ; } IndexReader ir = iw . getReader ( ) ; IndexSearcher searcher = newSearcher ( ir ) ; for ( int i = 0 ; i < numDocs ; i ++ ) { checkDocument ( searcher , i , maxTopN ) ; } iw . close ( ) ; ir . close ( ) ; dir . close ( ) ; }
indexes a bunch of gibberish , and then highlights top ( n ) . asserts that top ( n ) highlights is a subset of top ( n + 1 ) up to some max n
