Ospod. Forum uses Lucene as the core of the search engine. For Lucene paging, ospod encapsulates hits twice. After the desired result set is retrieved, turn off hits, greatly improving the search efficiency. The reference code is as follows:
/**
* Index paging object
*/
Private pagination page;
/**
* Number of hit result data
*/
Private int hitslength = 0;
/**
* Hit result set of the current page
*/
Private list results;
/**
* Maximum number of results used for paging
*/
Private int Total = 0;
/**
* Constructor: Creates and initializes an index result set object.
* @ Param hits: Query hit results
* @ Param Actual position of start result set Extraction
* @ Param count: current number of inputs
* @ Param totallimit refers to the maximum number of result sets for paging. Limiting the maximum number of extracted results is conducive to system query performance.
*/
Public indexresultset (hits, int start, int count, int totallimit ){
Results = new arraylist ();
Page = paginationutils. Create ();
Hitslength = hits. Length ();
If (hitslength> totallimit ){
Total = totallimit;
} Else {
Total = hitslength;
}
Int pagesize = count;
If (start + count> total ){
Count = total-start;
}
Page. INIT (START, Count, total, pagesize );
Int end = start + count;
Try {
Document Doc;
For (INT I = start; I <end; I ++ ){
Doc = hits.doc (I );
Iterator iter = Doc. getfields (). iterator ();
Emap DATA = new emap ();
String name, value, lvalue;
While (ITER. hasnext ()){
Field F = (field) ITER. Next ();
Name = f. Name ();
Value = Doc. Get (name );
Data. setvalue (name, value );
}
Data. setvalue ("score _", hits. Score (I ));
Data. setvalue ("docid _", hits. ID (I ));
Results. Add (data );
}
} Catch (ioexception ex ){
Throw new indexexception ("An error occurred while retrieving the index result set", ex );
}
}