Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use lucene4.7 paging technology

Shulou Source: shulou.com Published: 2022-06-01 09:13:49 09月26日 Update

This article introduces the relevant knowledge of "how to use lucene4.7 paging technology". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Before we introduce paging, let's take a look at the above requirement, which does not require paging.

In fact, in lucene, each index corresponds to a non-repeating docid, and this is the same as the pseudo-column rownum of Oralce database. It is precisely because of the existence of this docid that lucene has better performance in massive data retrieval. We all know that Oracle database uses pseudo-columns for paging, so my lucene is the same, since there is a docid. Then the above requirements are very simple.

Method 1: according to each docid in turn to get the document and then write to the txt, so as to avoid the shortcomings of insufficient memory, but such a single read, the speed may be a little slower, but can meet the needs is understandable. The pseudo code is as follows

Try {directory=FSDirectory.open (new File (indexReadPath)); / / Open the index folder IndexReader reader=DirectoryReader.open (directory); / / read the directory IndexSearcher search=new IndexSearcher (reader); / / initialize the query component for (int idoc.indethmur1) {/ / stop break when the number of pages is greater than the total number of pages } else {Document dosc=searcher.doc (docI] .doc); System.out.println (dosc.get ("name"));}}

Finally, let's take a look at the paging method using SearcherAfter. The code is as follows:

Try {directory=FSDirectory.open (new File (indexReadPath)); / / Open index folder IndexReader reader=DirectoryReader.open (directory); / / read directory IndexSearcher search=new IndexSearcher (reader); / / initialize query component int pageStart=0; ScoreDoc lastBottom=null;// is equivalent to pageSize while (pageStart)

Tags: Data query method index speed demand technology code memory again files folders directories components resources large location content scene situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Apple Shulou Technology Redmi Docker