You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sa...@apache.org on 2018/07/17 21:12:43 UTC
[08/48] lucene-solr:jira/lucene-2562: Add luke as a sub-module.
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/AddDocumentController.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/AddDocumentController.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/AddDocumentController.java
new file mode 100644
index 0000000..1cc1a54
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/AddDocumentController.java
@@ -0,0 +1,423 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dialog.documents;
+
+import com.google.common.base.Strings;
+import com.google.inject.Inject;
+import javafx.beans.property.BooleanProperty;
+import javafx.beans.property.ObjectProperty;
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import javafx.fxml.FXML;
+import javafx.geometry.Insets;
+import javafx.geometry.Orientation;
+import javafx.geometry.Pos;
+import javafx.scene.control.Button;
+import javafx.scene.control.ChoiceBox;
+import javafx.scene.control.Hyperlink;
+import javafx.scene.control.Label;
+import javafx.scene.control.TableCell;
+import javafx.scene.control.TableColumn;
+import javafx.scene.control.TableView;
+import javafx.scene.control.TextArea;
+import javafx.scene.control.cell.CheckBoxTableCell;
+import javafx.scene.control.cell.ChoiceBoxTableCell;
+import javafx.scene.control.cell.PropertyValueFactory;
+import javafx.scene.control.cell.TextFieldTableCell;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
+import javafx.scene.layout.FlowPane;
+import javafx.scene.layout.VBox;
+import javafx.stage.Stage;
+import javafx.util.StringConverter;
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.DoublePoint;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.FloatPoint;
+import org.apache.lucene.document.IntPoint;
+import org.apache.lucene.document.LongPoint;
+import org.apache.lucene.document.NumericDocValuesField;
+import org.apache.lucene.document.SortedDocValuesField;
+import org.apache.lucene.document.SortedNumericDocValuesField;
+import org.apache.lucene.document.SortedSetDocValuesField;
+import org.apache.lucene.document.StoredField;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.document.TextField;
+import org.apache.lucene.index.IndexableField;
+import org.apache.lucene.index.IndexableFieldType;
+import org.apache.lucene.luke.app.IndexHandler;
+import org.apache.lucene.luke.app.LukeState;
+import org.apache.lucene.luke.app.controllers.DocumentsController;
+import org.apache.lucene.luke.app.controllers.LukeController;
+import org.apache.lucene.luke.app.controllers.dialog.DialogWindowController;
+import org.apache.lucene.luke.app.controllers.dialog.HelpController;
+import org.apache.lucene.luke.app.controllers.dto.documents.NewField;
+import org.apache.lucene.luke.app.util.DialogOpener;
+import org.apache.lucene.luke.app.util.NumericUtils;
+import org.apache.lucene.luke.models.LukeException;
+import org.apache.lucene.luke.models.tools.IndexTools;
+import org.apache.lucene.luke.app.util.MessageUtils;
+import org.apache.lucene.luke.models.tools.IndexToolsFactory;
+import org.apache.lucene.util.BytesRef;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Constructor;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+import static org.apache.lucene.luke.app.util.ExceptionHandler.runnableWrapper;
+
+public class AddDocumentController implements DialogWindowController {
+
+ private static Logger logger = LoggerFactory.getLogger(AddDocumentController.class);
+
+ private final IndexHandler indexHandler;
+
+ private IndexTools toolsModel;
+
+ private LukeController parent;
+
+ private DocumentsController documentsController;
+
+ private Analyzer currentAnalyzer;
+
+ @Inject
+ public AddDocumentController(IndexToolsFactory toolsFactory, IndexHandler indexHandler) {
+ this.indexHandler = indexHandler;
+
+ LukeState state = indexHandler.getState();
+ this.toolsModel = toolsFactory.newInstance(state.getIndexReader(), state.useCompound(), state.keepAllCommits());
+ }
+
+ @FXML
+ private Label analyzerName;
+
+ @FXML
+ private Hyperlink changeAnalyzer;
+
+ @FXML
+ private TableView<NewField> fieldsTable;
+
+ @FXML
+ private TableColumn<NewField, Boolean> delColumn;
+
+ @FXML
+ private TableColumn<NewField, String> nameColumn;
+
+ @FXML
+ private TableColumn<NewField, Class> typeColumn;
+
+ @FXML
+ private TableColumn<NewField, Hyperlink> optColumn;
+
+ @FXML
+ private TableColumn<NewField, String> valueColumn;
+
+ private ObservableList<NewField> newFieldList;
+
+ @FXML
+ private Button add;
+
+ @FXML
+ private Button cancel;
+
+ @FXML
+ private TextArea info;
+
+ @FXML
+ private void initialize() {
+ changeAnalyzer.setOnAction(e -> {
+ parent.switchTab(LukeController.Tab.ANALYZER);
+ closeWindow(cancel);
+ });
+
+ delColumn.setCellValueFactory(data -> {
+ BooleanProperty prop = data.getValue().deletedProperty();
+ prop.addListener((obs, oldV, newV) ->
+ fieldsTable.getSelectionModel().getSelectedItem().setDeleted(newV)
+ );
+ return prop;
+ });
+ delColumn.setCellFactory(col -> {
+ CheckBoxTableCell<NewField, Boolean> cell = new CheckBoxTableCell<>();
+ cell.setAlignment(Pos.CENTER);
+ return cell;
+ });
+
+ nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
+ nameColumn.setCellFactory(TextFieldTableCell.forTableColumn());
+ nameColumn.setOnEditCommit(e -> {
+ int rowIdx = fieldsTable.getSelectionModel().getFocusedIndex();
+ newFieldList.get(rowIdx).setName(e.getNewValue());
+ });
+
+ ImageView imageView = new ImageView(new Image("/img/icon_question_alt2.png"));
+ imageView.setFitWidth(12);
+ imageView.setFitHeight(12);
+ Hyperlink helpLink = new Hyperlink(MessageUtils.getLocalizedMessage("label.help"), imageView);
+ helpLink.setOnMouseClicked(e -> runnableWrapper(this::showTypeHelpDialog));
+ Label flagLabel = new Label("Type");
+ flagLabel.setPadding(new Insets(0, 10, 0, 0));
+ FlowPane flowPane = new FlowPane();
+ flowPane.setOrientation(Orientation.HORIZONTAL);
+ flowPane.setMaxWidth(Double.MAX_VALUE);
+ flowPane.setAlignment(Pos.CENTER);
+ flowPane.getChildren().addAll(flagLabel, helpLink);
+ typeColumn.setGraphic(flowPane);
+
+ typeColumn.setCellValueFactory(data -> {
+ ObjectProperty<Class> prop = data.getValue().getTypeProperty();
+ prop.addListener((obs, oldV, newV) -> {
+ NewField selectedItem = fieldsTable.getSelectionModel().getSelectedItem();
+ selectedItem.setType(newV);
+ selectedItem.resetFieldType(newV);
+ selectedItem.setStored(selectedItem.getFieldType().stored());
+ });
+ return prop;
+ });
+ typeColumn.setCellFactory(col -> {
+ ChoiceBoxTableCell<NewField, Class> cell = new ChoiceBoxTableCell<>();
+ cell.setConverter(new StringConverter<Class>() {
+ @Override
+ public String toString(Class clazz) {
+ return clazz.getSimpleName();
+ }
+
+ @Override
+ public Class fromString(String className) {
+ try {
+ return Class.forName(className);
+ } catch (ClassNotFoundException e) {
+ logger.error(e.getMessage(), e);
+ parent.showUnknownErrorMessage();
+ }
+ return null;
+ }
+ });
+ cell.getItems().addAll(presetFields());
+ return cell;
+ });
+
+ optColumn.setCellValueFactory(new PropertyValueFactory<>("option"));
+ optColumn.setCellFactory(col -> {
+ TableCell<NewField, Hyperlink> cell = new TableCell<NewField, Hyperlink>() {
+ @Override
+ protected void updateItem(Hyperlink link, boolean empty) {
+ setGraphic(link);
+ if (!empty) {
+ int rowIdx = getTableRow().getIndex();
+ link.setOnAction(e -> runnableWrapper(() -> showOptionsDialog(newFieldList.get(rowIdx))));
+ }
+ }
+ };
+ return cell;
+ });
+
+ valueColumn.setCellValueFactory(new PropertyValueFactory<>("value"));
+ valueColumn.setCellFactory(TextFieldTableCell.forTableColumn());
+ valueColumn.setOnEditCommit(e -> {
+ int rowIdx = fieldsTable.getSelectionModel().getFocusedIndex();
+ NewField selectedItem = newFieldList.get(rowIdx);
+ selectedItem.setValue(e.getNewValue());
+ selectedItem.resetFieldType(selectedItem.getType());
+ });
+
+ newFieldList = FXCollections.observableArrayList(
+ IntStream.range(0, 50).mapToObj(i -> NewField.newInstance()).collect(Collectors.toList())
+ );
+ fieldsTable.setItems(newFieldList);
+
+ add.setOnAction(e -> runnableWrapper(this::addDocument));
+ cancel.setOnAction(e -> closeWindow(cancel));
+ }
+
+ private Stage typeHelpDialog;
+
+ private void showTypeHelpDialog() throws Exception {
+ ObservableList<String> typesList = FXCollections.observableArrayList(
+ "TextField",
+ "StringField",
+ "IntPoint",
+ "LongPoint",
+ "FloatPoint",
+ "DoublePoint",
+ "SortedDocValuesField",
+ "SortedSetDocValuesField",
+ "NumericDocValuesField",
+ "SortedNumericDocValuesField",
+ "StoredField",
+ "Field"
+ );
+ ChoiceBox<String> types = new ChoiceBox<>(typesList);
+
+ TextArea details = new TextArea();
+ details.setEditable(false);
+ details.setWrapText(true);
+ details.setPrefHeight(300);
+ types.setOnAction(e -> {
+ String detail = MessageUtils.getLocalizedMessage("help.fieldtype." + types.getValue());
+ details.setText(detail);
+ });
+ types.setValue(typesList.get(0));
+
+ Label description = new Label("Brief description and Examples");
+
+ VBox vBox = new VBox();
+ vBox.getChildren().addAll(types, description, details);
+ vBox.setFillWidth(true);
+ vBox.setSpacing(10);
+
+ typeHelpDialog = new DialogOpener<HelpController>(parent).show(
+ typeHelpDialog,
+ "About type",
+ "/fxml/dialog/help.fxml",
+ 500, 400,
+ (controller) -> {
+ controller.setDescription("Select Field Class:");
+ controller.setContent(vBox);
+ }
+ );
+ }
+
+ private Stage optionsDialog;
+
+ private void showOptionsDialog(NewField nf) throws Exception {
+ optionsDialog = new DialogOpener<IndexOptionsController>(parent).show(
+ optionsDialog,
+ "Index Options for field: " + nf.getName(),
+ "/fxml/dialog/documents/index_options.fxml",
+ 500, 500,
+ (controller) -> {
+ controller.setNewField(nf);
+ },
+ "/styles/index_options.css"
+ );
+ }
+
+ private void addDocument() throws LukeException {
+ List<NewField> validFields = newFieldList.stream()
+ .filter(nf -> !nf.isDeleted())
+ .filter(nf -> !Strings.isNullOrEmpty(nf.getName()))
+ .filter(nf -> !Strings.isNullOrEmpty(nf.getValue()))
+ .collect(Collectors.toList());
+ if (validFields.isEmpty()) {
+ info.setText("Please add one or more fields. Name and Value are both required.");
+ return;
+ }
+
+ Document doc = new Document();
+ try {
+ for (NewField nf : validFields) {
+ doc.add(toIndexableField(nf));
+ System.out.println(doc);
+ }
+ } catch (NumberFormatException e) {
+ logger.error(e.getMessage(), e);
+ throw new LukeException("Invalid value: " + e.getMessage(), e);
+ } catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ throw new LukeException(e.getMessage(), e);
+ }
+
+ try {
+ toolsModel.addDocument(doc, currentAnalyzer);
+ indexHandler.reOpen();
+ documentsController.displayLatestDoc();
+ parent.switchTab(LukeController.Tab.DOCUMENTS);
+ info.setText(MessageUtils.getLocalizedMessage("add_document.message.success"));
+ add.setDisable(true);
+ } catch (LukeException e) {
+ info.setText(MessageUtils.getLocalizedMessage("add_document.message.fail"));
+ throw e;
+ } catch (Exception e) {
+ info.setText(MessageUtils.getLocalizedMessage("add_document.message.fail"));
+ throw new LukeException(e.getMessage(), e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private IndexableField toIndexableField(NewField nf) throws Exception {
+ if (nf.getType().equals(TextField.class) || nf.getType().equals(StringField.class)) {
+ Field.Store store = nf.isStored() ? Field.Store.YES : Field.Store.NO;
+ Constructor<IndexableField> constr = nf.getType().getConstructor(String.class, String.class, Field.Store.class);
+ return constr.newInstance(nf.getName(), nf.getValue(), store);
+ } else if (nf.getType().equals(IntPoint.class)) {
+ Constructor<IndexableField> constr = nf.getType().getConstructor(String.class, int[].class);
+ int[] values = NumericUtils.convertToIntArray(nf.getValue(), false);
+ return constr.newInstance(nf.getName(), values);
+ } else if (nf.getType().equals(LongPoint.class)) {
+ Constructor<IndexableField> constr = nf.getType().getConstructor(String.class, long[].class);
+ long[] values = NumericUtils.convertToLongArray(nf.getValue(), false);
+ return constr.newInstance(nf.getName(), values);
+ } else if (nf.getType().equals(FloatPoint.class)) {
+ Constructor<IndexableField> constr = nf.getType().getConstructor(String.class, float[].class);
+ float[] values = NumericUtils.convertToFloatArray(nf.getValue(), false);
+ return constr.newInstance(nf.getName(), values);
+ } else if (nf.getType().equals(DoublePoint.class)) {
+ Constructor<IndexableField> constr = nf.getType().getConstructor(String.class, double[].class);
+ double[] values = NumericUtils.convertToDoubleArray(nf.getValue(), false);
+ return constr.newInstance(nf.getName(), values);
+ } else if (nf.getType().equals(SortedDocValuesField.class) ||
+ nf.getType().equals(SortedSetDocValuesField.class)) {
+ Constructor<IndexableField> constr = nf.getType().getConstructor(String.class, BytesRef.class);
+ return constr.newInstance(nf.getName(), new BytesRef(nf.getValue()));
+ } else if (nf.getType().equals(NumericDocValuesField.class) ||
+ nf.getType().equals(SortedNumericDocValuesField.class)) {
+ Constructor<IndexableField> constr = nf.getType().getConstructor(String.class, long.class);
+ long value = NumericUtils.tryConvertToLongValue(nf.getValue());
+ return constr.newInstance(nf.getName(), value);
+ } else if (nf.getType().equals(StoredField.class)) {
+ Constructor<IndexableField> constr = nf.getType().getConstructor(String.class, String.class);
+ return constr.newInstance(nf.getName(), nf.getValue());
+ } else if (nf.getType().equals(Field.class)) {
+ Constructor<IndexableField> constr = nf.getType().getConstructor(String.class, String.class, IndexableFieldType.class);
+ return constr.newInstance(nf.getName(), nf.getValue(), nf.getFieldType());
+ } else {
+ // TODO: unknown field
+ return new StringField(nf.getName(), nf.getValue(), Field.Store.YES);
+ }
+ }
+
+ public void setParent(LukeController parent, DocumentsController documentsController) {
+ this.parent = parent;
+ this.documentsController = documentsController;
+ }
+
+ public void setAnalyzer(Analyzer analyzer) {
+ this.currentAnalyzer = analyzer;
+ analyzerName.setText(analyzer.getClass().getName());
+ }
+
+ @SuppressWarnings("unchecked")
+ private static List<Class<? extends Field>> presetFields() {
+ final Class[] presetFieldClasses = new Class[]{
+ TextField.class, StringField.class,
+ IntPoint.class, LongPoint.class, FloatPoint.class, DoublePoint.class,
+ SortedDocValuesField.class, SortedSetDocValuesField.class,
+ NumericDocValuesField.class, SortedNumericDocValuesField.class,
+ StoredField.class, Field.class
+ };
+ return Arrays.asList(presetFieldClasses);
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/DocValuesController.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/DocValuesController.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/DocValuesController.java
new file mode 100644
index 0000000..b7bc6a4
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/DocValuesController.java
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dialog.documents;
+
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import javafx.fxml.FXML;
+import javafx.scene.control.Button;
+import javafx.scene.control.ChoiceBox;
+import javafx.scene.control.Label;
+import javafx.scene.control.ListView;
+import javafx.scene.control.SelectionMode;
+import javafx.scene.input.Clipboard;
+import javafx.scene.input.ClipboardContent;
+import javafx.scene.layout.FlowPane;
+import org.apache.lucene.luke.app.controllers.dialog.DialogWindowController;
+import org.apache.lucene.luke.models.documents.DocValues;
+import org.apache.lucene.luke.util.BytesRefUtils;
+import org.apache.lucene.util.NumericUtils;
+
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+public class DocValuesController implements DialogWindowController {
+
+ private DocValues docValues;
+
+ @FXML
+ private Label field;
+
+ @FXML
+ private Label dvType;
+
+ @FXML
+ private FlowPane decoderPane;
+
+ @FXML
+ private ChoiceBox<Decoder> decoders;
+
+ @FXML
+ private ListView<String> values;
+
+ private ObservableList<String> valueList;
+
+ @FXML
+ private Button copy;
+
+ @FXML
+ private Button close;
+
+ @FXML
+ private void initialize() {
+ decoders.getItems().addAll(Arrays.asList(Decoder.values()));
+ decoders.setValue(Decoder.LONG);
+ decoders.setOnAction(e -> {
+ onChangeDecoder(decoders.getSelectionModel().getSelectedItem());
+ });
+
+ valueList = FXCollections.observableArrayList();
+ values.setItems(valueList);
+ values.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
+
+ copy.setOnAction(e -> copyToClipboard());
+ close.setOnAction(e -> closeWindow(close));
+ }
+
+ public void setValue(String fieldName, DocValues docValues) {
+ this.docValues = docValues;
+
+ field.setText(fieldName);
+ dvType.setText(docValues.getDvType().toString());
+
+ if (docValues.getValues().size() > 0) {
+ decoderPane.setDisable(true);
+ valueList.setAll(
+ docValues.getValues().stream()
+ .map(BytesRefUtils::decode)
+ .collect(Collectors.toList()));
+
+ } else if (docValues.getNumericValues().size() > 0) {
+ valueList.setAll(
+ docValues.getNumericValues().stream()
+ .map(String::valueOf)
+ .collect(Collectors.toList())
+ );
+ }
+ }
+
+ private void onChangeDecoder(Decoder decoder) {
+ if (docValues.getNumericValues().isEmpty()) {
+ return;
+ }
+ valueList.clear();
+ switch (decoder) {
+ case LONG:
+ valueList.setAll(
+ docValues.getNumericValues().stream()
+ .map(String::valueOf)
+ .collect(Collectors.toList())
+ );
+ break;
+ case FLOAT:
+ valueList.setAll(
+ docValues.getNumericValues().stream()
+ .mapToInt(Long::intValue)
+ .mapToObj(NumericUtils::sortableIntToFloat)
+ .map(String::valueOf)
+ .collect(Collectors.toList())
+ );
+ break;
+ case DOUBLE:
+ valueList.setAll(
+ docValues.getNumericValues().stream()
+ .map(NumericUtils::sortableLongToDouble)
+ .map(String::valueOf)
+ .collect(Collectors.toList())
+ );
+ break;
+ default:
+ }
+ }
+
+ private void copyToClipboard() {
+ Clipboard clipboard = Clipboard.getSystemClipboard();
+ ClipboardContent content = new ClipboardContent();
+ ObservableList<String> selected = values.getSelectionModel().getSelectedItems();
+ if (selected.isEmpty()) {
+ content.putString(String.join("\n", valueList));
+ } else {
+ content.putString(String.join("\n", selected));
+ }
+ clipboard.setContent(content);
+ }
+
+ enum Decoder {
+
+ LONG("long"), FLOAT("float"), DOUBLE("double");
+
+ private final String label;
+
+ Decoder(String label) {
+ this.label = label;
+ }
+
+ @Override
+ public String toString() {
+ return label;
+ }
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/IndexOptionsController.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/IndexOptionsController.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/IndexOptionsController.java
new file mode 100644
index 0000000..554d866
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/IndexOptionsController.java
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dialog.documents;
+
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import javafx.fxml.FXML;
+import javafx.scene.control.Button;
+import javafx.scene.control.CheckBox;
+import javafx.scene.control.ChoiceBox;
+import javafx.scene.control.TextField;
+import javafx.util.converter.IntegerStringConverter;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.FieldType;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.index.DocValuesType;
+import org.apache.lucene.index.IndexOptions;
+import org.apache.lucene.index.IndexableFieldType;
+import org.apache.lucene.luke.app.controllers.dialog.DialogWindowController;
+import org.apache.lucene.luke.app.controllers.dto.documents.NewField;
+import org.apache.lucene.luke.app.util.IntegerTextFormatter;
+
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+public class IndexOptionsController implements DialogWindowController {
+
+ private NewField nf;
+
+ @FXML
+ private CheckBox stored;
+
+ @FXML
+ private CheckBox tokenized;
+
+ @FXML
+ private CheckBox omitNorms;
+
+ @FXML
+ private ChoiceBox<String> idxOptions;
+
+ private ObservableList<String> idxOptionList;
+
+ @FXML
+ private CheckBox storeTv;
+
+ @FXML
+ private CheckBox storeTvPos;
+
+ @FXML
+ private CheckBox storeTvOff;
+
+ @FXML
+ private CheckBox storeTvPay;
+
+ @FXML
+ private ChoiceBox<String> dvType;
+
+ private ObservableList<String> dvTypeList;
+
+ @FXML
+ private TextField pvDimCount;
+
+ @FXML
+ private TextField pvDimNumB;
+
+ @FXML
+ private Button ok;
+
+ @FXML
+ private Button cancel;
+
+ @FXML
+ private void initialize() {
+ idxOptionList = FXCollections.observableArrayList(
+ Arrays.stream(IndexOptions.values()).map(IndexOptions::name).collect(Collectors.toList())
+ );
+ idxOptions.setItems(idxOptionList);
+
+ dvTypeList = FXCollections.observableArrayList(
+ Arrays.stream(DocValuesType.values()).map(DocValuesType::name).collect(Collectors.toList())
+ );
+ dvType.setItems(dvTypeList);
+
+ pvDimCount.setTextFormatter(new IntegerTextFormatter(new IntegerStringConverter(), 0));
+
+ pvDimNumB.setTextFormatter(new IntegerTextFormatter(new IntegerStringConverter(), 0));
+
+ ok.setOnAction(e -> saveOptions());
+ cancel.setOnAction(e -> closeWindow(cancel));
+ }
+
+ private void saveOptions() {
+ nf.setStored(stored.isSelected());
+ if (nf.getType().equals(Field.class)) {
+ FieldType ftype = (FieldType) nf.getFieldType();
+ ftype.setStored(stored.isSelected());
+ ftype.setTokenized(tokenized.isSelected());
+ ftype.setOmitNorms(omitNorms.isSelected());
+ ftype.setIndexOptions(IndexOptions.valueOf(idxOptions.getValue()));
+ ftype.setStoreTermVectors(storeTv.isSelected());
+ ftype.setStoreTermVectorPositions(storeTvPay.isSelected());
+ ftype.setStoreTermVectorOffsets(storeTvOff.isSelected());
+ ftype.setStoreTermVectorPayloads(storeTvPay.isSelected());
+ }
+ closeWindow(ok);
+ }
+
+ void setNewField(NewField nf) {
+ this.nf = nf;
+
+ stored.setSelected(nf.isStored());
+
+ IndexableFieldType fieldType = nf.getFieldType();
+ tokenized.setSelected(fieldType.tokenized());
+ omitNorms.setSelected(fieldType.omitNorms());
+ idxOptions.setValue(fieldType.indexOptions().name());
+ storeTv.setSelected(fieldType.storeTermVectors());
+ storeTvPos.setSelected(fieldType.storeTermVectorPositions());
+ storeTvOff.setSelected(fieldType.storeTermVectorOffsets());
+ storeTvPay.setSelected(fieldType.storeTermVectorPayloads());
+ dvType.setValue(fieldType.docValuesType().name());
+ pvDimCount.setText(String.valueOf(fieldType.pointDimensionCount()));
+ pvDimNumB.setText(String.valueOf(fieldType.pointNumBytes()));
+
+ if (nf.getType().equals(org.apache.lucene.document.TextField.class) ||
+ nf.getType().equals(StringField.class) ||
+ nf.getType().equals(Field.class)) {
+ stored.setDisable(false);
+ } else {
+ stored.setDisable(true);
+ //stored.setStyle("-fx-opacity: 0.8");
+ }
+
+ if (nf.getType().equals(Field.class)) {
+ tokenized.setDisable(false);
+ omitNorms.setDisable(false);
+ idxOptions.setDisable(false);
+ storeTv.setDisable(false);
+ storeTvPos.setDisable(false);
+ storeTvOff.setDisable(false);
+ storeTvPay.setDisable(false);
+ } else {
+ tokenized.setDisable(true);
+ //tokenized.setStyle("-fx-opacity: 0.8");
+ omitNorms.setDisable(true);
+ //omitNorms.setStyle("-fx-opacity: 0.8");
+ idxOptions.setDisable(true);
+ //idxOptions.setStyle("-fx-opacity: 0.8");
+ storeTv.setDisable(true);
+ //storeTv.setStyle("-fx-opacity: 0.8");
+ storeTvPos.setDisable(true);
+ //storeTvPos.setStyle("-fx-opacity: 0.8");
+ storeTvOff.setDisable(true);
+ //storeTvOff.setStyle("-fx-opacity: 0.8");
+ storeTvPay.setDisable(true);
+ //storeTvPay.setStyle("-fx-opacity: 0.8");
+ }
+
+ // TODO
+ dvType.setDisable(true);
+ //dvType.setStyle("-fx-opacity: 0.8");
+ pvDimCount.setDisable(true);
+ //pvDimCount.setStyle("-fx-opacity: 0.8");
+ pvDimNumB.setDisable(true);
+ //pvDimNumB.setStyle("-fx-opacity: 0.8");
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/StoredValueController.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/StoredValueController.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/StoredValueController.java
new file mode 100644
index 0000000..8dd9c3e
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/StoredValueController.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dialog.documents;
+
+import javafx.fxml.FXML;
+import javafx.scene.control.Button;
+import javafx.scene.control.Label;
+import javafx.scene.control.TextArea;
+import javafx.scene.input.Clipboard;
+import javafx.scene.input.ClipboardContent;
+import org.apache.lucene.luke.app.controllers.dialog.DialogWindowController;
+
+public class StoredValueController implements DialogWindowController {
+
+ @FXML
+ private Label field;
+
+ @FXML
+ private TextArea value;
+
+ @FXML
+ private Button copy;
+
+ @FXML
+ private Button close;
+
+
+ @FXML
+ private void initialize() {
+ copy.setOnAction(e -> copyToClipboard());
+ close.setOnAction(e -> closeWindow(close));
+ }
+
+ public void setValue(String fieldName, String stored) {
+ field.setText(fieldName);
+ value.setText(stored);
+ }
+
+ private void copyToClipboard() {
+ Clipboard clipboard = Clipboard.getSystemClipboard();
+ ClipboardContent content = new ClipboardContent();
+ content.putString(value.getText());
+ clipboard.setContent(content);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/TermVectorController.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/TermVectorController.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/TermVectorController.java
new file mode 100644
index 0000000..5782ac9
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/documents/TermVectorController.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dialog.documents;
+
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import javafx.fxml.FXML;
+import javafx.scene.control.Button;
+import javafx.scene.control.Label;
+import javafx.scene.control.TableColumn;
+import javafx.scene.control.TableView;
+import javafx.scene.control.cell.PropertyValueFactory;
+import org.apache.lucene.luke.app.controllers.dialog.DialogWindowController;
+import org.apache.lucene.luke.app.controllers.dto.documents.TermVector;
+import org.apache.lucene.luke.models.documents.TermVectorEntry;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class TermVectorController implements DialogWindowController {
+
+ @FXML
+ private Label field;
+
+ @FXML
+ private TableView<TermVector> termVectorTable;
+
+ @FXML
+ private TableColumn<TermVector, String> termColumn;
+
+ @FXML
+ private TableColumn<TermVector, Integer> freqColumn;
+
+ @FXML
+ private TableColumn<TermVector, String> positionsColumn;
+
+ @FXML
+ private TableColumn<TermVector, String> offsetsColumn;
+
+ private ObservableList<TermVector> termVectorList;
+
+ @FXML
+ private Button close;
+
+ @FXML
+ private void initialize() {
+ // initialize term vector table
+ termColumn.setCellValueFactory(new PropertyValueFactory<>("termText"));
+ freqColumn.setCellValueFactory(new PropertyValueFactory<>("freq"));
+ positionsColumn.setCellValueFactory(new PropertyValueFactory<>("positions"));
+ offsetsColumn.setCellValueFactory(new PropertyValueFactory<>("offsets"));
+ termVectorList = FXCollections.observableArrayList();
+ termVectorTable.setItems(termVectorList);
+
+ close.setOnAction(e -> closeWindow(close));
+ }
+
+ public void setTermVector(String fieldName, List<TermVectorEntry> tvEntries) {
+ field.setText(fieldName);
+ termVectorList.clear();
+ termVectorList.addAll(tvEntries.stream().map(TermVector::of).collect(Collectors.toList()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/menubar/AboutController.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/menubar/AboutController.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/menubar/AboutController.java
new file mode 100644
index 0000000..0e51f8a
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/menubar/AboutController.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dialog.menubar;
+
+import javafx.fxml.FXML;
+import javafx.scene.control.Button;
+import org.apache.lucene.luke.app.controllers.dialog.DialogWindowController;
+
+public class AboutController implements DialogWindowController {
+
+ @FXML
+ private Button close;
+
+ @FXML
+ private void initialize() {
+ close.setOnAction(e -> closeWindow(close));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/menubar/CheckIndexController.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/menubar/CheckIndexController.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/menubar/CheckIndexController.java
new file mode 100644
index 0000000..47254d7
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/menubar/CheckIndexController.java
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dialog.menubar;
+
+import javafx.application.Platform;
+import javafx.concurrent.Task;
+import javafx.fxml.FXML;
+import javafx.scene.control.Button;
+import javafx.scene.control.Label;
+import javafx.scene.control.TextArea;
+import javafx.scene.layout.Pane;
+import org.apache.lucene.index.CheckIndex;
+import org.apache.lucene.luke.app.DirectoryHandler;
+import org.apache.lucene.luke.app.IndexHandler;
+import org.apache.lucene.luke.app.LukeState;
+import org.apache.lucene.luke.app.controllers.dialog.DialogWindowController;
+import org.apache.lucene.luke.app.util.IndexTask;
+import org.apache.lucene.luke.app.util.TextAreaPrintStream;
+import org.apache.lucene.luke.models.LukeException;
+import org.apache.lucene.luke.models.tools.IndexTools;
+import org.apache.lucene.luke.models.tools.IndexToolsFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nullable;
+import javax.inject.Inject;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import static org.apache.lucene.luke.app.util.ExceptionHandler.runnableWrapper;
+
+public class CheckIndexController implements DialogWindowController {
+
+ private static Logger logger = LoggerFactory.getLogger(CheckIndexController.class);
+
+ private final IndexHandler indexHandler;
+
+ private IndexTools toolsModel;
+
+ private LukeState state;
+
+ @FXML
+ private Label dirPath;
+
+ @FXML
+ private Label results;
+
+ @FXML
+ private Button check;
+
+ @FXML
+ private Button repair;
+
+ @FXML
+ private Label repairWarn;
+
+ @FXML
+ private Button close;
+
+ @FXML
+ private Label status;
+
+ @FXML
+ private Pane indicatorPane;
+
+ @FXML
+ private TextArea info;
+
+ private PrintStream ps;
+
+ private CheckIndex.Status st;
+
+ @Inject
+ public CheckIndexController(IndexToolsFactory toolsModelFactory, DirectoryHandler directoryHandler, IndexHandler indexHandler) {
+ this.indexHandler = indexHandler;
+
+ if (directoryHandler.directoryOpened()) {
+ this.state = directoryHandler.getState();
+ this.toolsModel = toolsModelFactory.newInstance(state.getDirectory());
+ } else if (indexHandler.indexOpened()) {
+ this.state = indexHandler.getState();
+ this.toolsModel = toolsModelFactory.newInstance(state.getIndexReader(), state.useCompound(), state.keepAllCommits());
+ } else {
+ throw new LukeException("Directory or IndexReader is not opened");
+ }
+ }
+
+ @FXML
+ private void initialize() {
+ dirPath.setText(state.getIndexPath());
+
+ ps = new TextAreaPrintStream(info, new ByteArrayOutputStream(), logger);
+
+ check.setOnAction(e -> checkIndex());
+ repair.setOnAction(e -> repairIndex());
+ repair.setDisable(true);
+ repairWarn.setDisable(true);
+ close.setOnAction(e -> closeWindow(close));
+ }
+
+ private void checkIndex() {
+ ExecutorService executor = Executors.newSingleThreadExecutor();
+
+ Task<CheckIndex.Status> task = new IndexTask<CheckIndex.Status>(indicatorPane) {
+ @Override
+ protected CheckIndex.Status call() throws Exception {
+ try {
+ return toolsModel.checkIndex(ps);
+ } catch (Exception e) {
+ Platform.runLater(() -> logger.error(e.getMessage(), e));
+ throw e;
+ } finally {
+ ps.flush();
+ }
+ }
+ };
+
+ task.setOnSucceeded(e -> {
+ CheckIndex.Status st = task.getValue();
+ this.st = st;
+ results.setText(createResultsMessage(st));
+ if (!st.clean) {
+ repair.setDisable(false);
+ repairWarn.setDisable(false);
+ }
+ });
+ status.textProperty().bind(task.messageProperty());
+
+ executor.submit(task);
+ executor.shutdown();
+ }
+
+ private String createResultsMessage(@Nullable CheckIndex.Status status) {
+ String msg;
+ if (status == null) {
+ msg = "?";
+ } else if (status.clean) {
+ msg = "OK";
+ } else if (status.toolOutOfDate) {
+ msg = "ERROR: Can't check - tool out-of-date";
+ } else {
+ StringBuilder sb = new StringBuilder("BAD:");
+ if (status.cantOpenSegments) {
+ sb.append(" Can't open segmengs.");
+ }
+ if (status.missingSegments) {
+ sb.append(" Missing segments.");
+ }
+ if (status.missingSegmentVersion) {
+ sb.append(" Missing segment version.");
+ }
+ if (status.numBadSegments > 0) {
+ sb.append(" numBadSegments=");
+ sb.append(status.numBadSegments);
+ }
+ if (status.totLoseDocCount > 0) {
+ sb.append(" totLoseDocCount=");
+ sb.append(status.totLoseDocCount);
+ }
+ msg = sb.toString();
+ }
+ return msg;
+ }
+
+ private void repairIndex() {
+ ExecutorService executor = Executors.newSingleThreadExecutor();
+
+ Task task = new IndexTask<Void>(indicatorPane) {
+ @Override
+ protected Void call() {
+ try {
+ toolsModel.repairIndex(st, ps);
+ } catch (Exception e) {
+ Platform.runLater(() -> logger.error(e.getMessage(), e));
+ throw e;
+ } finally {
+ ps.flush();
+ }
+ return null;
+ }
+ };
+
+ task.setOnSucceeded(e -> runnableWrapper(() -> {
+ indexHandler.open(state.getIndexPath(), state.getDirImpl());
+ results.setText("?");
+ repair.setDisable(true);
+ repairWarn.setDisable(true);
+ }));
+ status.textProperty().bind(task.messageProperty());
+
+ executor.submit(task);
+ executor.shutdown();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/menubar/OpenIndexController.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/menubar/OpenIndexController.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/menubar/OpenIndexController.java
new file mode 100644
index 0000000..4263eed
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/menubar/OpenIndexController.java
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dialog.menubar;
+
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import javafx.fxml.FXML;
+import javafx.scene.control.Button;
+import javafx.scene.control.CheckBox;
+import javafx.scene.control.ChoiceBox;
+import javafx.scene.control.RadioButton;
+import javafx.scene.control.ToggleGroup;
+import javafx.stage.DirectoryChooser;
+import javafx.stage.Stage;
+import javafx.stage.Window;
+import org.apache.lucene.luke.app.DirectoryHandler;
+import org.apache.lucene.luke.app.IndexHandler;
+import org.apache.lucene.luke.app.controllers.LukeController;
+import org.apache.lucene.luke.app.controllers.dialog.DialogWindowController;
+import org.apache.lucene.luke.app.controllers.dialog.WarnController;
+import org.apache.lucene.luke.app.desktop.Preferences;
+import org.apache.lucene.luke.app.util.DialogOpener;
+import org.apache.lucene.luke.app.util.MessageUtils;
+import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.MMapDirectory;
+import org.apache.lucene.store.NativeUnixDirectory;
+import org.reflections.Reflections;
+import org.reflections.scanners.SubTypesScanner;
+import org.reflections.util.ClasspathHelper;
+import org.reflections.util.ConfigurationBuilder;
+import org.reflections.util.FilterBuilder;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.apache.lucene.luke.app.util.ExceptionHandler.runnableWrapper;
+
+public class OpenIndexController implements DialogWindowController {
+
+ private final Preferences prefs;
+
+ private final DirectoryHandler directoryHandler;
+
+ private final IndexHandler indexHandler;
+
+ private LukeController mainController;
+
+ @FXML
+ private ChoiceBox<String> indexPath;
+
+ private ObservableList<String> indexHistory;
+
+ @FXML
+ private Button browse;
+
+ @FXML
+ private CheckBox readOnly;
+
+ @FXML
+ private ChoiceBox<String> dirImpl;
+
+ private ObservableList<String> dirImplList;
+
+ @FXML
+ private CheckBox noReader;
+
+ @FXML
+ private CheckBox useCompound;
+
+ @FXML
+ private ToggleGroup keepCommitsGroup;
+
+ @FXML
+ private RadioButton keepLastCommit;
+
+ @FXML
+ private RadioButton keepAllCommits;
+
+ @FXML
+ private Button ok;
+
+ @FXML
+ private Button cancel;
+
+
+ @Inject
+ public OpenIndexController(Preferences prefs, DirectoryHandler directoryHandler, IndexHandler indexHandler) {
+ this.prefs = prefs;
+ this.directoryHandler = directoryHandler;
+ this.indexHandler = indexHandler;
+ }
+
+ @FXML
+ private void initialize() {
+
+ readOnly.setSelected(prefs.isReadOnly());
+ dirImpl.setValue(prefs.getDirImpl());
+ noReader.setSelected(prefs.isNoReader());
+ useCompound.setSelected(prefs.isUseCompound());
+ keepAllCommits.setSelected(prefs.isKeepAllCommits());
+ keepLastCommit.setSelected(!prefs.isKeepAllCommits());
+ indexHistory = FXCollections.observableArrayList();
+ indexPath.setItems(indexHistory);
+
+ setHistory(prefs.getHistory());
+ browse.setOnAction(e -> showBrowseDialog());
+
+ // load Directory sub types
+ Reflections reflections = new Reflections(new ConfigurationBuilder()
+ .setUrls(ClasspathHelper.forPackage("org.apache.lucene.store"))
+ .setScanners(new SubTypesScanner())
+ .filterInputsBy(new FilterBuilder().include("org\\.apache\\.lucene\\.store.*"))
+ );
+ Set<Class<? extends FSDirectory>> clazzSet = reflections.getSubTypesOf(FSDirectory.class);
+ dirImplList = FXCollections.observableArrayList();
+ dirImplList.add(FSDirectory.class.getName());
+ dirImplList.add(MMapDirectory.class.getName());
+ dirImplList.addAll(clazzSet.stream().map(Class::getCanonicalName).collect(Collectors.toList()));
+ dirImplList.remove(NativeUnixDirectory.class.getName());
+ dirImpl.setItems(dirImplList);
+
+ readOnly.setOnAction(e -> setWriterConfigsDisable(readOnly.isSelected()));
+
+ ok.setOnAction(e -> runnableWrapper(this::openIndex));
+ cancel.setOnAction(e -> closeWindow(cancel));
+ }
+
+ private void setWriterConfigsDisable(boolean value) {
+ useCompound.setDisable(value);
+ keepLastCommit.setDisable(value);
+ keepAllCommits.setDisable(value);
+ }
+
+ private void showBrowseDialog() {
+ DirectoryChooser directoryChooser = new DirectoryChooser();
+ File homeDir = new File(System.getProperty("user.home"));
+ directoryChooser.setInitialDirectory(homeDir);
+ Window window = browse.getScene().getWindow();
+ File file = directoryChooser.showDialog(window);
+ if (file != null) {
+ indexHistory.add(file.getAbsolutePath());
+ indexPath.setValue(file.getAbsolutePath());
+ }
+ }
+
+ private void openIndex() throws Exception {
+ String selectedPath = indexPath.getValue();
+ String dirImplClazz = dirImpl.getValue();
+ if (selectedPath == null || selectedPath.length() == 0) {
+ String msg = MessageUtils.getLocalizedMessage("openindex.message.index_path_not_selected");
+ showInvalidIndexSelectedDialog(msg);
+ return;
+ }
+ if (noReader.isSelected()) {
+ directoryHandler.open(selectedPath, dirImplClazz);
+ } else {
+ indexHandler.open(selectedPath, dirImplClazz, readOnly.isSelected(), useCompound.isSelected(),
+ keepCommitsGroup.getSelectedToggle().getUserData().equals("all"));
+ }
+ addHistory(selectedPath);
+ prefs.setIndexOpenerPrefs(readOnly.isSelected(), dirImpl.getValue(), noReader.isSelected(), useCompound.isSelected(), keepAllCommits.isSelected());
+ closeWindow(ok);
+ }
+
+ private Stage warnDialog;
+
+ private void showInvalidIndexSelectedDialog(String message) throws Exception {
+ warnDialog = new DialogOpener<WarnController>(mainController).show(
+ warnDialog,
+ "Invalid index path",
+ "/fxml/dialog/warn.fxml",
+ 400, 200,
+ (controller) -> controller.setContent(message)
+ );
+ }
+
+ public void setMainController(LukeController mainController) {
+ this.mainController = mainController;
+ }
+
+ private void setHistory(List<String> history) {
+ this.indexHistory.setAll(history);
+ if (indexHistory.size() > 0) {
+ indexPath.setValue(indexHistory.get(0));
+ }
+ }
+
+ private void addHistory(String indexPath) throws IOException {
+ prefs.addHistory(indexPath);
+ setHistory(prefs.getHistory());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/menubar/OptimizeController.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/menubar/OptimizeController.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/menubar/OptimizeController.java
new file mode 100644
index 0000000..fdd51d0
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/menubar/OptimizeController.java
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dialog.menubar;
+
+import javafx.application.Platform;
+import javafx.concurrent.Task;
+import javafx.fxml.FXML;
+import javafx.scene.control.Button;
+import javafx.scene.control.CheckBox;
+import javafx.scene.control.Label;
+import javafx.scene.control.Spinner;
+import javafx.scene.control.SpinnerValueFactory;
+import javafx.scene.control.TextArea;
+import javafx.scene.control.TextFormatter;
+import javafx.scene.layout.Pane;
+import org.apache.lucene.luke.app.IndexHandler;
+import org.apache.lucene.luke.app.LukeState;
+import org.apache.lucene.luke.app.controllers.dialog.DialogWindowController;
+import org.apache.lucene.luke.app.util.IndexTask;
+import org.apache.lucene.luke.app.util.IntegerTextFormatter;
+import org.apache.lucene.luke.app.util.TextAreaPrintStream;
+import org.apache.lucene.luke.models.tools.IndexTools;
+import org.apache.lucene.luke.models.tools.IndexToolsFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import static org.apache.lucene.luke.app.util.ExceptionHandler.runnableWrapper;
+
+public class OptimizeController implements DialogWindowController {
+
+ private static final Logger logger = LoggerFactory.getLogger(OptimizeController.class);
+
+ private final IndexToolsFactory toolsFactory;
+
+ private final IndexHandler indexHandler;
+
+ private IndexTools toolsModel;
+
+ @FXML
+ private Label dirPath;
+
+ @FXML
+ private CheckBox expunge;
+
+ @FXML
+ private Spinner<Integer> numSegments;
+
+ @FXML
+ private Button optimize;
+
+ @FXML
+ private Button close;
+
+ @FXML
+ private Label status;
+
+ @FXML
+ private Pane indicatorPane;
+
+ @FXML
+ private TextArea info;
+
+ private PrintStream ps;
+
+ @Inject
+ public OptimizeController(IndexToolsFactory toolsFactory, IndexHandler indexHandler) {
+ this.toolsFactory = toolsFactory;
+ this.indexHandler = indexHandler;
+ initIndexTools(indexHandler.getState());
+ }
+
+ @FXML
+ private void initialize() {
+ dirPath.setText(indexHandler.getState().getIndexPath());
+
+ SpinnerValueFactory.IntegerSpinnerValueFactory valueFactory =
+ new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 50, 1, -1);
+ numSegments.setValueFactory(valueFactory);
+ TextFormatter<Integer> textFormatter = new IntegerTextFormatter(valueFactory.getConverter(), 1);
+ valueFactory.valueProperty().bindBidirectional(textFormatter.valueProperty());
+ numSegments.getEditor().setTextFormatter(textFormatter);
+ numSegments.focusedProperty().addListener((obs, oldV, newV) -> {
+ if (newV) {
+ // won't not change value, but commit editor
+ // https://stackoverflow.com/questions/32340476/manually-typing-in-text-in-javafx-spinner-is-not-updating-the-value-unless-user
+ numSegments.increment(0);
+ }
+ });
+
+ ps = new TextAreaPrintStream(info, new ByteArrayOutputStream(), logger);
+
+ optimize.setOnAction(e -> optimize());
+ close.setOnAction(e -> closeWindow(close));
+ }
+
+ private void optimize() {
+ ExecutorService executor = Executors.newSingleThreadExecutor();
+
+ Task task = new IndexTask<Void>(indicatorPane) {
+
+ @Override
+ protected Void call() {
+ try {
+ toolsModel.optimize(expunge.isSelected(), numSegments.getValue(), ps);
+ } catch (Exception e) {
+ Platform.runLater(() -> logger.error(e.getMessage(), e));
+ throw e;
+ } finally {
+ ps.flush();
+ }
+ return null;
+ }
+ };
+
+ task.setOnSucceeded(e -> runnableWrapper(() -> {
+ indexHandler.reOpen();
+ initIndexTools(indexHandler.getState());
+ }));
+ status.textProperty().bind(task.messageProperty());
+
+ executor.submit(task);
+ executor.shutdown();
+ }
+
+ private void initIndexTools(LukeState state) {
+ this.toolsModel = toolsFactory.newInstance(state.getIndexReader(), state.useCompound(), state.keepAllCommits());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/search/ExplanationController.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/search/ExplanationController.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/search/ExplanationController.java
new file mode 100644
index 0000000..d5d465a
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dialog/search/ExplanationController.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dialog.search;
+
+import javafx.fxml.FXML;
+import javafx.scene.control.Button;
+import javafx.scene.control.Label;
+import javafx.scene.control.TreeItem;
+import javafx.scene.control.TreeView;
+import javafx.scene.input.Clipboard;
+import javafx.scene.input.ClipboardContent;
+import org.apache.lucene.luke.app.controllers.dialog.DialogWindowController;
+import org.apache.lucene.search.Explanation;
+
+import javax.annotation.Nonnull;
+import java.util.List;
+import java.util.stream.IntStream;
+
+public class ExplanationController implements DialogWindowController {
+
+ @FXML
+ private Label docNum;
+
+ @FXML
+ private TreeView<String> tree;
+
+ @FXML
+ private Button copy;
+
+ @FXML
+ private Button close;
+
+ @FXML
+ private void initialize() {
+ copy.setOnAction(e -> copyToClipboard());
+ close.setOnAction(e -> closeWindow(close));
+ }
+
+ public void setDocNum(int docId) {
+ docNum.setText(String.valueOf(docId));
+ }
+
+ public void setExplanation(@Nonnull Explanation explanation) {
+ TreeItem<String> root = createItem(explanation);
+ traverse(root, explanation.getDetails());
+ tree.setRoot(root);
+ }
+
+ private void traverse(TreeItem<String> parent, Explanation[] explanations) {
+ parent.setExpanded(true);
+ for (Explanation explanation : explanations) {
+ TreeItem<String> item = createItem(explanation);
+ parent.getChildren().add(item);
+ traverse(item, explanation.getDetails());
+ }
+ }
+
+ private TreeItem<String> createItem(Explanation explanation) {
+ return new TreeItem<>(String.format("%f %s", explanation.getValue(), explanation.getDescription()));
+ }
+
+ private void copyToClipboard() {
+ Clipboard clipboard = Clipboard.getSystemClipboard();
+ ClipboardContent content = new ClipboardContent();
+ content.putString(treeToString());
+ clipboard.setContent(content);
+ }
+
+ private String treeToString() {
+ TreeItem<String> root = tree.getRoot();
+ StringBuilder sb = new StringBuilder(root.getValue());
+ sb.append("\n");
+ traverseToCopy(sb, 1, root.getChildren());
+ return sb.toString();
+ }
+
+ private void traverseToCopy(StringBuilder sb, int depth, List<TreeItem<String>> items) {
+ for (TreeItem<String> item : items) {
+ IntStream.range(0, depth).forEach(i -> sb.append(" "));
+ sb.append(item.getValue());
+ sb.append("\n");
+ traverseToCopy(sb, depth + 1, item.getChildren());
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/analysis/FilterFactory.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/analysis/FilterFactory.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/analysis/FilterFactory.java
new file mode 100644
index 0000000..437d66d
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/analysis/FilterFactory.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dto.analysis;
+
+import javafx.beans.property.BooleanProperty;
+import javafx.beans.property.SimpleBooleanProperty;
+
+public class FilterFactory {
+ private BooleanProperty deleted = new SimpleBooleanProperty(false);
+ private int order;
+ private String factory;
+
+ public static FilterFactory of(int order, String factory) {
+ FilterFactory ff = new FilterFactory();
+ ff.order = order;
+ ff.factory = factory;
+ return ff;
+ }
+
+ private FilterFactory() {
+ }
+
+ public Boolean isDeleted() {
+ return deleted.get();
+ }
+
+ public void setDeleted(boolean val) {
+ deleted.set(val);
+ }
+
+ public BooleanProperty getDeletedProperty() {
+ return deleted;
+ }
+
+ public int getOrder() {
+ return order;
+ }
+
+ public String getFactory() {
+ return factory;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/analysis/Param.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/analysis/Param.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/analysis/Param.java
new file mode 100644
index 0000000..63a4778
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/analysis/Param.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dto.analysis;
+
+import javafx.beans.property.BooleanProperty;
+import javafx.beans.property.SimpleBooleanProperty;
+
+public class Param {
+ private BooleanProperty deleted = new SimpleBooleanProperty(false);
+ private String name = "";
+ private String value = "";
+
+ public static Param newInstance() {
+ return new Param();
+ }
+
+ public static Param of(String name, String value) {
+ Param param = new Param();
+ param.name = name;
+ param.value = value;
+ return param;
+ }
+
+ private Param() {
+ }
+
+ public Boolean isDeleted() {
+ return deleted.get();
+ }
+
+ public void setDeleted(boolean val) {
+ deleted.set(val);
+ }
+
+ public BooleanProperty getDeletedProperty() {
+ return deleted;
+ }
+
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public boolean isValid() {
+ return name != null && name.length() > 0;
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/analysis/Token.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/analysis/Token.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/analysis/Token.java
new file mode 100644
index 0000000..14bd237
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/analysis/Token.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dto.analysis;
+
+import org.apache.lucene.luke.models.analysis.Analysis;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class Token {
+ private String term;
+ private String attributes;
+ private Analysis.Token originalToken;
+
+ public static Token of(Analysis.Token token) {
+ Token t = new Token();
+ t.term = token.getTerm();
+ t.originalToken = token;
+ List<String> attValues = token.getAttributes().stream()
+ .flatMap(att -> att.getAttValues().entrySet().stream()
+ .map(e -> e.getKey() + "=" + e.getValue()))
+ .collect(Collectors.toList());
+ t.attributes = String.join(",", attValues);
+ return t;
+ }
+
+ private Token() {
+ }
+
+ public String getTerm() {
+ return term;
+ }
+
+ public String getAttributes() {
+ return attributes;
+ }
+
+ public Analysis.Token getOriginalToken() {
+ return originalToken;
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/analysis/TokenAttValue.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/analysis/TokenAttValue.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/analysis/TokenAttValue.java
new file mode 100644
index 0000000..b5942bf
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/analysis/TokenAttValue.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dto.analysis;
+
+public class TokenAttValue {
+ private String attClass;
+ private String name;
+ private String value;
+
+ public static TokenAttValue of(String attClass, String name, String value) {
+ TokenAttValue attValue = new TokenAttValue();
+ attValue.attClass = attClass;
+ attValue.name = name;
+ attValue.value = value;
+ return attValue;
+ }
+
+ private TokenAttValue() {
+ }
+
+ public String getAttClass() {
+ return attClass;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/commits/File.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/commits/File.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/commits/File.java
new file mode 100644
index 0000000..5a0b150
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/commits/File.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dto.commits;
+
+public class File {
+ private String name;
+ private String size;
+
+ public static File of(org.apache.lucene.luke.models.commits.File f) {
+ File file = new File();
+ file.name = f.getFileName();
+ file.size = f.getDisplaySize();
+ return file;
+ }
+
+ private File() {
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getSize() {
+ return size;
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/commits/Segment.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/commits/Segment.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/commits/Segment.java
new file mode 100644
index 0000000..130c9de
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/commits/Segment.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dto.commits;
+
+public class Segment {
+ private String name;
+ private int maxDoc;
+ private long delGen;
+ private int delCount;
+ private String luceneVer;
+ private String codecName;
+ private String size;
+ private boolean useCompoundFile;
+
+ public static Segment of(org.apache.lucene.luke.models.commits.Segment seg) {
+ Segment segment = new Segment();
+ segment.name = seg.getName();
+ segment.maxDoc = seg.getMaxDoc();
+ segment.delGen = seg.getDelGen();
+ segment.delCount = seg.getDelCount();
+ segment.luceneVer = seg.getLuceneVer();
+ segment.size = seg.getDisplaySize();
+ segment.useCompoundFile = seg.isUseCompoundFile();
+ return segment;
+ }
+
+ private Segment() {
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getMaxDoc() {
+ return maxDoc;
+ }
+
+ public long getDelGen() {
+ return delGen;
+ }
+
+ public int getDelCount() {
+ return delCount;
+ }
+
+ public String getLuceneVer() {
+ return luceneVer;
+ }
+
+ public String getCodecName() {
+ return codecName;
+ }
+
+ public String getSize() {
+ return size;
+ }
+
+ public boolean isUseCompoundFile() {
+ return useCompoundFile;
+ }
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/documents/DocumentField.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/documents/DocumentField.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/documents/DocumentField.java
new file mode 100644
index 0000000..1ddb6bc
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/documents/DocumentField.java
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dto.documents;
+
+import org.apache.lucene.index.DocValuesType;
+import org.apache.lucene.index.IndexOptions;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+public class DocumentField {
+
+ private String field;
+ private String flag;
+ private Long norm;
+ private String value;
+
+ public static DocumentField of(org.apache.lucene.luke.models.documents.DocumentField f) {
+ DocumentField dField = new DocumentField();
+ dField.field = f.getName();
+ dField.flag = flags(f);
+ dField.norm = f.getNorm();
+ if (f.getStringValue() != null) {
+ dField.value = f.getStringValue();
+ } else if (f.getNumericValue() != null) {
+ dField.value = String.valueOf(f.getNumericValue());
+ } else if (f.getBinaryValue() != null) {
+ dField.value = String.valueOf(f.getBinaryValue());
+ }
+ return dField;
+ }
+
+ private DocumentField() {
+ }
+
+ public String getField() {
+ return field;
+ }
+
+ public String getFlag() {
+ return flag;
+ }
+
+ public Long getNorm() {
+ return norm;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ private static String flags(org.apache.lucene.luke.models.documents.DocumentField f) {
+ StringBuilder sb = new StringBuilder();
+ // index options
+ if (f.getIdxOptions() == null || f.getIdxOptions() == IndexOptions.NONE) {
+ sb.append("-----");
+ } else {
+ sb.append("I");
+ switch (f.getIdxOptions()) {
+ case DOCS:
+ sb.append("d---");
+ break;
+ case DOCS_AND_FREQS:
+ sb.append("df--");
+ break;
+ case DOCS_AND_FREQS_AND_POSITIONS:
+ sb.append("dfp-");
+ break;
+ case DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS:
+ sb.append("dfpo");
+ break;
+ default:
+ sb.append("----");
+ }
+ }
+ // has norm?
+ if (f.hasNorms()) {
+ sb.append("N");
+ } else {
+ sb.append("-");
+ }
+ // has payloads?
+ if (f.hasPayloads()) {
+ sb.append("P");
+ } else {
+ sb.append("-");
+ }
+ // stored?
+ if (f.isStored()) {
+ sb.append("S");
+ } else {
+ sb.append("-");
+ }
+ // binary?
+ if (f.getBinaryValue() != null) {
+ sb.append("B");
+ } else {
+ sb.append("-");
+ }
+ // numeric?
+ if (f.getNumericValue() == null) {
+ sb.append("----");
+ } else {
+ sb.append("#");
+ // try faking it
+ Number numeric = f.getNumericValue();
+ if (numeric instanceof Integer) {
+ sb.append("i32");
+ } else if (numeric instanceof Long) {
+ sb.append("i64");
+ } else if (numeric instanceof Float) {
+ sb.append("f32");
+ } else if (numeric instanceof Double) {
+ sb.append("f64");
+ } else if (numeric instanceof Short) {
+ sb.append("i16");
+ } else if (numeric instanceof Byte) {
+ sb.append("i08");
+ } else if (numeric instanceof BigDecimal) {
+ sb.append("b^d");
+ } else if (numeric instanceof BigInteger) {
+ sb.append("b^i");
+ } else {
+ sb.append("???");
+ }
+ }
+ // has term vector?
+ if (f.hasTermVectors()) {
+ sb.append("V");
+ } else {
+ sb.append("-");
+ }
+ // doc values
+ if (f.getDvType() == null || f.getDvType() == DocValuesType.NONE) {
+ sb.append("-------");
+ } else {
+ sb.append("D");
+ switch (f.getDvType()) {
+ case NUMERIC:
+ sb.append("number");
+ break;
+ case BINARY:
+ sb.append("binary");
+ break;
+ case SORTED:
+ sb.append("sorted");
+ break;
+ case SORTED_NUMERIC:
+ sb.append("srtnum");
+ break;
+ case SORTED_SET:
+ sb.append("srtset");
+ break;
+ default:
+ sb.append("??????");
+ }
+ }
+ // point values
+ if (f.getPointDimensionCount() == 0) {
+ sb.append("----");
+ } else {
+ sb.append("T");
+ sb.append(f.getPointNumBytes());
+ sb.append("/");
+ sb.append(f.getPointDimensionCount());
+ }
+ return sb.toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/documents/NewField.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/documents/NewField.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/documents/NewField.java
new file mode 100644
index 0000000..dd401e8
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/documents/NewField.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dto.documents;
+
+import javafx.beans.property.BooleanProperty;
+import javafx.beans.property.ObjectProperty;
+import javafx.beans.property.SimpleBooleanProperty;
+import javafx.beans.property.SimpleObjectProperty;
+import javafx.scene.control.Hyperlink;
+import org.apache.lucene.document.DoublePoint;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.FieldType;
+import org.apache.lucene.document.FloatPoint;
+import org.apache.lucene.document.IntPoint;
+import org.apache.lucene.document.LongPoint;
+import org.apache.lucene.document.NumericDocValuesField;
+import org.apache.lucene.document.SortedDocValuesField;
+import org.apache.lucene.document.SortedNumericDocValuesField;
+import org.apache.lucene.document.SortedSetDocValuesField;
+import org.apache.lucene.document.StoredField;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.document.TextField;
+import org.apache.lucene.index.IndexableFieldType;
+import org.apache.lucene.luke.app.util.NumericUtils;
+
+public class NewField {
+
+ private BooleanProperty deletedProperty;
+
+ private String name;
+
+ private ObjectProperty<Class> typeProperty;
+
+ private Hyperlink option;
+
+ private String value;
+
+ private IndexableFieldType fieldType;
+
+ private boolean stored;
+
+ public static NewField newInstance() {
+ NewField f = new NewField();
+ f.deletedProperty = new SimpleBooleanProperty(false);
+ f.name = "";
+ f.typeProperty = new SimpleObjectProperty<>(TextField.class);
+ f.option = new Hyperlink("option");
+ f.value = "";
+ f.fieldType = new TextField("", "", Field.Store.NO).fieldType();
+ f.stored = f.fieldType.stored();
+ return f;
+ }
+
+ private NewField() {
+ }
+
+ public boolean isDeleted() {
+ return deletedProperty.get();
+ }
+
+ public BooleanProperty deletedProperty() {
+ return deletedProperty;
+ }
+
+ public void setDeleted(boolean value) {
+ this.deletedProperty.set(value);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public ObjectProperty<Class> getTypeProperty() {
+ return typeProperty;
+ }
+
+ public Class getType() {
+ return typeProperty.get();
+ }
+
+ public void setType(Class type) {
+ this.typeProperty.set(type);
+ }
+
+ public Hyperlink getOption() {
+ return option;
+ }
+
+ public void resetFieldType(Class type) {
+ if (type.equals(TextField.class)) {
+ fieldType = new TextField("", "", Field.Store.NO).fieldType();
+ } else if (type.equals(StringField.class)) {
+ fieldType = new StringField("", "", Field.Store.NO).fieldType();
+ } else if (type.equals(IntPoint.class)) {
+ fieldType = new IntPoint("", NumericUtils.convertToIntArray(value, true)).fieldType();
+ } else if (type.equals(LongPoint.class)) {
+ fieldType = new LongPoint("", NumericUtils.convertToLongArray(value, true)).fieldType();
+ } else if (type.equals(FloatPoint.class)) {
+ fieldType = new FloatPoint("", NumericUtils.convertToFloatArray(value, true)).fieldType();
+ } else if (type.equals(DoublePoint.class)) {
+ fieldType = new DoublePoint("", NumericUtils.convertToDoubleArray(value, true)).fieldType();
+ } else if (type.equals(SortedDocValuesField.class)) {
+ fieldType = new SortedDocValuesField("", null).fieldType();
+ } else if (type.equals(SortedSetDocValuesField.class)) {
+ fieldType = new SortedSetDocValuesField("", null).fieldType();
+ } else if (type.equals(NumericDocValuesField.class)) {
+ fieldType = new NumericDocValuesField("", 0).fieldType();
+ } else if (type.equals(SortedNumericDocValuesField.class)) {
+ fieldType = new SortedNumericDocValuesField("", 0).fieldType();
+ } else if (type.equals(StoredField.class)) {
+ fieldType = new StoredField("", "").fieldType();
+ } else if (type.equals(Field.class)) {
+ fieldType = new FieldType(this.fieldType);
+ }
+ }
+
+ public IndexableFieldType getFieldType() {
+ return fieldType;
+ }
+
+ public boolean isStored() {
+ return stored;
+ }
+
+ public void setStored(boolean stored) {
+ this.stored = stored;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/dc72c4a0/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/documents/TermPosting.java
----------------------------------------------------------------------
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/documents/TermPosting.java b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/documents/TermPosting.java
new file mode 100644
index 0000000..424e4b6
--- /dev/null
+++ b/lucene/luke/src/java/org/apache/lucene/luke/app/controllers/dto/documents/TermPosting.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.luke.app.controllers.dto.documents;
+
+import org.apache.lucene.luke.util.BytesRefUtils;
+
+public class TermPosting {
+
+ private int position = -1;
+ private String offset = "";
+ private String payload = "";
+
+ public static TermPosting of(org.apache.lucene.luke.models.documents.TermPosting p) {
+ TermPosting posting = new TermPosting();
+ posting.position = p.getPosition();
+ if (p.getStartOffset() >= 0 && p.getEndOffset() >= 0) {
+ posting.offset = String.format("%d-%d", p.getStartOffset(), p.getEndOffset());
+ }
+ if (p.getPayload() != null) {
+ posting.payload = BytesRefUtils.decode(p.getPayload());
+ }
+ return posting;
+ }
+
+ private TermPosting() {
+ }
+
+ public int getPosition() {
+ return position;
+ }
+
+ public String getOffset() {
+ return offset;
+ }
+
+ public String getPayload() {
+ return payload;
+ }
+}