@@ -155,6 +155,22 @@ public void searchContentAction() throws Exception {
155155 Query isDirectoryQuery = IntPoint .newExactQuery ("isDirectory" , 1 );
156156 builder .add (isDirectoryQuery , BooleanClause .Occur .MUST );
157157 }
158+ long fileSizeFrom = fileSearchToolController .getFileSizeFromSpinner ().getValue ();
159+ long fileSizeTo = fileSearchToolController .getFileSizeToSpinner ().getValue ();
160+ if (fileSizeFrom > 0 || fileSizeTo > 0 ) {
161+ if (fileSizeFrom > 0 ) {
162+ fileSizeFrom = getFileSize (fileSearchToolController .getFileSizeFromChoiceBox ().getSelectionModel ().getSelectedIndex (), fileSizeFrom );
163+ } else {
164+ fileSizeFrom = -1 ;
165+ }
166+ if (fileSizeTo > 0 ) {
167+ fileSizeTo = getFileSize (fileSearchToolController .getFileSizeToChoiceBox ().getSelectionModel ().getSelectedIndex (), fileSizeTo );
168+ } else {
169+ fileSizeTo = Long .MAX_VALUE ;
170+ }
171+ Query fileSizeFromQuery = LongPoint .newRangeQuery ("fileSize" , fileSizeFrom , fileSizeTo );
172+ builder .add (fileSizeFromQuery , BooleanClause .Occur .MUST );
173+ }
158174 if (StringUtils .isNotEmpty (path )) {
159175 PrefixQuery pathQuery = new PrefixQuery (new Term ("absolutePath" , path ));// 字段搜索 Field:Keyword,自动在结尾添加 *
160176 builder .add (pathQuery , BooleanClause .Occur .MUST );
@@ -169,7 +185,6 @@ public void searchContentAction() throws Exception {
169185 Map map = new HashMap ();
170186 map .put ("fileName" , document .get ("fileName" ));
171187 map .put ("absolutePath" , document .get ("absolutePath" ));
172- // map.put("fileSize", document.get("fileSize"));
173188 map .put ("fileSize" , (int ) Math .ceil (document .getField ("fileSize" ).numericValue ().longValue () / 1024.0 ) + "KB" );
174189// map.put("lastModified", new Date(Long.parseLong(document.get("lastModified"))).toLocaleString());
175190 map .put ("lastModified" , new Date (document .getField ("lastModified" ).numericValue ().longValue ()).toLocaleString ());
@@ -184,6 +199,18 @@ public void searchContentAction() throws Exception {
184199 fileSearchToolController .getSearchTextLabel ().setText ("总共查询到" + selectCount + "个文档; 当前一共缓存" + allCount + "个文档; 耗时:" + consumingTime + "毫秒" );
185200 }
186201
202+ private long getFileSize (int fileSizeType , long fileSize ) {
203+ if (fileSizeType == 0 ) {
204+ } else if (fileSizeType == 1 ) {
205+ fileSize = fileSize * 1024 ;
206+ } else if (fileSizeType == 2 ) {
207+ fileSize = fileSize * 1024 * 1024 ;
208+ } else if (fileSizeType == 3 ) {
209+ fileSize = fileSize * 1024 * 1024 * 1024 ;
210+ }
211+ return fileSize ;
212+ }
213+
187214 public void refreshIndexAction () throws Exception {
188215 String path = fileSearchToolController .getSearchDirectoryTextField ().getText ();
189216 if (StringUtils .isEmpty (path )) {
@@ -223,13 +250,10 @@ public void addIndexDocument(File file) throws Exception {
223250 doc .add (new StringField ("fileNameLowerCase" , file .getName ().toLowerCase (), Field .Store .NO ));
224251 doc .add (new StringField ("absolutePath" , file .getAbsolutePath (), Field .Store .YES ));
225252 doc .add (new StoredField ("fileSize" , file .length ()));
253+ doc .add (new LongPoint ("fileSize" , file .length ()));
226254 doc .add (new StoredField ("lastModified" , file .lastModified ()));
227255 doc .add (new IntPoint ("isHidden" , file .isHidden () ? 1 : 0 ));
228256 doc .add (new IntPoint ("isDirectory" , file .isDirectory () ? 1 : 0 ));
229- // doc.add(new StringField("fileSize", String.valueOf(file.length()), Field.Store.YES));
230- // doc.add(new StringField("lastModified", String.valueOf(file.lastModified()), Field.Store.YES));
231- // doc.add(new StringField("isHidden", String.valueOf(file.isHidden()), Field.Store.NO));
232- // doc.add(new StringField("isDirectory", String.valueOf(file.isDirectory()), Field.Store.NO));
233257
234258 indexWriter .updateDocument (new Term ("absolutePath" , file .getAbsolutePath ()), doc );
235259// indexWriter.addDocument(doc);
0 commit comments