Package COM. jadyer. lucene; import Java. io. file; import Java. io. ioexception; import Java. text. parseexception; import Java. text. simpledateformat; import Java. util. date; import Org. apache. lucene. analysis. standard. standardanalyzer; import org.apache.e.doc ument. document; import org.apache.e.doc ument. field; import org.apache.e.doc ument. numericfield; import Org. apache. lucene. index. indexreader; import Org. apache. lucene. index. indexwriter; import Org. apache. lucene. index. indexwriterconfig; import Org. apache. lucene. queryparser. queryparser; import Org. apache. lucene. search. filter; import Org. apache. lucene. search. indexsearcher; import Org. apache. lucene. search. scoredoc; import Org. apache. lucene. search. topdocs; import Org. apache. lucene. store. directory; import Org. apache. lucene. store. fsdirectory; import Org. apach E. lucene. util. version; import COM. jadyer. custom. myfilter; /*** [lucene3.6.2 entry series] section 07th _ General filter and custom filter Advanced Search * @ create Aug 19,201 3 11:13:40 am * @ author Xuan Yu
The following is the custom myfilter. Java
Package COM. jadyer. custom; import Java. io. ioexception; import Org. apache. lucene. index. indexreader; import Org. apache. lucene. index. term; import Org. apache. lucene. index. termdocs; import Org. apache. lucene. search. docidset; import Org. apache. lucene. search. filter; import Org. apache. lucene. util. openbitset;/*** custom filter * @ see parameters * @ see application scenarios in this example * @ see assume a lot of data, and then delete some of the data, at this time, when you accept the search request, you can update the index so that no deleted data will be searched * @ see. However, updating the index will consume a lot of time (because of the large amount of data ), in addition, it is necessary to ensure that the deleted data will not be searched * @ see. At this time, you can customize the filter. The principle is that when this record is found to be deleted during the search process, if this parameter is not added to the returned search result set * @ See Filters * @ see custom filter, follow the steps below * @ see 1) to inherit the filter class and override the getdocidset () method * @ see 2) return a new docidset object * @ see variables * @ see docidset sub-solution * @ see here. The filter is actually used to create a docidset, while the docidset is actually an array, it can be understood that only the 0 or 1 value is stored * @ see each searched document has a document number, so how many documents are searched, the number of records in the docidset * @ see, and the index number of each record in the docidset corresponds to the document number one by one * @ see. Therefore, when the record in the docidset is 1, the document corresponding to the document number will be added to topdocs, 0 will be filtered out * @ See example * @ create Aug 6, 2013 7:28:53 pm * @ author Xuan Yu