├── .gitignore ├── .travis.yml ├── CHANGES.txt ├── LICENSE.txt ├── NOTICE.txt ├── README.md ├── build.xml ├── docs └── img │ ├── ApacheCon_Luke_lightning_talk.png │ ├── LukeExportIndex.png │ ├── LukeStyles_Sky.png │ ├── LukeTermVector.png │ └── jetbrains.svg ├── java_logo.png ├── luke-swing.png ├── luke.bat ├── luke.sh ├── pom.xml └── src ├── main ├── assembly │ └── assembly.xml ├── java │ ├── org │ │ └── apache │ │ │ └── lucene │ │ │ └── luke │ │ │ ├── app │ │ │ ├── AbstractHandler.java │ │ │ ├── DirectoryHandler.java │ │ │ ├── DirectoryObserver.java │ │ │ ├── IndexHandler.java │ │ │ ├── IndexObserver.java │ │ │ ├── LukeState.java │ │ │ ├── Observer.java │ │ │ ├── desktop │ │ │ │ ├── LukeMain.java │ │ │ │ ├── MessageBroker.java │ │ │ │ ├── Preferences.java │ │ │ │ ├── PreferencesFactory.java │ │ │ │ ├── PreferencesImpl.java │ │ │ │ ├── components │ │ │ │ │ ├── AnalysisPanelProvider.java │ │ │ │ │ ├── AnalysisTabOperator.java │ │ │ │ │ ├── CommitsPanelProvider.java │ │ │ │ │ ├── ComponentOperatorRegistry.java │ │ │ │ │ ├── DocumentsPanelProvider.java │ │ │ │ │ ├── DocumentsTabOperator.java │ │ │ │ │ ├── LogsPanelProvider.java │ │ │ │ │ ├── LukeWindowOperator.java │ │ │ │ │ ├── LukeWindowProvider.java │ │ │ │ │ ├── MenuBarProvider.java │ │ │ │ │ ├── OverviewPanelProvider.java │ │ │ │ │ ├── SearchPanelProvider.java │ │ │ │ │ ├── SearchTabOperator.java │ │ │ │ │ ├── TabSwitcherProxy.java │ │ │ │ │ ├── TabbedPaneProvider.java │ │ │ │ │ ├── TableColumnInfo.java │ │ │ │ │ ├── TableModelBase.java │ │ │ │ │ ├── dialog │ │ │ │ │ │ ├── ConfirmDialogFactory.java │ │ │ │ │ │ ├── HelpDialogFactory.java │ │ │ │ │ │ ├── analysis │ │ │ │ │ │ │ ├── AnalysisChainDialogFactory.java │ │ │ │ │ │ │ ├── EditFiltersDialogFactory.java │ │ │ │ │ │ │ ├── EditFiltersMode.java │ │ │ │ │ │ │ ├── EditParamsDialogFactory.java │ │ │ │ │ │ │ ├── EditParamsMode.java │ │ │ │ │ │ │ ├── TokenAttributeDialogFactory.java │ │ │ │ │ │ │ └── package-info.java │ │ │ │ │ │ ├── documents │ │ │ │ │ │ │ ├── AddDocumentDialogFactory.java │ │ │ │ │ │ │ ├── AddDocumentDialogOperator.java │ │ │ │ │ │ │ ├── DocValuesDialogFactory.java │ │ │ │ │ │ │ ├── IndexOptionsDialogFactory.java │ │ │ │ │ │ │ ├── StoredValueDialogFactory.java │ │ │ │ │ │ │ ├── TermVectorDialogFactory.java │ │ │ │ │ │ │ └── package-info.java │ │ │ │ │ │ ├── menubar │ │ │ │ │ │ │ ├── AboutDialogFactory.java │ │ │ │ │ │ │ ├── CheckIndexDialogFactory.java │ │ │ │ │ │ │ ├── CreateIndexDialogFactory.java │ │ │ │ │ │ │ ├── OpenIndexDialogFactory.java │ │ │ │ │ │ │ ├── OptimizeIndexDialogFactory.java │ │ │ │ │ │ │ └── package-info.java │ │ │ │ │ │ ├── package-info.java │ │ │ │ │ │ └── search │ │ │ │ │ │ │ ├── ExplainDialogFactory.java │ │ │ │ │ │ │ └── package-info.java │ │ │ │ │ ├── fragments │ │ │ │ │ │ ├── analysis │ │ │ │ │ │ │ ├── CustomAnalyzerPanelOperator.java │ │ │ │ │ │ │ ├── CustomAnalyzerPanelProvider.java │ │ │ │ │ │ │ ├── PresetAnalyzerPanelOperator.java │ │ │ │ │ │ │ ├── PresetAnalyzerPanelProvider.java │ │ │ │ │ │ │ └── package-info.java │ │ │ │ │ │ ├── package-info.java │ │ │ │ │ │ └── search │ │ │ │ │ │ │ ├── AnalyzerPaneProvider.java │ │ │ │ │ │ │ ├── AnalyzerTabOperator.java │ │ │ │ │ │ │ ├── FieldValuesPaneProvider.java │ │ │ │ │ │ │ ├── FieldValuesTabOperator.java │ │ │ │ │ │ │ ├── MLTPaneProvider.java │ │ │ │ │ │ │ ├── MLTTabOperator.java │ │ │ │ │ │ │ ├── QueryParserPaneProvider.java │ │ │ │ │ │ │ ├── QueryParserTabOperator.java │ │ │ │ │ │ │ ├── SimilarityPaneProvider.java │ │ │ │ │ │ │ ├── SimilarityTabOperator.java │ │ │ │ │ │ │ ├── SortPaneProvider.java │ │ │ │ │ │ │ ├── SortTabOperator.java │ │ │ │ │ │ │ └── package-info.java │ │ │ │ │ └── package-info.java │ │ │ │ ├── dto │ │ │ │ │ └── documents │ │ │ │ │ │ ├── NewField.java │ │ │ │ │ │ └── package-info.java │ │ │ │ ├── package-info.java │ │ │ │ └── util │ │ │ │ │ ├── DialogOpener.java │ │ │ │ │ ├── ExceptionHandler.java │ │ │ │ │ ├── FontUtils.java │ │ │ │ │ ├── HelpHeaderRenderer.java │ │ │ │ │ ├── ImageUtils.java │ │ │ │ │ ├── ListUtils.java │ │ │ │ │ ├── MessageUtils.java │ │ │ │ │ ├── NumericUtils.java │ │ │ │ │ ├── StringUtils.java │ │ │ │ │ ├── StyleConstants.java │ │ │ │ │ ├── TabUtils.java │ │ │ │ │ ├── TableUtils.java │ │ │ │ │ ├── TextAreaAppender.java │ │ │ │ │ ├── TextAreaPrintStream.java │ │ │ │ │ ├── URLLabel.java │ │ │ │ │ ├── inifile │ │ │ │ │ ├── IniFile.java │ │ │ │ │ ├── IniFileReader.java │ │ │ │ │ ├── IniFileWriter.java │ │ │ │ │ ├── OptionMap.java │ │ │ │ │ ├── SimpleIniFile.java │ │ │ │ │ ├── SimpleIniFileReader.java │ │ │ │ │ ├── SimpleIniFileWriter.java │ │ │ │ │ └── package-info.java │ │ │ │ │ ├── lang │ │ │ │ │ ├── Callable.java │ │ │ │ │ └── package-info.java │ │ │ │ │ └── package-info.java │ │ │ └── package-info.java │ │ │ ├── models │ │ │ ├── LukeException.java │ │ │ ├── LukeModel.java │ │ │ ├── analysis │ │ │ │ ├── Analysis.java │ │ │ │ ├── AnalysisFactory.java │ │ │ │ ├── AnalysisImpl.java │ │ │ │ ├── CustomAnalyzerConfig.java │ │ │ │ └── package-info.java │ │ │ ├── commits │ │ │ │ ├── Commit.java │ │ │ │ ├── Commits.java │ │ │ │ ├── CommitsFactory.java │ │ │ │ ├── CommitsImpl.java │ │ │ │ ├── File.java │ │ │ │ ├── Segment.java │ │ │ │ └── package-info.java │ │ │ ├── documents │ │ │ │ ├── DocValues.java │ │ │ │ ├── DocValuesAdapter.java │ │ │ │ ├── DocumentField.java │ │ │ │ ├── Documents.java │ │ │ │ ├── DocumentsFactory.java │ │ │ │ ├── DocumentsImpl.java │ │ │ │ ├── TermPosting.java │ │ │ │ ├── TermVectorEntry.java │ │ │ │ ├── TermVectorsAdapter.java │ │ │ │ └── package-info.java │ │ │ ├── overview │ │ │ │ ├── Overview.java │ │ │ │ ├── OverviewFactory.java │ │ │ │ ├── OverviewImpl.java │ │ │ │ ├── TermCounts.java │ │ │ │ ├── TermCountsOrder.java │ │ │ │ ├── TermStats.java │ │ │ │ ├── TopTerms.java │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ ├── search │ │ │ │ ├── MLTConfig.java │ │ │ │ ├── QueryParserConfig.java │ │ │ │ ├── Search.java │ │ │ │ ├── SearchFactory.java │ │ │ │ ├── SearchImpl.java │ │ │ │ ├── SearchResults.java │ │ │ │ ├── SimilarityConfig.java │ │ │ │ └── package-info.java │ │ │ ├── tools │ │ │ │ ├── IndexTools.java │ │ │ │ ├── IndexToolsFactory.java │ │ │ │ ├── IndexToolsImpl.java │ │ │ │ └── package-info.java │ │ │ └── util │ │ │ │ ├── IndexUtils.java │ │ │ │ ├── package-info.java │ │ │ │ ├── reflection │ │ │ │ ├── ClassScanner.java │ │ │ │ ├── SubtypeCollector.java │ │ │ │ └── package-info.java │ │ │ │ └── twentynewsgroups │ │ │ │ ├── Message.java │ │ │ │ ├── MessageFilesParser.java │ │ │ │ └── package-info.java │ │ │ ├── package-info.java │ │ │ └── util │ │ │ ├── BytesRefUtils.java │ │ │ └── package-info.java │ └── overview.html └── resources │ ├── font │ └── ElegantIcons.ttf │ ├── img │ ├── indicator.gif │ ├── lucene-logo.gif │ ├── lucene.gif │ └── luke-logo.gif │ ├── log4j2.xml │ └── messages.properties └── test ├── java └── org │ └── apache │ └── lucene │ └── luke │ ├── app │ └── desktop │ │ └── util │ │ └── inifile │ │ └── SimpleIniFileTest.java │ └── models │ ├── analysis │ └── AnalysisImplTest.java │ ├── commits │ └── CommitsImplTest.java │ ├── documents │ ├── DocValuesAdapterTest.java │ ├── DocumentsImplTest.java │ ├── DocumentsTestBase.java │ └── TermVectorsAdapterTest.java │ ├── overview │ ├── OverviewImplTest.java │ ├── OverviewTestBase.java │ ├── TermCountsTest.java │ └── TopTermsTest.java │ └── search │ └── SearchImplTest.java └── resources └── log4j2.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .DS_Store 3 | .classpath 4 | .project 5 | .settings 6 | .idea 7 | *.iml 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk8 4 | - openjdk8 5 | - openjdk9 6 | - openjdk10 7 | - openjdk11 8 | script: mvn clean verify 9 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | ================================ 2 | Luke: Lucene Toolbox Project 3 | ================================ 4 | 5 | This software includes icon images from 6 | 7 | The Elegant Icon Font 8 | 9 | which can be downloaded from 10 | 11 | https://www.elegantthemes.com/blog/resources/elegant-icon-font 12 | 13 | These icons are dual licensed under the GPL 2.0 and MIT. 14 | -------------------------------------------------------------------------------- /docs/img/ApacheCon_Luke_lightning_talk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DmitryKey/luke/867b7de1d8dcd32220d35702995cb63214025215/docs/img/ApacheCon_Luke_lightning_talk.png -------------------------------------------------------------------------------- /docs/img/LukeExportIndex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DmitryKey/luke/867b7de1d8dcd32220d35702995cb63214025215/docs/img/LukeExportIndex.png -------------------------------------------------------------------------------- /docs/img/LukeStyles_Sky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DmitryKey/luke/867b7de1d8dcd32220d35702995cb63214025215/docs/img/LukeStyles_Sky.png -------------------------------------------------------------------------------- /docs/img/LukeTermVector.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DmitryKey/luke/867b7de1d8dcd32220d35702995cb63214025215/docs/img/LukeTermVector.png -------------------------------------------------------------------------------- /java_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DmitryKey/luke/867b7de1d8dcd32220d35702995cb63214025215/java_logo.png -------------------------------------------------------------------------------- /luke-swing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DmitryKey/luke/867b7de1d8dcd32220d35702995cb63214025215/luke-swing.png -------------------------------------------------------------------------------- /luke.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | set JAVA_OPTIONS=%JAVA_OPTIONS% -Xmx1024m -Xms512m -XX:MaxMetaspaceSize=256m 3 | start javaw %JAVA_OPTIONS% -Dswing.systemlaf=com.jgoodies.looks.plastic.PlasticXPLookAndFeel -jar .\target\luke-swing-with-deps.jar 4 | -------------------------------------------------------------------------------- /luke.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | JAVA_OPTIONS="${JAVA_OPTIONS} -Xmx1024m -Xms512m -XX:MaxMetaspaceSize=256m" 4 | JAR_FILE="target/luke-swing-with-deps.jar" 5 | 6 | LOG_DIR=${HOME}/.luke.d/ 7 | if [[ ! -d ${LOG_DIR} ]]; then 8 | mkdir ${LOG_DIR} 9 | fi 10 | 11 | LUKE_PATH=$(cd $(dirname $0) && pwd) 12 | cd ${LUKE_PATH} 13 | nohup java ${JAVA_OPTIONS} -jar ${JAR_FILE} > ${LOG_DIR}/luke_out.log 2>&1 & 14 | -------------------------------------------------------------------------------- /src/main/assembly/assembly.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | luke-release 21 | 22 | tar.gz 23 | zip 24 | 25 | false 26 | 27 | 28 | luke-swing-${project.version} 29 | 30 | luke.sh 31 | luke.bat 32 | 33 | 34 | 35 | target 36 | luke-swing-${project.version}/target 37 | 38 | luke-swing-with-deps.jar 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/AbstractHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app; 19 | 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | /** Abstract handler class */ 27 | public abstract class AbstractHandler { 28 | 29 | private static final Logger log = LoggerFactory.getLogger(AbstractHandler.class); 30 | 31 | private List observers = new ArrayList<>(); 32 | 33 | public void addObserver(T observer) { 34 | observers.add(observer); 35 | log.debug("{} registered.", observer.getClass().getName()); 36 | } 37 | 38 | void notifyObservers() { 39 | for (T observer : observers) { 40 | notifyOne(observer); 41 | } 42 | } 43 | 44 | protected abstract void notifyOne(T observer); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/DirectoryHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app; 19 | 20 | import org.apache.lucene.luke.app.desktop.util.MessageUtils; 21 | import org.apache.lucene.luke.models.LukeException; 22 | import org.apache.lucene.luke.models.util.IndexUtils; 23 | import org.apache.lucene.store.Directory; 24 | 25 | import java.io.IOException; 26 | import java.util.Objects; 27 | 28 | /** Directory open/close handler */ 29 | public final class DirectoryHandler extends AbstractHandler { 30 | 31 | private static final DirectoryHandler instance = new DirectoryHandler(); 32 | 33 | private LukeStateImpl state; 34 | 35 | public static DirectoryHandler getInstance() { 36 | return instance; 37 | } 38 | 39 | @Override 40 | protected void notifyOne(DirectoryObserver observer) { 41 | if (state.closed) { 42 | observer.closeDirectory(); 43 | } else { 44 | observer.openDirectory(state); 45 | } 46 | } 47 | 48 | public boolean directoryOpened() { 49 | return state != null && !state.closed; 50 | } 51 | 52 | public void open(String indexPath, String dirImpl) { 53 | Objects.requireNonNull(indexPath); 54 | 55 | if (directoryOpened()) { 56 | close(); 57 | } 58 | 59 | Directory dir; 60 | try { 61 | dir = IndexUtils.openDirectory(indexPath, dirImpl); 62 | } catch (IOException e) { 63 | throw new LukeException(MessageUtils.getLocalizedMessage("openindex.message.index_path_invalid", indexPath), e); 64 | } 65 | 66 | state = new LukeStateImpl(); 67 | state.indexPath = indexPath; 68 | state.dirImpl = dirImpl; 69 | state.dir = dir; 70 | 71 | notifyObservers(); 72 | } 73 | 74 | public void close() { 75 | if (state == null) { 76 | return; 77 | } 78 | 79 | IndexUtils.close(state.dir); 80 | 81 | state.closed = true; 82 | notifyObservers(); 83 | } 84 | 85 | public LukeState getState() { 86 | return state; 87 | } 88 | 89 | public static class LukeStateImpl implements LukeState { 90 | private boolean closed = false; 91 | 92 | private String indexPath; 93 | private String dirImpl; 94 | private Directory dir; 95 | 96 | @Override 97 | public String getIndexPath() { 98 | return indexPath; 99 | } 100 | 101 | @Override 102 | public String getDirImpl() { 103 | return dirImpl; 104 | } 105 | 106 | @Override 107 | public Directory getDirectory() { 108 | return dir; 109 | } 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/DirectoryObserver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app; 19 | 20 | /** Directory open/close observer */ 21 | public interface DirectoryObserver extends Observer { 22 | 23 | void openDirectory(LukeState state); 24 | 25 | void closeDirectory(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/IndexObserver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app; 19 | 20 | /** Index open/close observer */ 21 | public interface IndexObserver extends Observer { 22 | 23 | void openIndex(LukeState state); 24 | 25 | void closeIndex(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/LukeState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app; 19 | 20 | import org.apache.lucene.index.DirectoryReader; 21 | import org.apache.lucene.index.IndexReader; 22 | import org.apache.lucene.store.Directory; 23 | 24 | /** 25 | * Holder for current index/directory. 26 | */ 27 | public interface LukeState { 28 | 29 | String getIndexPath(); 30 | 31 | String getDirImpl(); 32 | 33 | default Directory getDirectory() { 34 | throw new UnsupportedOperationException(); 35 | } 36 | 37 | default IndexReader getIndexReader() { 38 | throw new UnsupportedOperationException(); 39 | } 40 | 41 | default boolean readOnly() { 42 | throw new UnsupportedOperationException(); 43 | } 44 | 45 | default boolean useCompound() { 46 | throw new UnsupportedOperationException(); 47 | } 48 | 49 | default boolean keepAllCommits() { 50 | throw new UnsupportedOperationException(); 51 | } 52 | 53 | default boolean hasDirectoryReader() { 54 | return getIndexReader() instanceof DirectoryReader; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/Observer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app; 19 | 20 | /** Marker interface for observers */ 21 | public interface Observer { 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/LukeMain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop; 19 | 20 | import org.apache.lucene.luke.app.desktop.components.LukeWindowProvider; 21 | import org.apache.lucene.luke.app.desktop.components.dialog.menubar.OpenIndexDialogFactory; 22 | import org.apache.lucene.luke.app.desktop.util.DialogOpener; 23 | import org.apache.lucene.luke.app.desktop.util.FontUtils; 24 | import org.apache.lucene.luke.app.desktop.util.MessageUtils; 25 | import org.slf4j.Logger; 26 | import org.slf4j.LoggerFactory; 27 | 28 | import javax.swing.JFrame; 29 | import javax.swing.UIManager; 30 | import java.awt.GraphicsEnvironment; 31 | import java.io.IOException; 32 | 33 | import static org.apache.lucene.luke.app.desktop.util.ExceptionHandler.handle; 34 | 35 | /** Entry class for desktop Luke */ 36 | public class LukeMain { 37 | 38 | private static final Logger log = LoggerFactory.getLogger(LukeMain.class); 39 | 40 | private static JFrame frame; 41 | 42 | public static JFrame getOwnerFrame() { 43 | return frame; 44 | } 45 | 46 | private static void createAndShowGUI() { 47 | 48 | // uncaught error handler 49 | MessageBroker messageBroker = MessageBroker.getInstance(); 50 | Thread.setDefaultUncaughtExceptionHandler((thread, cause) -> 51 | handle(cause, messageBroker) 52 | ); 53 | 54 | try { 55 | frame = new LukeWindowProvider().get(); 56 | frame.setLocation(200, 100); 57 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 58 | frame.pack(); 59 | frame.setVisible(true); 60 | 61 | // show open index dialog 62 | OpenIndexDialogFactory openIndexDialogFactory = OpenIndexDialogFactory.getInstance(); 63 | new DialogOpener<>(openIndexDialogFactory).open(MessageUtils.getLocalizedMessage("openindex.dialog.title"), 600, 420, 64 | (factory) -> { 65 | }); 66 | } catch (IOException e) { 67 | messageBroker.showUnknownErrorMessage(); 68 | log.error("Cannot initialize components.", e); 69 | } 70 | } 71 | 72 | public static void main(String[] args) throws Exception { 73 | 74 | String lookAndFeelClassName = UIManager.getSystemLookAndFeelClassName(); 75 | if (!lookAndFeelClassName.contains("AquaLookAndFeel") && !lookAndFeelClassName.contains("PlasticXPLookAndFeel")) { 76 | // may be running on linux platform 77 | lookAndFeelClassName = "javax.swing.plaf.metal.MetalLookAndFeel"; 78 | } 79 | UIManager.setLookAndFeel(lookAndFeelClassName); 80 | 81 | GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment(); 82 | genv.registerFont(FontUtils.createElegantIconFont()); 83 | 84 | javax.swing.SwingUtilities.invokeLater(LukeMain::createAndShowGUI); 85 | 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/MessageBroker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | /** Message broker */ 24 | public class MessageBroker { 25 | 26 | private static final MessageBroker instance = new MessageBroker(); 27 | 28 | private List receivers = new ArrayList<>(); 29 | 30 | public static MessageBroker getInstance() { 31 | return instance; 32 | } 33 | 34 | public void registerReceiver(MessageReceiver receiver) { 35 | receivers.add(receiver); 36 | } 37 | 38 | public void showStatusMessage(String message) { 39 | for (MessageReceiver receiver : receivers) { 40 | receiver.showStatusMessage(message); 41 | } 42 | } 43 | 44 | public void showUnknownErrorMessage() { 45 | for (MessageReceiver receiver : receivers) { 46 | receiver.showUnknownErrorMessage(); 47 | } 48 | } 49 | 50 | public void clearStatusMessage() { 51 | for (MessageReceiver receiver : receivers) { 52 | receiver.clearStatusMessage(); 53 | } 54 | } 55 | 56 | public interface MessageReceiver { 57 | void showStatusMessage(String message); 58 | 59 | void showUnknownErrorMessage(); 60 | 61 | void clearStatusMessage(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/Preferences.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop; 19 | 20 | import java.awt.Color; 21 | import java.io.IOException; 22 | import java.util.List; 23 | 24 | /** Preference */ 25 | public interface Preferences { 26 | 27 | List getHistory(); 28 | 29 | void addHistory(String indexPath) throws IOException; 30 | 31 | boolean isReadOnly(); 32 | 33 | String getDirImpl(); 34 | 35 | boolean isNoReader(); 36 | 37 | boolean isUseCompound(); 38 | 39 | boolean isKeepAllCommits(); 40 | 41 | void setIndexOpenerPrefs(boolean readOnly, String dirImpl, boolean noReader, boolean useCompound, boolean keepAllCommits) throws IOException; 42 | 43 | ColorTheme getColorTheme(); 44 | 45 | void setColorTheme(ColorTheme theme) throws IOException; 46 | 47 | enum ColorTheme { 48 | 49 | /* Gray theme */ 50 | GRAY(Color.decode("#e6e6e6")), 51 | /* Classic theme */ 52 | CLASSIC(Color.decode("#ece9d0")), 53 | /* Sandstone theme */ 54 | SANDSTONE(Color.decode("#ddd9d4")), 55 | /* Navy theme */ 56 | NAVY(Color.decode("#e6e6ff")); 57 | 58 | private Color backgroundColor; 59 | 60 | ColorTheme(Color backgroundColor) { 61 | this.backgroundColor = backgroundColor; 62 | } 63 | 64 | public Color getBackgroundColor() { 65 | return backgroundColor; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/PreferencesFactory.java: -------------------------------------------------------------------------------- 1 | package org.apache.lucene.luke.app.desktop; 2 | 3 | import java.io.IOException; 4 | 5 | /** Factory of {@link Preferences} */ 6 | public class PreferencesFactory { 7 | 8 | private static Preferences prefs; 9 | 10 | public synchronized static Preferences getInstance() throws IOException { 11 | if (prefs == null) { 12 | prefs = new PreferencesImpl(); 13 | } 14 | return prefs; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/AnalysisTabOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components; 19 | 20 | import org.apache.lucene.analysis.Analyzer; 21 | import org.apache.lucene.luke.models.analysis.CustomAnalyzerConfig; 22 | 23 | /** Operator for the Analysis tab */ 24 | public interface AnalysisTabOperator extends ComponentOperatorRegistry.ComponentOperator { 25 | 26 | void setAnalyzerByType(String analyzerType); 27 | 28 | void setAnalyzerByCustomConfiguration(CustomAnalyzerConfig config); 29 | 30 | Analyzer getCurrentAnalyzer(); 31 | 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/ComponentOperatorRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | import java.util.Optional; 23 | 24 | /** An utility class for interaction between components */ 25 | public class ComponentOperatorRegistry { 26 | 27 | private static final ComponentOperatorRegistry instance = new ComponentOperatorRegistry(); 28 | 29 | private final Map, Object> operators = new HashMap<>(); 30 | 31 | public static ComponentOperatorRegistry getInstance() { 32 | return instance; 33 | } 34 | 35 | public void register(Class type, T operator) { 36 | if (!operators.containsKey(type)) { 37 | operators.put(type, operator); 38 | } 39 | } 40 | 41 | @SuppressWarnings("unchecked") 42 | public Optional get(Class type) { 43 | return Optional.ofNullable((T) operators.get(type)); 44 | } 45 | 46 | public interface ComponentOperator { 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/DocumentsTabOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components; 19 | 20 | /** Operator for the Documents tab */ 21 | public interface DocumentsTabOperator extends ComponentOperatorRegistry.ComponentOperator { 22 | void browseTerm(String field, String term); 23 | 24 | void displayLatestDoc(); 25 | 26 | void displayDoc(int donid); 27 | 28 | void seekNextTerm(); 29 | 30 | void showFirstTermDoc(); 31 | } -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/LogsPanelProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components; 19 | 20 | import org.apache.lucene.luke.app.desktop.util.MessageUtils; 21 | 22 | import javax.swing.BorderFactory; 23 | import javax.swing.JLabel; 24 | import javax.swing.JPanel; 25 | import javax.swing.JScrollPane; 26 | import javax.swing.JTextArea; 27 | import java.awt.BorderLayout; 28 | import java.awt.FlowLayout; 29 | import java.io.File; 30 | 31 | /** Provider of the Logs panel */ 32 | public final class LogsPanelProvider { 33 | 34 | private static final String LOG_FILE = System.getProperty("user.home") + File.separator + ".luke.d" + File.separator + "luke.log"; 35 | 36 | private final JTextArea logTextArea; 37 | 38 | public LogsPanelProvider(JTextArea logTextArea) { 39 | this.logTextArea = logTextArea; 40 | } 41 | 42 | public JPanel get() { 43 | JPanel panel = new JPanel(new BorderLayout()); 44 | panel.setOpaque(false); 45 | panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); 46 | 47 | JPanel header = new JPanel(new FlowLayout(FlowLayout.LEADING)); 48 | header.setOpaque(false); 49 | header.add(new JLabel(MessageUtils.getLocalizedMessage("logs.label.see_also"))); 50 | 51 | JLabel logPathLabel = new JLabel(LOG_FILE); 52 | header.add(logPathLabel); 53 | 54 | panel.add(header, BorderLayout.PAGE_START); 55 | 56 | panel.add(new JScrollPane(logTextArea), BorderLayout.CENTER); 57 | return panel; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/LukeWindowOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components; 19 | 20 | import org.apache.lucene.luke.app.desktop.Preferences; 21 | 22 | /** Operator for the root window */ 23 | public interface LukeWindowOperator extends ComponentOperatorRegistry.ComponentOperator { 24 | void setColorTheme(Preferences.ColorTheme theme); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/SearchTabOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components; 19 | 20 | /** Operator for the Search tab */ 21 | public interface SearchTabOperator extends ComponentOperatorRegistry.ComponentOperator { 22 | void searchByTerm(String field, String term); 23 | 24 | void mltSearch(int docNum); 25 | 26 | void enableExactHitsCB(boolean value); 27 | 28 | void setExactHits(boolean value); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/TabSwitcherProxy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components; 19 | 20 | /** An utility class for switching tabs. */ 21 | public class TabSwitcherProxy { 22 | 23 | private static final TabSwitcherProxy instance = new TabSwitcherProxy(); 24 | 25 | private TabSwitcher switcher; 26 | 27 | public static TabSwitcherProxy getInstance() { 28 | return instance; 29 | } 30 | 31 | public void set(TabSwitcher switcher) { 32 | if (this.switcher == null) { 33 | this.switcher = switcher; 34 | } 35 | } 36 | 37 | public void switchTab(TabbedPaneProvider.Tab tab) { 38 | if (switcher == null) { 39 | throw new IllegalStateException(); 40 | } 41 | switcher.switchTab(tab); 42 | } 43 | 44 | public interface TabSwitcher { 45 | void switchTab(TabbedPaneProvider.Tab tab); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/TableColumnInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components; 19 | 20 | /** Holder of table column attributes */ 21 | public interface TableColumnInfo { 22 | 23 | String getColName(); 24 | 25 | int getIndex(); 26 | 27 | Class getType(); 28 | 29 | default int getColumnWidth() { 30 | return 0; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/TableModelBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components; 19 | 20 | import org.apache.lucene.luke.app.desktop.util.TableUtils; 21 | 22 | import javax.swing.table.AbstractTableModel; 23 | import java.util.Map; 24 | 25 | /** Base table model that stores table's meta data and content. This also provides some default implementation of the {@link javax.swing.table.TableModel} interface. */ 26 | public abstract class TableModelBase extends AbstractTableModel { 27 | 28 | private final Map columnMap = TableUtils.columnMap(columnInfos()); 29 | 30 | private final String[] colNames = TableUtils.columnNames(columnInfos()); 31 | 32 | protected final Object[][] data; 33 | 34 | protected TableModelBase() { 35 | this.data = new Object[0][colNames.length]; 36 | } 37 | 38 | protected TableModelBase(int rows) { 39 | this.data = new Object[rows][colNames.length]; 40 | } 41 | 42 | protected abstract T[] columnInfos(); 43 | 44 | @Override 45 | public int getRowCount() { 46 | return data.length; 47 | } 48 | 49 | @Override 50 | public int getColumnCount() { 51 | return colNames.length; 52 | } 53 | 54 | @Override 55 | public String getColumnName(int colIndex) { 56 | if (columnMap.containsKey(colIndex)) { 57 | return columnMap.get(colIndex).getColName(); 58 | } 59 | return ""; 60 | } 61 | 62 | @Override 63 | public Class getColumnClass(int colIndex) { 64 | if (columnMap.containsKey(colIndex)) { 65 | return columnMap.get(colIndex).getType(); 66 | } 67 | return Object.class; 68 | } 69 | 70 | 71 | @Override 72 | public Object getValueAt(int rowIndex, int columnIndex) { 73 | return data[rowIndex][columnIndex]; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/dialog/HelpDialogFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components.dialog; 19 | 20 | import org.apache.lucene.luke.app.desktop.Preferences; 21 | import org.apache.lucene.luke.app.desktop.PreferencesFactory; 22 | import org.apache.lucene.luke.app.desktop.util.DialogOpener; 23 | import org.apache.lucene.luke.app.desktop.util.MessageUtils; 24 | 25 | import javax.swing.BorderFactory; 26 | import javax.swing.JButton; 27 | import javax.swing.JComponent; 28 | import javax.swing.JDialog; 29 | import javax.swing.JLabel; 30 | import javax.swing.JPanel; 31 | import java.awt.BorderLayout; 32 | import java.awt.Dialog; 33 | import java.awt.Dimension; 34 | import java.awt.FlowLayout; 35 | import java.awt.GridLayout; 36 | import java.awt.Window; 37 | import java.io.IOException; 38 | 39 | /** Factory of help dialog */ 40 | public final class HelpDialogFactory implements DialogOpener.DialogFactory { 41 | 42 | private static HelpDialogFactory instance; 43 | 44 | private final Preferences prefs; 45 | 46 | private JDialog dialog; 47 | 48 | private String desc; 49 | 50 | private JComponent helpContent; 51 | 52 | public synchronized static HelpDialogFactory getInstance() throws IOException { 53 | if (instance == null) { 54 | instance = new HelpDialogFactory(); 55 | } 56 | return instance; 57 | } 58 | 59 | private HelpDialogFactory() throws IOException { 60 | this.prefs = PreferencesFactory.getInstance(); 61 | } 62 | 63 | public void setDesc(String desc) { 64 | this.desc = desc; 65 | } 66 | 67 | public void setContent(JComponent helpContent) { 68 | this.helpContent = helpContent; 69 | } 70 | 71 | @Override 72 | public JDialog create(Window owner, String title, int width, int height) { 73 | dialog = new JDialog(owner, title, Dialog.ModalityType.APPLICATION_MODAL); 74 | dialog.add(content()); 75 | dialog.setSize(new Dimension(width, height)); 76 | dialog.setLocationRelativeTo(owner); 77 | dialog.getContentPane().setBackground(prefs.getColorTheme().getBackgroundColor()); 78 | return dialog; 79 | } 80 | 81 | private JPanel content() { 82 | JPanel panel = new JPanel(new BorderLayout()); 83 | panel.setOpaque(false); 84 | panel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15)); 85 | 86 | JPanel header = new JPanel(new FlowLayout(FlowLayout.LEADING)); 87 | header.setOpaque(false); 88 | header.add(new JLabel(desc)); 89 | panel.add(header, BorderLayout.PAGE_START); 90 | 91 | JPanel center = new JPanel(new GridLayout(1, 1)); 92 | center.setOpaque(false); 93 | center.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 94 | center.add(helpContent); 95 | panel.add(center, BorderLayout.CENTER); 96 | 97 | JPanel footer = new JPanel(new FlowLayout(FlowLayout.TRAILING)); 98 | footer.setOpaque(false); 99 | JButton closeBtn = new JButton(MessageUtils.getLocalizedMessage("button.close")); 100 | closeBtn.addActionListener(e -> dialog.dispose()); 101 | footer.add(closeBtn); 102 | panel.add(footer, BorderLayout.PAGE_END); 103 | 104 | return panel; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/dialog/analysis/EditFiltersMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components.dialog.analysis; 19 | 20 | /** Edit filters mode */ 21 | public enum EditFiltersMode { 22 | CHARFILTER, TOKENFILTER; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/dialog/analysis/EditParamsMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components.dialog.analysis; 19 | 20 | /** Edit parameters mode */ 21 | public enum EditParamsMode { 22 | CHARFILTER, TOKENIZER, TOKENFILTER; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/dialog/analysis/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Dialogs used in the Analysis tab */ 19 | package org.apache.lucene.luke.app.desktop.components.dialog.analysis; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/dialog/documents/AddDocumentDialogOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components.dialog.documents; 19 | 20 | import org.apache.lucene.analysis.Analyzer; 21 | import org.apache.lucene.luke.app.desktop.components.ComponentOperatorRegistry; 22 | 23 | /** Operator of add dodument dialog */ 24 | public interface AddDocumentDialogOperator extends ComponentOperatorRegistry.ComponentOperator { 25 | void setAnalyzer(Analyzer analyzer); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/dialog/documents/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Dialogs used in the Documents tab */ 19 | package org.apache.lucene.luke.app.desktop.components.dialog.documents; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/dialog/menubar/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Dialogs used in the menu bar */ 19 | package org.apache.lucene.luke.app.desktop.components.dialog.menubar; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/dialog/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Dialogs */ 19 | package org.apache.lucene.luke.app.desktop.components.dialog; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/dialog/search/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Dialogs used in the Search tab */ 19 | package org.apache.lucene.luke.app.desktop.components.dialog.search; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/fragments/analysis/CustomAnalyzerPanelOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components.fragments.analysis; 19 | 20 | import org.apache.lucene.luke.app.desktop.components.ComponentOperatorRegistry; 21 | import org.apache.lucene.luke.models.analysis.Analysis; 22 | 23 | import java.util.List; 24 | import java.util.Map; 25 | 26 | /** Operator of the custom analyzer panel */ 27 | public interface CustomAnalyzerPanelOperator extends ComponentOperatorRegistry.ComponentOperator { 28 | void setAnalysisModel(Analysis analysisModel); 29 | 30 | void resetAnalysisComponents(); 31 | 32 | void updateCharFilters(List deletedIndexes); 33 | 34 | void updateTokenFilters(List deletedIndexes); 35 | 36 | Map getCharFilterParams(int index); 37 | 38 | void updateCharFilterParams(int index, Map updatedParams); 39 | 40 | void updateTokenizerParams(Map updatedParams); 41 | 42 | Map getTokenFilterParams(int index); 43 | 44 | void updateTokenFilterParams(int index, Map updatedParams); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/fragments/analysis/PresetAnalyzerPanelOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components.fragments.analysis; 19 | 20 | import org.apache.lucene.analysis.Analyzer; 21 | import org.apache.lucene.luke.app.desktop.components.ComponentOperatorRegistry; 22 | 23 | import java.util.Collection; 24 | 25 | /** Operator of the preset analyzer panel */ 26 | public interface PresetAnalyzerPanelOperator extends ComponentOperatorRegistry.ComponentOperator { 27 | void setPresetAnalyzers(Collection> presetAnalyzers); 28 | 29 | void setSelectedAnalyzer(Class analyzer); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/fragments/analysis/PresetAnalyzerPanelProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components.fragments.analysis; 19 | 20 | import org.apache.lucene.analysis.Analyzer; 21 | import org.apache.lucene.luke.app.desktop.components.AnalysisTabOperator; 22 | import org.apache.lucene.luke.app.desktop.components.ComponentOperatorRegistry; 23 | import org.apache.lucene.luke.app.desktop.util.MessageUtils; 24 | 25 | import javax.swing.BorderFactory; 26 | import javax.swing.ComboBoxModel; 27 | import javax.swing.DefaultComboBoxModel; 28 | import javax.swing.JComboBox; 29 | import javax.swing.JLabel; 30 | import javax.swing.JPanel; 31 | import java.awt.BorderLayout; 32 | import java.awt.Dimension; 33 | import java.awt.FlowLayout; 34 | import java.awt.event.ActionEvent; 35 | import java.util.Collection; 36 | 37 | /** Provider of the preset analyzer panel */ 38 | public final class PresetAnalyzerPanelProvider implements PresetAnalyzerPanelOperator { 39 | 40 | private final ComponentOperatorRegistry operatorRegistry; 41 | 42 | private final JComboBox analyzersCB = new JComboBox<>(); 43 | 44 | private final ListenerFunctions listeners = new ListenerFunctions(); 45 | 46 | public PresetAnalyzerPanelProvider() { 47 | this.operatorRegistry = ComponentOperatorRegistry.getInstance(); 48 | operatorRegistry.register(PresetAnalyzerPanelOperator.class, this); 49 | } 50 | 51 | public JPanel get() { 52 | JPanel panel = new JPanel(new BorderLayout()); 53 | panel.setOpaque(false); 54 | panel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); 55 | 56 | JLabel header = new JLabel(MessageUtils.getLocalizedMessage("analysis_preset.label.preset")); 57 | panel.add(header, BorderLayout.PAGE_START); 58 | 59 | JPanel center = new JPanel(new FlowLayout(FlowLayout.LEADING)); 60 | center.setOpaque(false); 61 | center.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); 62 | center.setPreferredSize(new Dimension(400, 40)); 63 | analyzersCB.addActionListener(listeners::setAnalyzer); 64 | analyzersCB.setEnabled(false); 65 | center.add(analyzersCB); 66 | panel.add(center, BorderLayout.CENTER); 67 | 68 | return panel; 69 | } 70 | 71 | // control methods 72 | 73 | @Override 74 | public void setPresetAnalyzers(Collection> presetAnalyzers) { 75 | String[] analyzerNames = presetAnalyzers.stream().map(Class::getName).toArray(String[]::new); 76 | ComboBoxModel model = new DefaultComboBoxModel<>(analyzerNames); 77 | analyzersCB.setModel(model); 78 | analyzersCB.setEnabled(true); 79 | } 80 | 81 | @Override 82 | public void setSelectedAnalyzer(Class analyzer) { 83 | analyzersCB.setSelectedItem(analyzer.getName()); 84 | } 85 | 86 | private class ListenerFunctions { 87 | 88 | void setAnalyzer(ActionEvent e) { 89 | operatorRegistry.get(AnalysisTabOperator.class).ifPresent(operator -> 90 | operator.setAnalyzerByType((String) analyzersCB.getSelectedItem()) 91 | ); 92 | } 93 | 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/fragments/analysis/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** UI parts embedded in the Analysis tab */ 19 | package org.apache.lucene.luke.app.desktop.components.fragments.analysis; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/fragments/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** UI parts embedded in tabs */ 19 | package org.apache.lucene.luke.app.desktop.components.fragments; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/fragments/search/AnalyzerTabOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components.fragments.search; 19 | 20 | import org.apache.lucene.analysis.Analyzer; 21 | import org.apache.lucene.luke.app.desktop.components.ComponentOperatorRegistry; 22 | 23 | /** Operator for the Analyzer tab */ 24 | public interface AnalyzerTabOperator extends ComponentOperatorRegistry.ComponentOperator { 25 | void setAnalyzer(Analyzer analyzer); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/fragments/search/FieldValuesTabOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components.fragments.search; 19 | 20 | import org.apache.lucene.luke.app.desktop.components.ComponentOperatorRegistry; 21 | 22 | import java.util.Collection; 23 | import java.util.Set; 24 | 25 | /** Operator of the FieldValues tab */ 26 | public interface FieldValuesTabOperator extends ComponentOperatorRegistry.ComponentOperator { 27 | void setFields(Collection fields); 28 | 29 | Set getFieldsToLoad(); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/fragments/search/MLTTabOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components.fragments.search; 19 | 20 | import org.apache.lucene.analysis.Analyzer; 21 | import org.apache.lucene.luke.app.desktop.components.ComponentOperatorRegistry; 22 | import org.apache.lucene.luke.models.search.MLTConfig; 23 | 24 | import java.util.Collection; 25 | 26 | /** Operator of the MLT tab */ 27 | public interface MLTTabOperator extends ComponentOperatorRegistry.ComponentOperator { 28 | void setAnalyzer(Analyzer analyzer); 29 | 30 | void setFields(Collection fields); 31 | 32 | MLTConfig getConfig(); 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/fragments/search/QueryParserTabOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components.fragments.search; 19 | 20 | import org.apache.lucene.luke.app.desktop.components.ComponentOperatorRegistry; 21 | import org.apache.lucene.luke.models.search.QueryParserConfig; 22 | 23 | import java.util.Collection; 24 | 25 | /** Operator for the QueryParser tab */ 26 | public interface QueryParserTabOperator extends ComponentOperatorRegistry.ComponentOperator { 27 | void setSearchableFields(Collection searchableFields); 28 | 29 | void setRangeSearchableFields(Collection rangeSearchableFields); 30 | 31 | QueryParserConfig getConfig(); 32 | 33 | String getDefaultField(); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/fragments/search/SimilarityTabOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components.fragments.search; 19 | 20 | import org.apache.lucene.luke.app.desktop.components.ComponentOperatorRegistry; 21 | import org.apache.lucene.luke.models.search.SimilarityConfig; 22 | 23 | /** Operator for the Similarity tab */ 24 | public interface SimilarityTabOperator extends ComponentOperatorRegistry.ComponentOperator { 25 | SimilarityConfig getConfig(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/fragments/search/SortTabOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.components.fragments.search; 19 | 20 | import org.apache.lucene.luke.app.desktop.components.ComponentOperatorRegistry; 21 | import org.apache.lucene.luke.models.search.Search; 22 | import org.apache.lucene.search.Sort; 23 | 24 | import java.util.Collection; 25 | 26 | /** Operator for the Sort tab */ 27 | public interface SortTabOperator extends ComponentOperatorRegistry.ComponentOperator { 28 | void setSearchModel(Search model); 29 | 30 | void setSortableFields(Collection sortableFields); 31 | 32 | Sort getSort(); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/fragments/search/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** UI parts embedded in tabs */ 19 | package org.apache.lucene.luke.app.desktop.components.fragments.search; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/components/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** UI components of the desktop Luke */ 19 | package org.apache.lucene.luke.app.desktop.components; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/dto/documents/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** DTO classes */ 19 | package org.apache.lucene.luke.app.desktop.dto.documents; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Views (UIs) for Luke */ 19 | package org.apache.lucene.luke.app.desktop; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/DialogOpener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.util; 19 | 20 | import org.apache.lucene.luke.app.desktop.LukeMain; 21 | 22 | import javax.swing.JDialog; 23 | import java.awt.Window; 24 | import java.util.function.Consumer; 25 | 26 | /** An utility class for opening a dialog */ 27 | public class DialogOpener { 28 | 29 | private final T factory; 30 | 31 | public DialogOpener(T factory) { 32 | this.factory = factory; 33 | } 34 | 35 | public void open(String title, int width, int height, Consumer initializer, 36 | String... styleSheets) { 37 | open(LukeMain.getOwnerFrame(), title, width, height, initializer, styleSheets); 38 | } 39 | 40 | public void open(Window owner, String title, int width, int height, Consumer initializer, 41 | String... styleSheets) { 42 | initializer.accept(factory); 43 | JDialog dialog = factory.create(owner, title, width, height); 44 | dialog.setVisible(true); 45 | } 46 | 47 | public interface DialogFactory { 48 | JDialog create(Window owner, String title, int width, int height); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/ExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.util; 19 | 20 | import org.apache.lucene.luke.app.desktop.MessageBroker; 21 | import org.apache.lucene.luke.models.LukeException; 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | 25 | /** An utility class for handling exception */ 26 | public final class ExceptionHandler { 27 | 28 | private static final Logger log = LoggerFactory.getLogger(ExceptionHandler.class); 29 | 30 | public static void handle(Throwable t, MessageBroker messageBroker) { 31 | if (t instanceof LukeException) { 32 | Throwable cause = t.getCause(); 33 | String message = (cause == null) ? t.getMessage() : t.getMessage() + " " + cause.getMessage(); 34 | log.warn(t.getMessage(), t); 35 | messageBroker.showStatusMessage(message); 36 | } else { 37 | log.error(t.getMessage(), t); 38 | messageBroker.showUnknownErrorMessage(); 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/FontUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.util; 19 | 20 | import javax.swing.JLabel; 21 | import java.awt.Font; 22 | import java.awt.FontFormatException; 23 | import java.awt.font.TextAttribute; 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | import java.util.Map; 27 | 28 | /** Font utilities */ 29 | public class FontUtils { 30 | 31 | @SuppressWarnings("unchecked") 32 | public static JLabel toLinkText(JLabel label) { 33 | label.setForeground(StyleConstants.LINK_COLOR); 34 | Font font = label.getFont(); 35 | Map attributes = (Map) font.getAttributes(); 36 | attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); 37 | label.setFont(font.deriveFont(attributes)); 38 | return label; 39 | } 40 | 41 | public static Font createElegantIconFont() throws IOException, FontFormatException { 42 | InputStream is = FontUtils.class.getClassLoader().getResourceAsStream("font/ElegantIcons.ttf"); 43 | return Font.createFont(Font.TRUETYPE_FONT, is); 44 | } 45 | 46 | /** 47 | * Generates HTML text with embedded Elegant Icon Font. 48 | * See: https://www.elegantthemes.com/blog/resources/elegant-icon-font 49 | * 50 | * @param iconRef HTML numeric character reference of the icon 51 | */ 52 | public static String elegantIconHtml(String iconRef) { 53 | return "" + iconRef + ""; 54 | } 55 | 56 | /** 57 | * Generates HTML text with embedded Elegant Icon Font. 58 | * 59 | * @param iconRef HTML numeric character reference of the icon 60 | * @param text 61 | */ 62 | public static String elegantIconHtml(String iconRef, String text) { 63 | return "" + iconRef + " " + text + ""; 64 | } 65 | 66 | private FontUtils() { 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/ImageUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.util; 19 | 20 | import javax.swing.ImageIcon; 21 | import java.awt.Image; 22 | 23 | /** Image utilities */ 24 | public class ImageUtils { 25 | 26 | private static final int DEFAULT_ICON_WIDTH = 20; 27 | 28 | private static final int DEFAULT_ICON_HEIGHT = 20; 29 | 30 | public static ImageIcon createImageIcon(String path, int width, int height) { 31 | return createImageIcon(path, "", width, height); 32 | } 33 | 34 | public static ImageIcon createImageIcon(String path, String description, int width, int height) { 35 | java.net.URL imgURL = ImageUtils.class.getResource(path); 36 | if (imgURL != null) { 37 | ImageIcon originalIcon = new ImageIcon(imgURL, description); 38 | ImageIcon icon = new ImageIcon(originalIcon.getImage().getScaledInstance(width, height, Image.SCALE_DEFAULT)); 39 | return icon; 40 | } else { 41 | return null; 42 | } 43 | } 44 | 45 | private ImageUtils() { 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/ListUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.util; 19 | 20 | import javax.swing.JList; 21 | import javax.swing.ListModel; 22 | import java.util.List; 23 | import java.util.function.IntFunction; 24 | import java.util.stream.Collectors; 25 | import java.util.stream.IntStream; 26 | 27 | /** List model utilities */ 28 | public class ListUtils { 29 | 30 | public static List getAllItems(JList jlist) { 31 | ListModel model = jlist.getModel(); 32 | return getAllItems(jlist, model::getElementAt); 33 | } 34 | 35 | public static List getAllItems(JList jlist, IntFunction mapFunc) { 36 | ListModel model = jlist.getModel(); 37 | return IntStream.range(0, model.getSize()).mapToObj(mapFunc).collect(Collectors.toList()); 38 | } 39 | 40 | private ListUtils() { 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/MessageUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.util; 19 | 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | import java.io.InputStreamReader; 23 | import java.nio.charset.StandardCharsets; 24 | import java.text.MessageFormat; 25 | import java.util.Locale; 26 | import java.util.PropertyResourceBundle; 27 | import java.util.ResourceBundle; 28 | 29 | /** 30 | * Utilities for accessing message resources. 31 | */ 32 | public class MessageUtils { 33 | 34 | public static String getLocalizedMessage(String key) { 35 | return bundle.getString(key); 36 | } 37 | 38 | public static String getLocalizedMessage(String key, Object... args) { 39 | String pattern = bundle.getString(key); 40 | return new MessageFormat(pattern, Locale.ENGLISH).format(args); 41 | } 42 | 43 | // https://stackoverflow.com/questions/4659929/how-to-use-utf-8-in-resource-properties-with-resourcebundle 44 | private static ResourceBundle.Control UTF8_RESOURCEBUNDLE_CONTROL = new ResourceBundle.Control() { 45 | @Override 46 | public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException { 47 | String bundleName = toBundleName(baseName, locale); 48 | String resourceName = toResourceName(bundleName, "properties"); 49 | try (InputStream is = loader.getResourceAsStream(resourceName)) { 50 | return new PropertyResourceBundle(new InputStreamReader(is, StandardCharsets.UTF_8)); 51 | } 52 | } 53 | }; 54 | 55 | private static ResourceBundle bundle = ResourceBundle.getBundle("messages", Locale.ENGLISH, UTF8_RESOURCEBUNDLE_CONTROL); 56 | 57 | private MessageUtils() { 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/NumericUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.util; 19 | 20 | import java.util.Arrays; 21 | 22 | /** Utilities for handling numeric values */ 23 | public class NumericUtils { 24 | 25 | public static int[] convertToIntArray(String value, boolean ignoreException) throws NumberFormatException { 26 | if (StringUtils.isNullOrEmpty(value)) { 27 | return new int[]{0}; 28 | } 29 | try { 30 | return Arrays.stream(value.trim().split(",")).mapToInt(Integer::parseInt).toArray(); 31 | } catch (NumberFormatException e) { 32 | if (ignoreException) { 33 | return new int[]{0}; 34 | } else { 35 | throw e; 36 | } 37 | } 38 | } 39 | 40 | public static long[] convertToLongArray(String value, boolean ignoreException) throws NumberFormatException { 41 | if (StringUtils.isNullOrEmpty(value)) { 42 | return new long[]{0}; 43 | } 44 | try { 45 | return Arrays.stream(value.trim().split(",")).mapToLong(Long::parseLong).toArray(); 46 | } catch (NumberFormatException e) { 47 | if (ignoreException) { 48 | return new long[]{0}; 49 | } else { 50 | throw e; 51 | } 52 | } 53 | } 54 | 55 | public static float[] convertToFloatArray(String value, boolean ignoreException) throws NumberFormatException { 56 | if (StringUtils.isNullOrEmpty(value)) { 57 | return new float[]{0}; 58 | } 59 | try { 60 | String[] strVals = value.trim().split(","); 61 | float[] values = new float[strVals.length]; 62 | for (int i = 0; i < strVals.length; i++) { 63 | values[i] = Float.parseFloat(strVals[i]); 64 | } 65 | return values; 66 | } catch (NumberFormatException e) { 67 | if (ignoreException) { 68 | return new float[]{0}; 69 | } else { 70 | throw e; 71 | } 72 | } 73 | } 74 | 75 | public static double[] convertToDoubleArray(String value, boolean ignoreException) throws NumberFormatException { 76 | if (StringUtils.isNullOrEmpty(value)) { 77 | return new double[]{0}; 78 | } 79 | try { 80 | return Arrays.stream(value.trim().split(",")).mapToDouble(Double::parseDouble).toArray(); 81 | } catch (NumberFormatException e) { 82 | if (ignoreException) { 83 | return new double[]{0}; 84 | } else { 85 | throw e; 86 | } 87 | } 88 | } 89 | 90 | public static long tryConvertToLongValue(String value) throws NumberFormatException { 91 | try { 92 | // try parse to long 93 | return Long.parseLong(value.trim()); 94 | } catch (NumberFormatException e) { 95 | // try parse to double 96 | double dvalue = Double.parseDouble(value.trim()); 97 | return org.apache.lucene.util.NumericUtils.doubleToSortableLong(dvalue); 98 | } 99 | } 100 | 101 | private NumericUtils() { 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/StringUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.util; 19 | 20 | import java.util.Objects; 21 | 22 | /** Utilities for handling strings */ 23 | public class StringUtils { 24 | 25 | public static boolean isNullOrEmpty(String s) { 26 | return Objects.isNull(s) || s.equals(""); 27 | } 28 | 29 | private StringUtils() { 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/StyleConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.util; 19 | 20 | import java.awt.Color; 21 | import java.awt.Font; 22 | 23 | /** Constants for the default styles */ 24 | public class StyleConstants { 25 | 26 | public static Font FONT_BUTTON_LARGE = new Font("SanSerif", Font.PLAIN, 15); 27 | 28 | public static Font FONT_MONOSPACE_LARGE = new Font("monospaced", Font.PLAIN, 12); 29 | 30 | public static Color LINK_COLOR = Color.decode("#0099ff"); 31 | 32 | public static Color DISABLED_COLOR = Color.decode("#d9d9d9"); 33 | 34 | public static int TABLE_ROW_HEIGHT_DEFAULT = 18; 35 | 36 | public static int TABLE_COLUMN_MARGIN_DEFAULT = 10; 37 | 38 | public static int TABLE_ROW_MARGIN_DEFAULT = 3; 39 | 40 | private StyleConstants() { 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/TabUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.util; 19 | 20 | import javax.swing.JTabbedPane; 21 | import javax.swing.UIManager; 22 | import java.awt.Graphics; 23 | 24 | /** Tab utilities */ 25 | public class TabUtils { 26 | 27 | public static void forceTransparent(JTabbedPane tabbedPane) { 28 | String lookAndFeelClassName = UIManager.getLookAndFeel().getClass().getName(); 29 | if (lookAndFeelClassName.contains("AquaLookAndFeel")) { 30 | // may be running on mac OS. nothing to do. 31 | return; 32 | } 33 | // https://coderanch.com/t/600541/java/JtabbedPane-transparency 34 | tabbedPane.setUI(new javax.swing.plaf.metal.MetalTabbedPaneUI() { 35 | protected void paintContentBorder(Graphics g, int tabPlacement, int selectedIndex) { 36 | } 37 | }); 38 | } 39 | 40 | private TabUtils(){} 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/TableUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.util; 19 | 20 | import org.apache.lucene.luke.app.desktop.components.TableColumnInfo; 21 | 22 | import javax.swing.JTable; 23 | import javax.swing.table.DefaultTableModel; 24 | import javax.swing.table.TableModel; 25 | import java.awt.Color; 26 | import java.awt.event.MouseListener; 27 | import java.util.Arrays; 28 | import java.util.TreeMap; 29 | import java.util.function.UnaryOperator; 30 | import java.util.stream.Collectors; 31 | 32 | /** Table utilities */ 33 | public class TableUtils { 34 | 35 | public static void setupTable(JTable table, int selectionModel, TableModel model, MouseListener mouseListener, 36 | int... colWidth) { 37 | table.setFillsViewportHeight(true); 38 | table.setFont(StyleConstants.FONT_MONOSPACE_LARGE); 39 | table.setRowHeight(StyleConstants.TABLE_ROW_HEIGHT_DEFAULT); 40 | table.setShowHorizontalLines(true); 41 | table.setShowVerticalLines(false); 42 | table.setGridColor(Color.lightGray); 43 | table.getColumnModel().setColumnMargin(StyleConstants.TABLE_COLUMN_MARGIN_DEFAULT); 44 | table.setRowMargin(StyleConstants.TABLE_ROW_MARGIN_DEFAULT); 45 | table.setSelectionMode(selectionModel); 46 | if (model != null) { 47 | table.setModel(model); 48 | } else { 49 | table.setModel(new DefaultTableModel()); 50 | } 51 | if (mouseListener != null) { 52 | table.removeMouseListener(mouseListener); 53 | table.addMouseListener(mouseListener); 54 | } 55 | for (int i = 0; i < colWidth.length; i++) { 56 | table.getColumnModel().getColumn(i).setMinWidth(colWidth[i]); 57 | table.getColumnModel().getColumn(i).setMaxWidth(colWidth[i]); 58 | } 59 | } 60 | 61 | public static void setEnabled(JTable table, boolean enabled) { 62 | table.setEnabled(enabled); 63 | if (enabled) { 64 | table.setRowSelectionAllowed(true); 65 | table.setForeground(Color.black); 66 | table.setBackground(Color.white); 67 | } else { 68 | table.setRowSelectionAllowed(false); 69 | table.setForeground(Color.gray); 70 | table.setBackground(Color.lightGray); 71 | } 72 | } 73 | 74 | public static String[] columnNames(T[] columns) { 75 | return columnMap(columns).entrySet().stream().map(e -> e.getValue().getColName()).toArray(String[]::new); 76 | } 77 | 78 | public static TreeMap columnMap(T[] columns) { 79 | return Arrays.stream(columns).collect(Collectors.toMap(T::getIndex, UnaryOperator.identity(), (e1, e2) -> e1, TreeMap::new)); 80 | } 81 | 82 | private TableUtils() { 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/TextAreaAppender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.util; 19 | 20 | import org.apache.logging.log4j.core.Filter; 21 | import org.apache.logging.log4j.core.Layout; 22 | import org.apache.logging.log4j.core.LogEvent; 23 | import org.apache.logging.log4j.core.appender.AbstractAppender; 24 | import org.apache.logging.log4j.core.config.Property; 25 | import org.apache.logging.log4j.core.config.plugins.Plugin; 26 | import org.apache.logging.log4j.core.config.plugins.PluginAttribute; 27 | import org.apache.logging.log4j.core.config.plugins.PluginElement; 28 | import org.apache.logging.log4j.core.config.plugins.PluginFactory; 29 | import org.apache.logging.log4j.core.layout.PatternLayout; 30 | 31 | import javax.swing.JTextArea; 32 | import java.io.Serializable; 33 | import java.nio.charset.StandardCharsets; 34 | import java.util.concurrent.locks.Lock; 35 | import java.util.concurrent.locks.ReadWriteLock; 36 | import java.util.concurrent.locks.ReentrantReadWriteLock; 37 | 38 | /** Log appender for text areas */ 39 | @Plugin(name = "TextAreaAppender", category = "Core", elementType = "appender", printObject = true) 40 | public final class TextAreaAppender extends AbstractAppender { 41 | 42 | private static JTextArea textArea; 43 | 44 | private final ReadWriteLock rwLock = new ReentrantReadWriteLock(); 45 | private final Lock readLock = rwLock.readLock(); 46 | 47 | protected TextAreaAppender(String name, Filter filter, 48 | org.apache.logging.log4j.core.Layout layout, final boolean ignoreExceptions) { 49 | super(name, filter, layout, ignoreExceptions, Property.EMPTY_ARRAY); 50 | } 51 | 52 | public static void setTextArea(JTextArea ta) { 53 | if (textArea != null) { 54 | throw new IllegalStateException("TextArea already set."); 55 | } 56 | textArea = ta; 57 | } 58 | 59 | @Override 60 | public void append(LogEvent event) { 61 | if (textArea == null) { 62 | throw new IllegalStateException(); 63 | } 64 | 65 | readLock.lock(); 66 | try { 67 | String message = new String(getLayout().toByteArray(event), StandardCharsets.UTF_8); 68 | textArea.append(message); 69 | } finally { 70 | readLock.unlock(); 71 | } 72 | } 73 | 74 | @PluginFactory 75 | public static TextAreaAppender createAppender( 76 | @PluginAttribute("name") String name, 77 | @PluginElement("Layout") Layout layout, 78 | @PluginElement("Filter") final Filter filter, 79 | @PluginAttribute("otherAttribute") String otherAttribute 80 | ) { 81 | if (name == null) { 82 | LOGGER.error("No name provided for MyCustomAppenderImpl"); 83 | return null; 84 | } 85 | if (layout == null) { 86 | layout = PatternLayout.createDefaultLayout(); 87 | } 88 | 89 | return new TextAreaAppender(name, filter, layout, true); 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/TextAreaPrintStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.util; 19 | 20 | import org.slf4j.Logger; 21 | 22 | import javax.swing.JTextArea; 23 | import java.io.ByteArrayOutputStream; 24 | import java.io.IOException; 25 | import java.io.PrintStream; 26 | import java.io.UnsupportedEncodingException; 27 | import java.nio.charset.Charset; 28 | import java.nio.charset.StandardCharsets; 29 | 30 | /** PrintStream for text areas */ 31 | public final class TextAreaPrintStream extends PrintStream { 32 | 33 | private Logger log; 34 | 35 | private ByteArrayOutputStream baos; 36 | 37 | private JTextArea textArea; 38 | 39 | public TextAreaPrintStream(JTextArea textArea, ByteArrayOutputStream baos, Charset charset, Logger log) throws UnsupportedEncodingException { 40 | super(baos, false, charset.name()); 41 | this.baos = baos; 42 | this.textArea = textArea; 43 | this.log = log; 44 | baos.reset(); 45 | } 46 | 47 | @Override 48 | public void println(String s) { 49 | try { 50 | baos.write(s.getBytes(StandardCharsets.UTF_8)); 51 | baos.write('\n'); 52 | } catch (IOException e) { 53 | log.error(e.getMessage(), e); 54 | } 55 | } 56 | 57 | @Override 58 | public void flush() { 59 | try { 60 | textArea.append(baos.toString(StandardCharsets.UTF_8.name())); 61 | } catch (IOException e) { 62 | log.error(e.getMessage(), e); 63 | } finally { 64 | baos.reset(); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/URLLabel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.util; 19 | 20 | import org.apache.lucene.luke.models.LukeException; 21 | 22 | import javax.swing.JLabel; 23 | import java.awt.Cursor; 24 | import java.awt.Desktop; 25 | import java.awt.event.MouseAdapter; 26 | import java.awt.event.MouseEvent; 27 | import java.io.IOException; 28 | import java.net.MalformedURLException; 29 | import java.net.URISyntaxException; 30 | import java.net.URL; 31 | 32 | /** JLabel extension for representing urls */ 33 | public final class URLLabel extends JLabel { 34 | 35 | private final URL link; 36 | 37 | public URLLabel(String text) { 38 | super(text); 39 | 40 | try { 41 | this.link = new URL(text); 42 | } catch (MalformedURLException e) { 43 | throw new LukeException(e.getMessage(), e); 44 | } 45 | 46 | setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 47 | 48 | addMouseListener(new MouseAdapter() { 49 | @Override 50 | public void mouseClicked(MouseEvent e) { 51 | openUrl(link); 52 | } 53 | }); 54 | } 55 | 56 | private void openUrl(URL link) { 57 | if (Desktop.isDesktopSupported()) { 58 | try { 59 | Desktop.getDesktop().browse(link.toURI()); 60 | } catch (IOException | URISyntaxException e) { 61 | throw new LukeException(e.getMessage(), e); 62 | } 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/inifile/IniFile.java: -------------------------------------------------------------------------------- 1 | package org.apache.lucene.luke.app.desktop.util.inifile; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.Path; 5 | 6 | /** Interface representing ini files */ 7 | public interface IniFile { 8 | 9 | void load(Path path) throws IOException; 10 | 11 | void store(Path path) throws IOException; 12 | 13 | void put(String section, String option, Object value); 14 | 15 | String getString(String section, String option); 16 | 17 | Boolean getBoolean(String section, String option); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/inifile/IniFileReader.java: -------------------------------------------------------------------------------- 1 | package org.apache.lucene.luke.app.desktop.util.inifile; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.Path; 5 | import java.util.Map; 6 | 7 | /** ini files interface */ 8 | public interface IniFileReader { 9 | 10 | Map readSections(Path path) throws IOException; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/inifile/IniFileWriter.java: -------------------------------------------------------------------------------- 1 | package org.apache.lucene.luke.app.desktop.util.inifile; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.Path; 5 | import java.util.Map; 6 | 7 | /** ini files writer */ 8 | public interface IniFileWriter { 9 | 10 | void writeSections(Path path, Map sections) throws IOException; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/inifile/OptionMap.java: -------------------------------------------------------------------------------- 1 | package org.apache.lucene.luke.app.desktop.util.inifile; 2 | 3 | import java.util.LinkedHashMap; 4 | 5 | /** Key-value store for options */ 6 | class OptionMap extends LinkedHashMap { 7 | 8 | String getAsString(String key) { 9 | return get(key); 10 | } 11 | 12 | Boolean getAsBoolean(String key) { 13 | return Boolean.parseBoolean(get(key)); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/inifile/SimpleIniFile.java: -------------------------------------------------------------------------------- 1 | package org.apache.lucene.luke.app.desktop.util.inifile; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.Path; 5 | import java.util.LinkedHashMap; 6 | import java.util.Map; 7 | import java.util.Objects; 8 | 9 | /** Simple implementation of {@link IniFile} */ 10 | public class SimpleIniFile implements IniFile { 11 | 12 | private final Map sections = new LinkedHashMap<>(); 13 | 14 | private IniFileWriter writer = new SimpleIniFileWriter(); 15 | 16 | private IniFileReader reader = new SimpleIniFileReader(); 17 | 18 | @Override 19 | public synchronized void load(Path path) throws IOException { 20 | sections.putAll(reader.readSections(path)); 21 | } 22 | 23 | @Override 24 | public synchronized void store(Path path) throws IOException { 25 | writer.writeSections(path, sections); 26 | } 27 | 28 | @Override 29 | public synchronized void put(String section, String option, Object value) { 30 | if (checkString(section) && checkString(option) && Objects.nonNull(value)) { 31 | sections.putIfAbsent(section, new OptionMap()); 32 | sections.get(section).put(option, (value instanceof String) ? (String) value : String.valueOf(value)); 33 | } 34 | } 35 | 36 | @Override 37 | public String getString(String section, String option) { 38 | if (checkString(section) && checkString(option)) { 39 | OptionMap options = sections.get(section); 40 | if (options != null) { 41 | return options.getAsString(option); 42 | } 43 | } 44 | return null; 45 | } 46 | 47 | @Override 48 | public Boolean getBoolean(String section, String option) { 49 | if (checkString(section) && checkString(option)) { 50 | OptionMap options = sections.get(section); 51 | if (options != null) { 52 | return options.getAsBoolean(option); 53 | } 54 | } 55 | return false; 56 | } 57 | 58 | private boolean checkString(String s) { 59 | return Objects.nonNull(s) && !s.equals(""); 60 | } 61 | 62 | Map getSections() { 63 | return sections; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/inifile/SimpleIniFileReader.java: -------------------------------------------------------------------------------- 1 | package org.apache.lucene.luke.app.desktop.util.inifile; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.nio.charset.StandardCharsets; 6 | import java.nio.file.Files; 7 | import java.nio.file.Path; 8 | import java.util.LinkedHashMap; 9 | import java.util.Map; 10 | 11 | /** Simple implementation of {@link IniFileReader} */ 12 | public class SimpleIniFileReader implements IniFileReader { 13 | 14 | private String currentSection = ""; 15 | 16 | @Override 17 | public Map readSections(Path path) throws IOException { 18 | final Map sections = new LinkedHashMap<>(); 19 | 20 | try (BufferedReader r = Files.newBufferedReader(path, StandardCharsets.UTF_8)) { 21 | r.lines().forEach(line -> { 22 | line = line.trim(); 23 | 24 | if (isSectionLine(line)) { 25 | // set section if this is a valid section string 26 | currentSection = line.substring(1, line.length()-1); 27 | sections.putIfAbsent(currentSection, new OptionMap()); 28 | } else if (!currentSection.equals("")) { 29 | // put option if this is a valid option string 30 | String[] ary = line.split("=", 2); 31 | if (ary.length == 2 && !ary[0].trim().equals("") && !ary[1].trim().equals("")) { 32 | sections.get(currentSection).put(ary[0].trim(), ary[1].trim()); 33 | } 34 | } 35 | 36 | }); 37 | } 38 | return sections; 39 | } 40 | 41 | private boolean isSectionLine(String line) { 42 | return line.startsWith("[") && line.endsWith("]") 43 | && line.substring(1, line.length()-1).matches("^[a-zA-Z0-9]+$"); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/inifile/SimpleIniFileWriter.java: -------------------------------------------------------------------------------- 1 | package org.apache.lucene.luke.app.desktop.util.inifile; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.IOException; 5 | import java.nio.charset.StandardCharsets; 6 | import java.nio.file.Files; 7 | import java.nio.file.Path; 8 | import java.util.Map; 9 | 10 | /** Simple implementation of {@link IniFileWriter} */ 11 | public class SimpleIniFileWriter implements IniFileWriter { 12 | 13 | @Override 14 | public void writeSections(Path path, Map sections) throws IOException { 15 | try (BufferedWriter w = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) { 16 | for (Map.Entry section : sections.entrySet()) { 17 | w.write("[" + section.getKey() + "]"); 18 | w.newLine(); 19 | 20 | for (Map.Entry option : section.getValue().entrySet()) { 21 | w.write(option.getKey() + " = " + option.getValue()); 22 | w.newLine(); 23 | } 24 | 25 | w.newLine(); 26 | } 27 | w.flush(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/inifile/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Ini file parser / writer */ 19 | package org.apache.lucene.luke.app.desktop.util.inifile; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/lang/Callable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.app.desktop.util.lang; 19 | 20 | /** Functional interface which provides sole method call() */ 21 | @FunctionalInterface 22 | public interface Callable { 23 | void call(); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/lang/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Syntax sugars / helpers */ 19 | package org.apache.lucene.luke.app.desktop.util.lang; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/desktop/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Utilities for the UI components */ 19 | package org.apache.lucene.luke.app.desktop.util; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/app/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Views (UIs) for Luke */ 19 | package org.apache.lucene.luke.app; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/LukeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models; 19 | 20 | /** Wrapper exception class to convert checked exceptions to runtime exceptions. */ 21 | public class LukeException extends RuntimeException { 22 | 23 | public LukeException(String message, Throwable cause) { 24 | super(message, cause); 25 | } 26 | 27 | public LukeException(Throwable cause) { 28 | super(cause); 29 | } 30 | 31 | public LukeException(String message) { 32 | super(message); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/LukeModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models; 19 | 20 | import org.apache.lucene.index.DirectoryReader; 21 | import org.apache.lucene.index.IndexCommit; 22 | import org.apache.lucene.index.IndexReader; 23 | import org.apache.lucene.luke.models.util.IndexUtils; 24 | import org.apache.lucene.store.Directory; 25 | import org.apache.lucene.util.Bits; 26 | 27 | import java.io.IOException; 28 | import java.util.Collection; 29 | import java.util.Objects; 30 | 31 | /** 32 | * Abstract model class. It holds index reader object and provides basic features for all concrete sub classes. 33 | */ 34 | public abstract class LukeModel { 35 | 36 | protected Directory dir; 37 | 38 | protected IndexReader reader; 39 | 40 | protected Bits liveDocs; 41 | 42 | protected IndexCommit commit; 43 | 44 | protected LukeModel(IndexReader reader) { 45 | this.reader = Objects.requireNonNull(reader); 46 | 47 | if (reader instanceof DirectoryReader) { 48 | DirectoryReader dr = (DirectoryReader) reader; 49 | this.dir = dr.directory(); 50 | try { 51 | this.commit = dr.getIndexCommit(); 52 | } catch (IOException e) { 53 | throw new LukeException(e.getMessage(), e); 54 | } 55 | } else { 56 | this.dir = null; 57 | this.commit = null; 58 | } 59 | 60 | this.liveDocs = IndexUtils.getLiveDocs(reader); 61 | } 62 | 63 | protected LukeModel (Directory dir) { 64 | this.dir = Objects.requireNonNull(dir); 65 | } 66 | 67 | public Collection getFieldNames() { 68 | return IndexUtils.getFieldNames(reader); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/analysis/AnalysisFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.analysis; 19 | 20 | /** Factory of {@link Analysis} */ 21 | public class AnalysisFactory { 22 | 23 | public Analysis newInstance() { 24 | return new AnalysisImpl(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/analysis/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Models and APIs for the Analysis tab */ 19 | package org.apache.lucene.luke.models.analysis; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/commits/Commit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.commits; 19 | 20 | import org.apache.lucene.index.IndexCommit; 21 | import org.apache.lucene.luke.models.util.IndexUtils; 22 | 23 | import java.io.IOException; 24 | 25 | /** 26 | * Holder for a commit. 27 | */ 28 | public final class Commit { 29 | 30 | private long generation; 31 | 32 | private boolean isDeleted; 33 | 34 | private int segCount; 35 | 36 | private String userData; 37 | 38 | static Commit of(IndexCommit ic) { 39 | Commit commit = new Commit(); 40 | commit.generation = ic.getGeneration(); 41 | commit.isDeleted = ic.isDeleted(); 42 | commit.segCount = ic.getSegmentCount(); 43 | try { 44 | commit.userData = IndexUtils.getCommitUserData(ic); 45 | } catch (IOException e) { 46 | } 47 | return commit; 48 | } 49 | 50 | public long getGeneration() { 51 | return generation; 52 | } 53 | 54 | public boolean isDeleted() { 55 | return isDeleted; 56 | } 57 | 58 | public int getSegCount() { 59 | return segCount; 60 | } 61 | 62 | public String getUserData() { 63 | return userData; 64 | } 65 | 66 | private Commit() { 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/commits/Commits.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.commits; 19 | 20 | import org.apache.lucene.codecs.Codec; 21 | import org.apache.lucene.luke.models.LukeException; 22 | 23 | import java.util.List; 24 | import java.util.Map; 25 | import java.util.Optional; 26 | 27 | /** 28 | * A dedicated interface for Luke's Commits tab. 29 | */ 30 | public interface Commits { 31 | 32 | /** 33 | * Returns commits that exists in this Directory. 34 | * @throws LukeException - if an internal error occurs when accessing index 35 | */ 36 | List listCommits(); 37 | 38 | /** 39 | * Returns a commit of the specified generation. 40 | * @param commitGen - generation 41 | * @throws LukeException - if an internal error occurs when accessing index 42 | */ 43 | Optional getCommit(long commitGen); 44 | 45 | /** 46 | * Returns index files for the specified generation. 47 | * @param commitGen - generation 48 | * @throws LukeException - if an internal error occurs when accessing index 49 | */ 50 | List getFiles(long commitGen); 51 | 52 | /** 53 | * Returns segments for the specified generation. 54 | * @param commitGen - generation 55 | * @throws LukeException - if an internal error occurs when accessing index 56 | */ 57 | List getSegments(long commitGen); 58 | 59 | /** 60 | * Returns internal codec attributes map for the specified segment. 61 | * @param commitGen - generation 62 | * @param name - segment name 63 | * @throws LukeException - if an internal error occurs when accessing index 64 | */ 65 | Map getSegmentAttributes(long commitGen, String name); 66 | 67 | /** 68 | * Returns diagnotics for the specified segment. 69 | * @param commitGen - generation 70 | * @param name - segment name 71 | * @throws LukeException - if an internal error occurs when accessing index 72 | */ 73 | Map getSegmentDiagnostics(long commitGen, String name); 74 | 75 | /** 76 | * Returns codec for the specified segment. 77 | * @param commitGen - generation 78 | * @param name - segment name 79 | * @throws LukeException - if an internal error occurs when accessing index 80 | */ 81 | Optional getSegmentCodec(long commitGen, String name); 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/commits/CommitsFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.commits; 19 | 20 | import org.apache.lucene.index.DirectoryReader; 21 | import org.apache.lucene.store.Directory; 22 | 23 | /** Factory of {@link Commits} */ 24 | public class CommitsFactory { 25 | 26 | public Commits newInstance(Directory dir, String indexPath) { 27 | return new CommitsImpl(dir, indexPath); 28 | } 29 | 30 | public Commits newInstance(DirectoryReader reader, String indexPath) { 31 | return new CommitsImpl(reader, indexPath); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/commits/File.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.commits; 19 | 20 | /** 21 | * Holder for a index file. 22 | */ 23 | public final class File { 24 | private String fileName; 25 | private String displaySize; 26 | 27 | static File of(String indexPath, String name) { 28 | File file = new File(); 29 | file.fileName = name; 30 | java.io.File fileObject = new java.io.File(indexPath, name); 31 | file.displaySize = CommitsImpl.toDisplaySize(fileObject.length()); 32 | return file; 33 | } 34 | 35 | public String getFileName() { 36 | return fileName; 37 | } 38 | 39 | public String getDisplaySize() { 40 | return displaySize; 41 | } 42 | 43 | private File() { 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/commits/Segment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.commits; 19 | 20 | import org.apache.lucene.index.SegmentCommitInfo; 21 | 22 | import java.io.IOException; 23 | 24 | /** 25 | * Holder for a segment. 26 | */ 27 | public final class Segment { 28 | 29 | private String name; 30 | 31 | private int maxDoc; 32 | 33 | private long delGen; 34 | 35 | private int delCount; 36 | 37 | private String luceneVer; 38 | 39 | private String codecName; 40 | 41 | private String displaySize; 42 | 43 | private boolean useCompoundFile; 44 | 45 | static Segment of(SegmentCommitInfo segInfo) { 46 | Segment segment = new Segment(); 47 | segment.name = segInfo.info.name; 48 | segment.maxDoc = segInfo.info.maxDoc(); 49 | segment.delGen = segInfo.getDelGen(); 50 | segment.delCount = segInfo.getDelCount(); 51 | segment.luceneVer = segInfo.info.getVersion().toString(); 52 | segment.codecName = segInfo.info.getCodec().getName(); 53 | try { 54 | segment.displaySize = CommitsImpl.toDisplaySize(segInfo.sizeInBytes()); 55 | } catch (IOException e) { 56 | } 57 | segment.useCompoundFile = segInfo.info.getUseCompoundFile(); 58 | return segment; 59 | } 60 | 61 | public String getName() { 62 | return name; 63 | } 64 | 65 | public int getMaxDoc() { 66 | return maxDoc; 67 | } 68 | 69 | public long getDelGen() { 70 | return delGen; 71 | } 72 | 73 | public int getDelCount() { 74 | return delCount; 75 | } 76 | 77 | public String getLuceneVer() { 78 | return luceneVer; 79 | } 80 | 81 | public String getCodecName() { 82 | return codecName; 83 | } 84 | 85 | public String getDisplaySize() { 86 | return displaySize; 87 | } 88 | 89 | public boolean isUseCompoundFile() { 90 | return useCompoundFile; 91 | } 92 | 93 | private Segment() { 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/commits/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Models and APIs for the Commits tab */ 19 | package org.apache.lucene.luke.models.commits; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/documents/DocValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.documents; 19 | 20 | import org.apache.lucene.index.DocValuesType; 21 | import org.apache.lucene.util.BytesRef; 22 | 23 | import java.util.List; 24 | import java.util.stream.Collectors; 25 | 26 | /** 27 | * Holder for doc values. 28 | */ 29 | public final class DocValues { 30 | 31 | private final DocValuesType dvType; 32 | 33 | private final List values; 34 | 35 | private final List numericValues; 36 | 37 | /** 38 | * Returns a new doc values entry representing the specified doc values type and values. 39 | * @param dvType - doc values type 40 | * @param values - (string) values 41 | * @param numericValues numeric values 42 | * @return doc values 43 | */ 44 | static DocValues of(DocValuesType dvType, List values, List numericValues) { 45 | return new DocValues(dvType, values, numericValues); 46 | } 47 | 48 | private DocValues(DocValuesType dvType, List values, List numericValues) { 49 | this.dvType = dvType; 50 | this.values = values; 51 | this.numericValues = numericValues; 52 | } 53 | 54 | /** 55 | * Returns the type of this doc values. 56 | */ 57 | public DocValuesType getDvType() { 58 | return dvType; 59 | } 60 | 61 | /** 62 | * Returns the list of (string) values. 63 | */ 64 | public List getValues() { 65 | return values; 66 | } 67 | 68 | /** 69 | * Returns the list of numeric values. 70 | */ 71 | public List getNumericValues() { 72 | return numericValues; 73 | } 74 | 75 | @Override 76 | public String toString() { 77 | String numValuesStr = numericValues.stream().map(String::valueOf).collect(Collectors.joining(",")); 78 | return "DocValues{" + 79 | "dvType=" + dvType + 80 | ", values=" + values + 81 | ", numericValues=[" + numValuesStr + "]" + 82 | '}'; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/documents/DocumentsFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.documents; 19 | 20 | import org.apache.lucene.index.IndexReader; 21 | 22 | /** Factory of {@link Documents} */ 23 | public class DocumentsFactory { 24 | 25 | public Documents newInstance(IndexReader reader) { 26 | return new DocumentsImpl(reader); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/documents/TermPosting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.documents; 19 | 20 | import org.apache.lucene.index.PostingsEnum; 21 | import org.apache.lucene.util.BytesRef; 22 | 23 | import java.io.IOException; 24 | 25 | /** 26 | * Holder for a term's position information, and optionally, offsets and payloads. 27 | */ 28 | public final class TermPosting { 29 | 30 | // position 31 | private int position = -1; 32 | 33 | // start and end offset (optional) 34 | private int startOffset = -1; 35 | private int endOffset = -1; 36 | 37 | // payload (optional) 38 | private BytesRef payload; 39 | 40 | static TermPosting of(int position, PostingsEnum penum) throws IOException { 41 | TermPosting posting = new TermPosting(); 42 | 43 | // set position 44 | posting.position = position; 45 | 46 | // set offset (if available) 47 | int sOffset = penum.startOffset(); 48 | int eOffset = penum.endOffset(); 49 | if (sOffset >= 0 && eOffset >= 0) { 50 | posting.startOffset = sOffset; 51 | posting.endOffset = eOffset; 52 | } 53 | 54 | // set payload (if available) 55 | if (penum.getPayload() != null) { 56 | posting.payload = BytesRef.deepCopyOf(penum.getPayload()); 57 | } 58 | 59 | return posting; 60 | } 61 | 62 | public int getPosition() { 63 | return position; 64 | } 65 | 66 | public int getStartOffset() { 67 | return startOffset; 68 | } 69 | 70 | public int getEndOffset() { 71 | return endOffset; 72 | } 73 | 74 | public BytesRef getPayload() { 75 | return payload; 76 | } 77 | 78 | @Override 79 | public String toString() { 80 | return "TermPosting{" + 81 | "position=" + position + 82 | ", startOffset=" + startOffset + 83 | ", endOffset=" + endOffset + 84 | ", payload=" + payload + 85 | '}'; 86 | } 87 | 88 | private TermPosting() { 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/documents/TermVectorsAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.documents; 19 | 20 | import org.apache.lucene.index.IndexReader; 21 | import org.apache.lucene.index.Terms; 22 | import org.apache.lucene.index.TermsEnum; 23 | import org.slf4j.Logger; 24 | import org.slf4j.LoggerFactory; 25 | 26 | import java.io.IOException; 27 | import java.util.ArrayList; 28 | import java.util.Collections; 29 | import java.util.List; 30 | import java.util.Objects; 31 | 32 | /** 33 | * An utility class to access to the term vectors. 34 | */ 35 | final class TermVectorsAdapter { 36 | 37 | private static Logger log = LoggerFactory.getLogger(TermVectorsAdapter.class); 38 | 39 | private IndexReader reader; 40 | 41 | TermVectorsAdapter(IndexReader reader) { 42 | this.reader = Objects.requireNonNull(reader); 43 | } 44 | 45 | /** 46 | * Returns the term vectors for the specified field in the specified document. 47 | * If no term vector is available for the field, empty list is returned. 48 | * 49 | * @param docid - document id 50 | * @param field - field name 51 | * @return list of term vector elements 52 | * @throws IOException 53 | */ 54 | List getTermVector(int docid, String field) throws IOException { 55 | Terms termVector = reader.getTermVector(docid, field); 56 | if (termVector == null) { 57 | // no term vector available 58 | log.warn("No term vector indexed for doc: #{} and field: {}", docid, field); 59 | return Collections.emptyList(); 60 | } 61 | 62 | List res = new ArrayList<>(); 63 | TermsEnum te = termVector.iterator(); 64 | while (te.next() != null) { 65 | res.add(TermVectorEntry.of(te)); 66 | } 67 | return res; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/documents/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Models and APIs for the Documents tab */ 19 | package org.apache.lucene.luke.models.documents; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/overview/OverviewFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.overview; 19 | 20 | import org.apache.lucene.index.IndexReader; 21 | 22 | /** Factory of {@link Overview} */ 23 | public class OverviewFactory { 24 | 25 | public Overview newInstance(IndexReader reader, String indexPath) { 26 | return new OverviewImpl(reader, indexPath); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/overview/TermCounts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.overview; 19 | 20 | import org.apache.lucene.index.IndexReader; 21 | import org.apache.lucene.luke.models.util.IndexUtils; 22 | 23 | import java.io.IOException; 24 | import java.util.Comparator; 25 | import java.util.LinkedHashMap; 26 | import java.util.Map; 27 | import java.util.Objects; 28 | import java.util.stream.Collectors; 29 | 30 | /** 31 | * An utility class that collects term counts terms for all fields in a index. 32 | */ 33 | final class TermCounts { 34 | 35 | private final Map termCountMap; 36 | 37 | TermCounts(IndexReader reader) throws IOException { 38 | Objects.requireNonNull(reader); 39 | termCountMap = IndexUtils.countTerms(reader, IndexUtils.getFieldNames(reader)); 40 | } 41 | 42 | /** 43 | * Returns the total number of terms in this index. 44 | */ 45 | long numTerms() { 46 | return termCountMap.values().stream().mapToLong(Long::longValue).sum(); 47 | } 48 | 49 | /** 50 | * Returns all fields with the number of terms for each field sorted by {@link TermCountsOrder} 51 | * @param order - sort order 52 | */ 53 | Map sortedTermCounts(TermCountsOrder order){ 54 | Objects.requireNonNull(order); 55 | 56 | Comparator> comparator; 57 | switch (order) { 58 | case NAME_ASC: 59 | comparator = Map.Entry.comparingByKey(); 60 | break; 61 | case NAME_DESC: 62 | comparator = Map.Entry.comparingByKey().reversed(); 63 | break; 64 | case COUNT_ASC: 65 | comparator = Map.Entry.comparingByValue(); 66 | break; 67 | case COUNT_DESC: 68 | comparator = Map.Entry.comparingByValue().reversed(); 69 | break; 70 | default: 71 | comparator = Map.Entry.comparingByKey(); 72 | } 73 | return sortedTermCounts(comparator); 74 | } 75 | 76 | private Map sortedTermCounts(Comparator> comparator) { 77 | return termCountMap.entrySet().stream() 78 | .sorted(comparator) 79 | .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (v1, v2) -> v1, LinkedHashMap::new)); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/overview/TermCountsOrder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.overview; 19 | 20 | /** 21 | * Sort orders for fields with their term counts 22 | */ 23 | public enum TermCountsOrder { 24 | /** 25 | * Ascending order by the field name 26 | */ 27 | NAME_ASC, 28 | 29 | /** 30 | * Descending order by the field name 31 | */ 32 | NAME_DESC, 33 | 34 | /** 35 | * Ascending order by the count of terms 36 | */ 37 | COUNT_ASC, 38 | 39 | /** 40 | * Descending order by the count of terms 41 | */ 42 | COUNT_DESC 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/overview/TermStats.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.overview; 19 | 20 | import org.apache.lucene.luke.util.BytesRefUtils; 21 | 22 | /** 23 | * Holder for statistics for a term in a specific field. 24 | */ 25 | public final class TermStats { 26 | 27 | private final String decodedTermText; 28 | 29 | private final String field; 30 | 31 | private final int docFreq; 32 | 33 | /** 34 | * Returns a TermStats instance representing the specified {@link org.apache.lucene.misc.TermStats} value. 35 | */ 36 | static TermStats of(org.apache.lucene.misc.TermStats stats) { 37 | String termText = BytesRefUtils.decode(stats.termtext); 38 | return new TermStats(termText, stats.field, stats.docFreq); 39 | } 40 | 41 | private TermStats(String decodedTermText, String field, int docFreq) { 42 | this.decodedTermText = decodedTermText; 43 | this.field = field; 44 | this.docFreq = docFreq; 45 | } 46 | 47 | /** 48 | * Returns the string representation for this term. 49 | */ 50 | public String getDecodedTermText() { 51 | return decodedTermText; 52 | } 53 | 54 | /** 55 | * Returns the field name. 56 | */ 57 | public String getField() { 58 | return field; 59 | } 60 | 61 | /** 62 | * Returns the document frequency of this term. 63 | */ 64 | public int getDocFreq() { 65 | return docFreq; 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return "TermStats{" + 71 | "decodedTermText='" + decodedTermText + '\'' + 72 | ", field='" + field + '\'' + 73 | ", docFreq=" + docFreq + 74 | '}'; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/overview/TopTerms.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.overview; 19 | 20 | import org.apache.lucene.index.IndexReader; 21 | import org.apache.lucene.misc.HighFreqTerms; 22 | 23 | import java.util.Arrays; 24 | import java.util.Collections; 25 | import java.util.List; 26 | import java.util.Map; 27 | import java.util.Objects; 28 | import java.util.WeakHashMap; 29 | import java.util.stream.Collectors; 30 | 31 | /** 32 | * An utility class that collects terms and their statistics in a specific field. 33 | */ 34 | final class TopTerms { 35 | 36 | private final IndexReader reader; 37 | 38 | private final Map> topTermsCache; 39 | 40 | TopTerms(IndexReader reader) { 41 | this.reader = Objects.requireNonNull(reader); 42 | this.topTermsCache = new WeakHashMap<>(); 43 | } 44 | 45 | /** 46 | * Returns the top indexed terms with their statistics for the specified field. 47 | * 48 | * @param field - the field name 49 | * @param numTerms - the max number of terms to be returned 50 | * @throws Exception - if an error occurs when collecting term statistics 51 | */ 52 | List getTopTerms(String field, int numTerms) throws Exception { 53 | 54 | if (!topTermsCache.containsKey(field) || topTermsCache.get(field).size() < numTerms) { 55 | org.apache.lucene.misc.TermStats[] stats = 56 | HighFreqTerms.getHighFreqTerms(reader, numTerms, field, new HighFreqTerms.DocFreqComparator()); 57 | 58 | List topTerms = Arrays.stream(stats) 59 | .map(TermStats::of) 60 | .collect(Collectors.toList()); 61 | 62 | // cache computed statistics for later uses 63 | topTermsCache.put(field, topTerms); 64 | } 65 | 66 | return Collections.unmodifiableList(topTermsCache.get(field)); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/overview/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Models and APIs for the Overview tab */ 19 | package org.apache.lucene.luke.models.overview; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Models and internal APIs for Luke */ 19 | package org.apache.lucene.luke.models; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/search/MLTConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.search; 19 | 20 | import org.apache.lucene.queries.mlt.MoreLikeThis; 21 | 22 | import java.util.ArrayList; 23 | import java.util.Collection; 24 | import java.util.Collections; 25 | import java.util.List; 26 | 27 | /** 28 | * Configurations for MoreLikeThis query. 29 | */ 30 | public final class MLTConfig { 31 | 32 | private final List fields; 33 | 34 | private final int maxDocFreq; 35 | 36 | private final int minDocFreq; 37 | 38 | private final int minTermFreq; 39 | 40 | public static class Builder { 41 | 42 | private final List fields = new ArrayList<>(); 43 | private int maxDocFreq = MoreLikeThis.DEFAULT_MAX_DOC_FREQ; 44 | private int minDocFreq = MoreLikeThis.DEFAULT_MIN_DOC_FREQ; 45 | private int minTermFreq = MoreLikeThis.DEFAULT_MIN_TERM_FREQ; 46 | 47 | public Builder fields(Collection val) { 48 | fields.addAll(val); 49 | return this; 50 | } 51 | 52 | public Builder maxDocFreq(int val) { 53 | maxDocFreq = val; 54 | return this; 55 | } 56 | 57 | public Builder minDocFreq(int val) { 58 | minDocFreq = val; 59 | return this; 60 | } 61 | 62 | public Builder minTermFreq(int val) { 63 | minTermFreq = val; 64 | return this; 65 | } 66 | 67 | public MLTConfig build() { 68 | return new MLTConfig(this); 69 | } 70 | } 71 | 72 | private MLTConfig(Builder builder) { 73 | this.fields = Collections.unmodifiableList(builder.fields); 74 | this.maxDocFreq = builder.maxDocFreq; 75 | this.minDocFreq = builder.minDocFreq; 76 | this.minTermFreq = builder.minTermFreq; 77 | } 78 | 79 | public String[] getFieldNames() { 80 | return fields.toArray(new String[fields.size()]); 81 | } 82 | 83 | public int getMaxDocFreq() { 84 | return maxDocFreq; 85 | } 86 | 87 | public int getMinDocFreq() { 88 | return minDocFreq; 89 | } 90 | 91 | public int getMinTermFreq() { 92 | return minTermFreq; 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/search/SearchFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.search; 19 | 20 | import org.apache.lucene.index.IndexReader; 21 | 22 | /** Factory of {@link Search} */ 23 | public class SearchFactory { 24 | 25 | public Search newInstance(IndexReader reader) { 26 | return new SearchImpl(reader); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/search/SimilarityConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.search; 19 | 20 | /** 21 | * Configurations for Similarity. 22 | */ 23 | public final class SimilarityConfig { 24 | 25 | private final boolean useClassicSimilarity; 26 | 27 | /* BM25Similarity parameters */ 28 | 29 | private final float k1; 30 | 31 | private final float b; 32 | 33 | /* Common parameters */ 34 | 35 | private final boolean discountOverlaps; 36 | 37 | public static class Builder { 38 | private boolean useClassicSimilarity = false; 39 | private float k1 = 1.2f; 40 | private float b = 0.75f; 41 | private boolean discountOverlaps = true; 42 | 43 | public Builder useClassicSimilarity(boolean val) { 44 | useClassicSimilarity = val; 45 | return this; 46 | } 47 | 48 | public Builder k1(float val) { 49 | k1 = val; 50 | return this; 51 | } 52 | 53 | public Builder b(float val) { 54 | b = val; 55 | return this; 56 | } 57 | 58 | public Builder discountOverlaps (boolean val) { 59 | discountOverlaps = val; 60 | return this; 61 | } 62 | 63 | public SimilarityConfig build() { 64 | return new SimilarityConfig(this); 65 | } 66 | } 67 | 68 | private SimilarityConfig(Builder builder) { 69 | this.useClassicSimilarity = builder.useClassicSimilarity; 70 | this.k1 = builder.k1; 71 | this.b = builder.b; 72 | this.discountOverlaps = builder.discountOverlaps; 73 | } 74 | 75 | public boolean isUseClassicSimilarity() { 76 | return useClassicSimilarity; 77 | } 78 | 79 | public float getK1() { 80 | return k1; 81 | } 82 | 83 | public float getB() { 84 | return b; 85 | } 86 | 87 | public boolean isDiscountOverlaps() { 88 | return discountOverlaps; 89 | } 90 | 91 | public String toString() { 92 | return "SimilarityConfig: [" + 93 | " use classic similarity=" + useClassicSimilarity + ";" + 94 | " discount overlaps=" + discountOverlaps + ";" + 95 | " k1=" + k1 + ";" + 96 | " b=" + b + ";" + 97 | "]"; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/search/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Models and APIs for the Search tab */ 19 | package org.apache.lucene.luke.models.search; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/tools/IndexTools.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.tools; 19 | 20 | import org.apache.lucene.analysis.Analyzer; 21 | import org.apache.lucene.document.Document; 22 | import org.apache.lucene.document.Field; 23 | import org.apache.lucene.index.CheckIndex; 24 | import org.apache.lucene.luke.models.LukeException; 25 | import org.apache.lucene.search.Query; 26 | 27 | import java.io.PrintStream; 28 | import java.util.Collection; 29 | 30 | /** 31 | * A dedicated interface for Luke's various index manipulations. 32 | */ 33 | public interface IndexTools { 34 | 35 | /** 36 | * Execute force merges. 37 | * 38 | *

