Secondary encapsulation of Lucene query result hits

Source: Internet
Author: User

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 );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.