39 | * Merges are executed until there are maxNumSegments segments.
40 | * When expunge is true, maxNumSegments parameter is ignored. 41 | *

42 | * 43 | * @param expunge - if true, only segments having deleted documents are merged 44 | * @param maxNumSegments - max number of segments 45 | * @param ps - information stream 46 | * @throws LukeException - if an internal error occurs when accessing index 47 | */ 48 | void optimize(boolean expunge, int maxNumSegments, PrintStream ps); 49 | 50 | /** 51 | * Check the current index status. 52 | * 53 | * @param ps information stream 54 | * @return index status 55 | * @throws LukeException - if an internal error occurs when accessing index 56 | */ 57 | CheckIndex.Status checkIndex(PrintStream ps); 58 | 59 | /** 60 | * Try to repair the corrupted index using previously returned index status. 61 | * 62 | *

This method must be called with the return value from {@link IndexTools#checkIndex(PrintStream)}.

63 | * 64 | * @param st - index status 65 | * @param ps - information stream 66 | * @throws LukeException - if an internal error occurs when accessing index 67 | */ 68 | void repairIndex(CheckIndex.Status st, PrintStream ps); 69 | 70 | /** 71 | * Add new document to this index. 72 | * 73 | * @param doc - document to be added 74 | * @param analyzer - analyzer for parsing to document 75 | * @throws LukeException - if an internal error occurs when accessing index 76 | */ 77 | void addDocument(Document doc, Analyzer analyzer); 78 | 79 | /** 80 | * Delete documents from this index by the specified query. 81 | * 82 | * @param query - query for deleting 83 | * @throws LukeException - if an internal error occurs when accessing index 84 | */ 85 | void deleteDocuments(Query query); 86 | 87 | /** 88 | * Create a new index. 89 | * 90 | * @throws LukeException - if an internal error occurs when accessing index 91 | */ 92 | void createNewIndex(); 93 | 94 | /** 95 | * Create a new index with sample documents. 96 | * @param dataDir - the directory path which contains sample documents (20 Newsgroups). 97 | */ 98 | void createNewIndex(String dataDir); 99 | 100 | /** 101 | * Returns preset {@link Field} classes. 102 | */ 103 | Collection> getPresetFields(); 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/tools/IndexToolsFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.tools; 19 | 20 | import org.apache.lucene.index.IndexReader; 21 | import org.apache.lucene.store.Directory; 22 | 23 | /** Factory of {@link IndexTools} */ 24 | public class IndexToolsFactory { 25 | 26 | public IndexTools newInstance(Directory dir) { 27 | return new IndexToolsImpl(dir, false, false); 28 | } 29 | 30 | public IndexTools newInstance(IndexReader reader, boolean useCompound, boolean keepAllCommits) { 31 | return new IndexToolsImpl(reader, useCompound, keepAllCommits); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/tools/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Models and APIs for various index manipulation */ 19 | package org.apache.lucene.luke.models.tools; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Utilities for models and APIs */ 19 | package org.apache.lucene.luke.models.util; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/util/reflection/ClassScanner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.util.reflection; 19 | 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | import java.io.IOException; 24 | import java.lang.invoke.MethodHandles; 25 | import java.net.URL; 26 | import java.nio.file.Path; 27 | import java.nio.file.Paths; 28 | import java.util.ArrayList; 29 | import java.util.Collections; 30 | import java.util.Enumeration; 31 | import java.util.HashSet; 32 | import java.util.List; 33 | import java.util.Set; 34 | import java.util.concurrent.ExecutorService; 35 | import java.util.concurrent.Executors; 36 | import java.util.concurrent.TimeUnit; 37 | 38 | /** 39 | * Utility class for scanning class files in jars. 40 | */ 41 | public class ClassScanner { 42 | 43 | private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); 44 | 45 | private final String packageName; 46 | private final ClassLoader[] classLoaders; 47 | 48 | public ClassScanner(String packageName, ClassLoader... classLoaders) { 49 | this.packageName = packageName; 50 | this.classLoaders = classLoaders; 51 | } 52 | 53 | public Set> scanSubTypes(Class superType) { 54 | final int numThreads = Runtime.getRuntime().availableProcessors(); 55 | 56 | List> collectors = new ArrayList<>(); 57 | for (int i = 0; i < numThreads; i++) { 58 | collectors.add(new SubtypeCollector(superType, packageName, classLoaders)); 59 | } 60 | 61 | try { 62 | List urls = getJarUrls(); 63 | for (int i = 0; i < urls.size(); i++) { 64 | collectors.get(i % numThreads).addUrl(urls.get(i)); 65 | } 66 | 67 | ExecutorService executorService = Executors.newFixedThreadPool(numThreads); 68 | for (SubtypeCollector collector : collectors) { 69 | executorService.submit(collector); 70 | } 71 | 72 | try { 73 | executorService.shutdown(); 74 | executorService.awaitTermination(10, TimeUnit.SECONDS); 75 | } catch (InterruptedException e) { 76 | } finally { 77 | executorService.shutdownNow(); 78 | } 79 | 80 | Set> types = new HashSet<>(); 81 | for (SubtypeCollector collector : collectors) { 82 | types.addAll(collector.getTypes()); 83 | } 84 | return types; 85 | } catch (IOException e) { 86 | log.error("Cannot load jar file entries", e); 87 | } 88 | return Collections.emptySet(); 89 | } 90 | 91 | private List getJarUrls() throws IOException { 92 | List urls = new ArrayList<>(); 93 | String resourceName = resourceName(packageName); 94 | for (ClassLoader loader : classLoaders) { 95 | for (Enumeration e = loader.getResources(resourceName); e.hasMoreElements(); ) { 96 | URL url = e.nextElement(); 97 | // extract jar file path from the resource name 98 | int index = url.getPath().lastIndexOf(".jar"); 99 | if (index > 0) { 100 | String path = url.getPath().substring(0, index + 4); 101 | urls.add(new URL(path)); 102 | } 103 | } 104 | } 105 | return urls; 106 | } 107 | 108 | private static String resourceName(String packageName) { 109 | if (packageName == null || packageName.equals("")) { 110 | return packageName; 111 | } 112 | return packageName.replace('.', '/'); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/util/reflection/SubtypeCollector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.util.reflection; 19 | 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | 23 | import java.io.IOException; 24 | import java.lang.invoke.MethodHandles; 25 | import java.net.URL; 26 | import java.util.Collections; 27 | import java.util.HashMap; 28 | import java.util.HashSet; 29 | import java.util.Map; 30 | import java.util.Set; 31 | import java.util.jar.JarInputStream; 32 | import java.util.zip.ZipEntry; 33 | 34 | final class SubtypeCollector implements Runnable { 35 | 36 | private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); 37 | 38 | private static final Map> cache = new HashMap<>(); 39 | 40 | private final Set urls = new HashSet<>(); 41 | 42 | private final Class superType; 43 | 44 | private final String packageName; 45 | 46 | private final ClassLoader[] classLoaders; 47 | 48 | private final Set> types = new HashSet<>(); 49 | 50 | SubtypeCollector(Class superType, String packageName, ClassLoader... classLoaders) { 51 | this.superType = superType; 52 | this.packageName = packageName; 53 | this.classLoaders = classLoaders; 54 | } 55 | 56 | void addUrl(URL url) { 57 | urls.add(url); 58 | } 59 | 60 | Set> getTypes() { 61 | return Collections.unmodifiableSet(types); 62 | } 63 | 64 | @Override 65 | public void run() { 66 | for (URL url : urls) { 67 | try (JarInputStream jis = new JarInputStream(url.openStream())) { 68 | // iterate all zip entry in the jar 69 | ZipEntry entry; 70 | while ((entry = jis.getNextEntry()) != null) { 71 | String name = entry.getName(); 72 | if (name.endsWith(".class") && name.indexOf('$') < 0 73 | && !name.contains("package-info") && !name.startsWith("META-INF")) { 74 | String fqcn = convertToFQCN(name); 75 | if (!fqcn.startsWith(packageName)) { 76 | continue; 77 | } 78 | for (ClassLoader cl : classLoaders) { 79 | try { 80 | Class clazz = Class.forName(fqcn, false, cl); 81 | if (isSubclassOf(clazz, superType)) { 82 | types.add(clazz.asSubclass(superType)); 83 | } 84 | break; 85 | } catch (Throwable e) { 86 | } 87 | } 88 | } 89 | } 90 | } catch (IOException e) { 91 | log.error("Cannot load jar " + url.toString(), e); 92 | } 93 | } 94 | } 95 | 96 | private static String convertToFQCN(String name) { 97 | if (name == null || name.equals("")) { 98 | return name; 99 | } 100 | int index = name.lastIndexOf(".class"); 101 | return name.replace('/', '.').substring(0, index); 102 | } 103 | 104 | private static boolean isSubclassOf(Class clazz, Class superType) { 105 | String superTypeName = superType.getName(); 106 | cache.putIfAbsent(superTypeName, new HashSet<>()); 107 | Class c = clazz.getSuperclass(); 108 | while (c != null) { 109 | if (cache.get(superTypeName).contains(clazz.getName())) { 110 | return true; 111 | } 112 | if (c.getName().equals(superTypeName)) { 113 | cache.get(superTypeName).add(clazz.getName()); 114 | return true; 115 | } 116 | c = c.getSuperclass(); 117 | } 118 | return false; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/util/reflection/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Utilities for reflections */ 19 | package org.apache.lucene.luke.models.util.reflection; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/util/twentynewsgroups/Message.java: -------------------------------------------------------------------------------- 1 | package org.apache.lucene.luke.models.util.twentynewsgroups; 2 | 3 | import org.apache.lucene.analysis.Analyzer; 4 | import org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper; 5 | import org.apache.lucene.analysis.standard.StandardAnalyzer; 6 | import org.apache.lucene.analysis.standard.UAX29URLEmailAnalyzer; 7 | import org.apache.lucene.document.Document; 8 | import org.apache.lucene.document.Field; 9 | import org.apache.lucene.document.IntPoint; 10 | import org.apache.lucene.document.SortedNumericDocValuesField; 11 | import org.apache.lucene.document.StoredField; 12 | import org.apache.lucene.document.StringField; 13 | import org.apache.lucene.document.TextField; 14 | 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | import java.util.Objects; 18 | 19 | /** Data holder class for a newsgroups message */ 20 | public class Message { 21 | 22 | private String from; 23 | private String[] newsgroups; 24 | private String subject; 25 | private String messageId; 26 | private String date; 27 | private String organization; 28 | private String body; 29 | private int lines; 30 | 31 | public String getFrom() { 32 | return from; 33 | } 34 | 35 | public void setFrom(String from) { 36 | this.from = from; 37 | } 38 | 39 | public String[] getNewsgroups() { 40 | return newsgroups; 41 | } 42 | 43 | public void setNewsgroups(String[] newsgroups) { 44 | this.newsgroups = newsgroups; 45 | } 46 | 47 | public String getSubject() { 48 | return subject; 49 | } 50 | 51 | public void setSubject(String subject) { 52 | this.subject = subject; 53 | } 54 | 55 | public String getMessageId() { 56 | return messageId; 57 | } 58 | 59 | public void setMessageId(String messageId) { 60 | this.messageId = messageId; 61 | } 62 | 63 | public String getDate() { 64 | return date; 65 | } 66 | 67 | public void setDate(String date) { 68 | this.date = date; 69 | } 70 | 71 | public String getOrganization() { 72 | return organization; 73 | } 74 | 75 | public void setOrganization(String organization) { 76 | this.organization = organization; 77 | } 78 | 79 | public String getBody() { 80 | return body; 81 | } 82 | 83 | public void setBody(String body) { 84 | this.body = body; 85 | } 86 | 87 | public int getLines() { 88 | return lines; 89 | } 90 | 91 | public void setLines(int lines) { 92 | this.lines = lines; 93 | } 94 | 95 | public Document toLuceneDoc() { 96 | Document doc = new Document(); 97 | 98 | if (Objects.nonNull(getFrom())) { 99 | doc.add(new TextField("from", getFrom(), Field.Store.YES)); 100 | } 101 | 102 | if (Objects.nonNull(getNewsgroups())) { 103 | for (String newsgroup : getNewsgroups()) { 104 | doc.add(new StringField("newsgroup", newsgroup, Field.Store.YES)); 105 | } 106 | } 107 | 108 | if (Objects.nonNull(getSubject())) { 109 | doc.add(new TextField("subject", getSubject(), Field.Store.YES)); 110 | } 111 | 112 | if (Objects.nonNull(getMessageId())) { 113 | doc.add(new StringField("messageId", getMessageId(), Field.Store.YES)); 114 | } 115 | 116 | if (Objects.nonNull(getDate())) { 117 | doc.add(new StoredField("date_raw", getDate())); 118 | } 119 | 120 | 121 | if (getOrganization() != null) { 122 | doc.add(new TextField("organization", getOrganization(), Field.Store.YES)); 123 | } 124 | 125 | doc.add(new IntPoint("lines_range", getLines())); 126 | doc.add(new SortedNumericDocValuesField("lines_sort", getLines())); 127 | doc.add(new StoredField("lines_raw", String.valueOf(getLines()))); 128 | 129 | if (Objects.nonNull(getBody())) { 130 | doc.add(new TextField("body", getBody(), Field.Store.YES)); 131 | } 132 | 133 | return doc; 134 | } 135 | 136 | public static Analyzer createLuceneAnalyzer() { 137 | Map map = new HashMap<>(); 138 | map.put("from", new UAX29URLEmailAnalyzer()); 139 | return new PerFieldAnalyzerWrapper(new StandardAnalyzer(), map); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/util/twentynewsgroups/MessageFilesParser.java: -------------------------------------------------------------------------------- 1 | package org.apache.lucene.luke.models.util.twentynewsgroups; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.io.BufferedReader; 7 | import java.io.IOException; 8 | import java.nio.charset.StandardCharsets; 9 | import java.nio.file.FileVisitResult; 10 | import java.nio.file.Files; 11 | import java.nio.file.Path; 12 | import java.nio.file.SimpleFileVisitor; 13 | import java.nio.file.attribute.BasicFileAttributes; 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | /** 20 Newsgroups (http://kdd.ics.uci.edu/databases/20newsgroups/20newsgroups.html) message files parser */ 18 | public class MessageFilesParser extends SimpleFileVisitor { 19 | 20 | private static final Logger log = LoggerFactory.getLogger(MessageFilesParser.class); 21 | 22 | private final Path root; 23 | 24 | private final List messages = new ArrayList<>(); 25 | 26 | public MessageFilesParser(Path root) { 27 | this.root = root; 28 | } 29 | 30 | public FileVisitResult visitFile(Path file, BasicFileAttributes attr) { 31 | try { 32 | if (attr.isRegularFile()) { 33 | Message message = parse(file); 34 | if (message != null) { 35 | messages.add(parse(file)); 36 | } 37 | } 38 | } catch (IOException e) { 39 | log.warn("Invalid file? " + file.toString()); 40 | } 41 | return FileVisitResult.CONTINUE; 42 | } 43 | 44 | Message parse(Path file) throws IOException { 45 | try (BufferedReader br = Files.newBufferedReader(file, StandardCharsets.UTF_8)) { 46 | String line = br.readLine(); 47 | 48 | Message message = new Message(); 49 | while (!line.equals("")) { 50 | String[] ary = line.split(":", 2); 51 | if (ary.length < 2) { 52 | line = br.readLine(); 53 | continue; 54 | } 55 | String att = ary[0].trim(); 56 | String val = ary[1].trim(); 57 | switch (att) { 58 | case "From": 59 | message.setFrom(val); 60 | break; 61 | case "Newsgroups": 62 | message.setNewsgroups(val.split(",")); 63 | break; 64 | case "Subject": 65 | message.setSubject(val); 66 | break; 67 | case "Message-ID": 68 | message.setMessageId(val); 69 | break; 70 | case "Date": 71 | message.setDate(val); 72 | break; 73 | case "Organization": 74 | message.setOrganization(val); 75 | break; 76 | case "Lines": 77 | try { 78 | message.setLines(Integer.parseInt(ary[1].trim())); 79 | } catch (NumberFormatException e) {} 80 | default: 81 | break; 82 | } 83 | 84 | line = br.readLine(); 85 | } 86 | 87 | StringBuilder sb = new StringBuilder(); 88 | while (line != null) { 89 | sb.append(line); 90 | sb.append(" "); 91 | line = br.readLine(); 92 | } 93 | message.setBody(sb.toString()); 94 | 95 | return message; 96 | } 97 | } 98 | 99 | public List parseAll() throws IOException { 100 | Files.walkFileTree(root, this); 101 | return messages; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/models/util/twentynewsgroups/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Utilities for indexing 20 Newsgroups data */ 19 | package org.apache.lucene.luke.models.util.twentynewsgroups; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** Luke : Lucene toolbox project */ 19 | package org.apache.lucene.luke; -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/util/BytesRefUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.util; 19 | 20 | import org.apache.lucene.util.BytesRef; 21 | 22 | /** 23 | * An utility class for handling {@link BytesRef} objects. 24 | */ 25 | public final class BytesRefUtils { 26 | 27 | public static String decode(BytesRef ref) { 28 | try { 29 | return ref.utf8ToString(); 30 | } catch (Exception e) { 31 | return ref.toString(); 32 | } 33 | } 34 | 35 | private BytesRefUtils() { 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/apache/lucene/luke/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** General utilities */ 19 | package org.apache.lucene.luke.util; -------------------------------------------------------------------------------- /src/main/java/overview.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | Luke 22 | 23 | 24 | Luke - Lucene Toolbox 25 | 26 | -------------------------------------------------------------------------------- /src/main/resources/font/ElegantIcons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DmitryKey/luke/867b7de1d8dcd32220d35702995cb63214025215/src/main/resources/font/ElegantIcons.ttf -------------------------------------------------------------------------------- /src/main/resources/img/indicator.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DmitryKey/luke/867b7de1d8dcd32220d35702995cb63214025215/src/main/resources/img/indicator.gif -------------------------------------------------------------------------------- /src/main/resources/img/lucene-logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DmitryKey/luke/867b7de1d8dcd32220d35702995cb63214025215/src/main/resources/img/lucene-logo.gif -------------------------------------------------------------------------------- /src/main/resources/img/lucene.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DmitryKey/luke/867b7de1d8dcd32220d35702995cb63214025215/src/main/resources/img/lucene.gif -------------------------------------------------------------------------------- /src/main/resources/img/luke-logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DmitryKey/luke/867b7de1d8dcd32220d35702995cb63214025215/src/main/resources/img/luke-logo.gif -------------------------------------------------------------------------------- /src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | [%d{ISO8601}] %5p (%F:%L) - %m%n 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | false 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/test/java/org/apache/lucene/luke/app/desktop/util/inifile/SimpleIniFileTest.java: -------------------------------------------------------------------------------- 1 | package org.apache.lucene.luke.app.desktop.util.inifile; 2 | 3 | import org.apache.lucene.util.LuceneTestCase; 4 | import org.junit.Test; 5 | 6 | import java.io.BufferedReader; 7 | import java.io.IOException; 8 | import java.nio.charset.StandardCharsets; 9 | import java.nio.file.Files; 10 | import java.nio.file.Path; 11 | import java.util.List; 12 | import java.util.Map; 13 | import java.util.stream.Collectors; 14 | 15 | public class SimpleIniFileTest extends LuceneTestCase { 16 | 17 | @Test 18 | public void testStore() throws IOException { 19 | Path path = saveTestIni(); 20 | assertTrue(Files.exists(path)); 21 | assertTrue(Files.isRegularFile(path)); 22 | 23 | try (BufferedReader br = Files.newBufferedReader(path, StandardCharsets.UTF_8)) { 24 | List lines = br.lines().collect(Collectors.toList()); 25 | assertEquals(8, lines.size()); 26 | assertEquals("[section1]", lines.get(0)); 27 | assertEquals("s1 = aaa", lines.get(1)); 28 | assertEquals("s2 = bbb", lines.get(2)); 29 | assertEquals("", lines.get(3)); 30 | assertEquals("[section2]", lines.get(4)); 31 | assertEquals("b1 = true", lines.get(5)); 32 | assertEquals("b2 = false", lines.get(6)); 33 | assertEquals("", lines.get(7)); 34 | } 35 | } 36 | 37 | @Test 38 | public void testLoad() throws IOException { 39 | Path path = saveTestIni(); 40 | 41 | SimpleIniFile iniFile = new SimpleIniFile(); 42 | iniFile.load(path); 43 | 44 | Map sections = iniFile.getSections(); 45 | assertEquals(2, sections.size()); 46 | assertEquals(2, sections.get("section1").size()); 47 | assertEquals(2, sections.get("section2").size()); 48 | } 49 | 50 | @Test 51 | public void testPut() { 52 | SimpleIniFile iniFile = new SimpleIniFile(); 53 | iniFile.put("section1", "s1", "aaa"); 54 | iniFile.put("section1", "s1", "aaa_updated"); 55 | iniFile.put("section2", "b1", true); 56 | iniFile.put("section2", "b2", null); 57 | 58 | Map sections = iniFile.getSections(); 59 | assertEquals("aaa_updated", sections.get("section1").get("s1")); 60 | assertEquals("true", sections.get("section2").get("b1")); 61 | assertNull(sections.get("section2").get("b2")); 62 | } 63 | 64 | @Test 65 | public void testGet() throws IOException { 66 | Path path = saveTestIni(); 67 | SimpleIniFile iniFile = new SimpleIniFile(); 68 | iniFile.load(path); 69 | 70 | assertNull(iniFile.getString("", "")); 71 | 72 | assertEquals("aaa", iniFile.getString("section1", "s1")); 73 | assertEquals("bbb", iniFile.getString("section1", "s2")); 74 | assertNull(iniFile.getString("section1", "s3")); 75 | assertNull(iniFile.getString("section1", "")); 76 | 77 | assertEquals(true, iniFile.getBoolean("section2", "b1")); 78 | assertEquals(false, iniFile.getBoolean("section2", "b2")); 79 | assertFalse(iniFile.getBoolean("section2", "b3")); 80 | } 81 | 82 | private Path saveTestIni() throws IOException { 83 | SimpleIniFile iniFile = new SimpleIniFile(); 84 | iniFile.put("", "s0", "000"); 85 | 86 | iniFile.put("section1", "s1", "aaa"); 87 | iniFile.put("section1", "s2", "---"); 88 | iniFile.put("section1", "s2", "bbb"); 89 | iniFile.put("section1", "", "ccc"); 90 | 91 | iniFile.put("section2", "b1", true); 92 | iniFile.put("section2", "b2", false); 93 | 94 | Path path = createTempFile(); 95 | iniFile.store(path); 96 | return path; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/test/java/org/apache/lucene/luke/models/overview/OverviewTestBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.overview; 19 | 20 | import org.apache.lucene.analysis.MockAnalyzer; 21 | import org.apache.lucene.document.Document; 22 | import org.apache.lucene.document.Field; 23 | import org.apache.lucene.document.TextField; 24 | import org.apache.lucene.index.DirectoryReader; 25 | import org.apache.lucene.index.IndexReader; 26 | import org.apache.lucene.index.RandomIndexWriter; 27 | import org.apache.lucene.store.Directory; 28 | import org.apache.lucene.util.LuceneTestCase; 29 | import org.junit.After; 30 | import org.junit.Before; 31 | 32 | import java.io.IOException; 33 | import java.nio.file.Path; 34 | import java.util.Collections; 35 | import java.util.HashMap; 36 | import java.util.Map; 37 | 38 | public abstract class OverviewTestBase extends LuceneTestCase { 39 | 40 | IndexReader reader; 41 | 42 | Directory dir; 43 | 44 | Path indexDir; 45 | 46 | @Override 47 | @Before 48 | public void setUp() throws Exception { 49 | super.setUp(); 50 | indexDir = createIndex(); 51 | dir = newFSDirectory(indexDir); 52 | reader = DirectoryReader.open(dir); 53 | } 54 | 55 | private Path createIndex() throws IOException { 56 | Path indexDir = createTempDir(); 57 | 58 | Directory dir = newFSDirectory(indexDir); 59 | RandomIndexWriter writer = new RandomIndexWriter(random(), dir, new MockAnalyzer(random())); 60 | 61 | Document doc1 = new Document(); 62 | doc1.add(newStringField("f1", "1", Field.Store.NO)); 63 | doc1.add(newTextField("f2", "a b c d e", Field.Store.NO)); 64 | writer.addDocument(doc1); 65 | 66 | Document doc2 = new Document(); 67 | doc2.add(newStringField("f1", "2", Field.Store.NO)); 68 | doc2.add(new TextField("f2", "a c", Field.Store.NO)); 69 | writer.addDocument(doc2); 70 | 71 | Document doc3 = new Document(); 72 | doc3.add(newStringField("f1", "3", Field.Store.NO)); 73 | doc3.add(newTextField("f2", "a f", Field.Store.NO)); 74 | writer.addDocument(doc3); 75 | 76 | Map userData = new HashMap<>(); 77 | userData.put("data", "val"); 78 | writer.w.setLiveCommitData(userData.entrySet()); 79 | 80 | writer.commit(); 81 | 82 | writer.close(); 83 | dir.close(); 84 | 85 | return indexDir; 86 | } 87 | 88 | @Override 89 | @After 90 | public void tearDown() throws Exception { 91 | super.tearDown(); 92 | reader.close(); 93 | dir.close(); 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/test/java/org/apache/lucene/luke/models/overview/TermCountsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.overview; 19 | 20 | import org.junit.Test; 21 | 22 | import java.util.ArrayList; 23 | import java.util.Arrays; 24 | import java.util.Map; 25 | 26 | public class TermCountsTest extends OverviewTestBase { 27 | 28 | @Test 29 | public void testNumTerms() throws Exception { 30 | TermCounts termCounts = new TermCounts(reader); 31 | assertEquals(9, termCounts.numTerms()); 32 | } 33 | 34 | @Test 35 | @SuppressWarnings("unchecked") 36 | public void testSortedTermCounts_count_asc() throws Exception { 37 | TermCounts termCounts = new TermCounts(reader); 38 | 39 | Map countsMap = termCounts.sortedTermCounts(TermCountsOrder.COUNT_ASC); 40 | assertEquals(Arrays.asList("f1", "f2"), new ArrayList<>(countsMap.keySet())); 41 | 42 | assertEquals(3, (long) countsMap.get("f1")); 43 | assertEquals(6, (long) countsMap.get("f2")); 44 | } 45 | 46 | @Test 47 | @SuppressWarnings("unchecked") 48 | public void testSortedTermCounts_count_desc() throws Exception { 49 | TermCounts termCounts = new TermCounts(reader); 50 | 51 | Map countsMap = termCounts.sortedTermCounts(TermCountsOrder.COUNT_DESC); 52 | assertEquals(Arrays.asList("f2", "f1"), new ArrayList<>(countsMap.keySet())); 53 | 54 | assertEquals(3, (long) countsMap.get("f1")); 55 | assertEquals(6, (long) countsMap.get("f2")); 56 | } 57 | 58 | @Test 59 | @SuppressWarnings("unchecked") 60 | public void testSortedTermCounts_name_asc() throws Exception { 61 | TermCounts termCounts = new TermCounts(reader); 62 | 63 | Map countsMap = termCounts.sortedTermCounts(TermCountsOrder.NAME_ASC); 64 | assertEquals(Arrays.asList("f1", "f2"), new ArrayList<>(countsMap.keySet())); 65 | 66 | assertEquals(3, (long) countsMap.get("f1")); 67 | assertEquals(6, (long) countsMap.get("f2")); 68 | } 69 | 70 | @Test 71 | @SuppressWarnings("unchecked") 72 | public void testSortedTermCounts_name_desc() throws Exception { 73 | TermCounts termCounts = new TermCounts(reader); 74 | 75 | Map countsMap = termCounts.sortedTermCounts(TermCountsOrder.NAME_DESC); 76 | assertEquals(Arrays.asList("f2", "f1"), new ArrayList<>(countsMap.keySet())); 77 | 78 | assertEquals(3, (long) countsMap.get("f1")); 79 | assertEquals(6, (long) countsMap.get("f2")); 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /src/test/java/org/apache/lucene/luke/models/overview/TopTermsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.lucene.luke.models.overview; 19 | 20 | import org.junit.Test; 21 | 22 | import java.util.List; 23 | 24 | public class TopTermsTest extends OverviewTestBase { 25 | 26 | @Test 27 | public void testGetTopTerms() throws Exception { 28 | TopTerms topTerms = new TopTerms(reader); 29 | List result = topTerms.getTopTerms("f2", 2); 30 | 31 | assertEquals("a", result.get(0).getDecodedTermText()); 32 | assertEquals(3, result.get(0).getDocFreq()); 33 | assertEquals("f2", result.get(0).getField()); 34 | 35 | assertEquals("c", result.get(1).getDecodedTermText()); 36 | assertEquals(2, result.get(1).getDocFreq()); 37 | assertEquals("f2", result.get(1).getField()); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/test/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | 22 | [%d{ISO8601}] %5p (%F:%L) - %m%n 23 | 24 | 25 | 26 | 27 | 28 | --------------------------------------------------------------------------------