List of usage examples for org.apache.solr.common.luke FieldFlag MULTI_VALUED
FieldFlag MULTI_VALUED
To view the source code for org.apache.solr.common.luke FieldFlag MULTI_VALUED.
Click Source Link
From source file:com.github.fengtan.sophie.beans.SolrUtils.java
License:Open Source License
/** * Whether Solr can sort a field./*w w w .ja v a 2 s .c o m*/ * * @param field * Field. * @return True if Solr can sort the field, false otherwise. */ public static boolean isFieldSortable(FieldInfo field) { // A field is sortable if // 1) it is indexed // 2) it is not multivalued // 3) it does not have docValues EnumSet<FieldFlag> flags = SolrUtils.getFlags(field); return (flags.contains(FieldFlag.INDEXED) && !flags.contains(FieldFlag.DOC_VALUES) && !flags.contains(FieldFlag.MULTI_VALUED)); }
From source file:com.github.fengtan.sophie.tables.DocumentsTable.java
License:Open Source License
/** * Create the Table./*from w w w . ja v a 2s. c o m*/ */ private void createTable() { // Instantiate the table. int style = SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION | SWT.VIRTUAL; table = new Table(composite, style); // Set layout. GridData gridData = new GridData(GridData.FILL_BOTH); gridData.grabExcessVerticalSpace = true; table.setLayoutData(gridData); // Set styles. table.setLinesVisible(true); table.setHeaderVisible(true); // Add KeyListener to delete documents. table.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent event) { if (event.keyCode == SWT.DEL) { deleteSelectedDocument(); } } }); // Initialize item count to 1 so we can populate the first row with // filters. table.setItemCount(1); // Populate subsequent rows with remote documents (virtual table). table.addListener(SWT.SetData, new Listener() { @Override public void handleEvent(Event event) { TableItem item = (TableItem) event.item; int rowIndex = table.indexOf(item); // The first line is populated by filters. if (rowIndex == 0) { return; } SolrDocument document; // The last lines are populated by local additions. if (rowIndex >= table.getItemCount() - documentsAdded.size()) { document = documentsAdded.get(documentsAdded.size() - table.getItemCount() + rowIndex); item.setBackground(GREEN); } else { try { // rowIndex - 1 since the first line is used for // filters. document = getRemoteDocument(rowIndex - 1); } catch (SophieException e) { ExceptionDialog.open(composite.getShell(), new SophieException("Unable to populate table", e)); return; } } // First column is used to show the row ID. item.setText(0, Integer.toString(rowIndex)); // Subsequent columns are used to show field values. for (int index = 1; index < table.getColumnCount(); index++) { TableColumn column = table.getColumn(index); String fieldName = (String) column.getData("fieldName"); FieldInfo field = (FieldInfo) column.getData("field"); // If field is not stored, display message. if (!SolrUtils.getFlags(field).contains(FieldFlag.STORED)) { item.setText(index, LABEL_NOT_STORED); } else { Object value = document.getFieldValue(fieldName); item.setText(index, value == null ? StringUtils.EMPTY : value.toString()); } } // Store document in item. item.setData("document", document); } }); // Add doubleclick listener to edit values. table.addListener(SWT.MouseDoubleClick, new Listener() { public void handleEvent(Event event) { Point point = new Point(event.x, event.y); TableItem item = table.getItem(point); if (item == null) { return; } // The first row is used for filters. if (table.indexOf(item) == 0) { return; } // We add 1 since the first column is used for row ID's. for (int i = 1; i < table.getColumnCount(); i++) { Rectangle rect = item.getBounds(i); if (rect.contains(point)) { SolrDocument document = (SolrDocument) item.getData("document"); String fieldName = (String) table.getColumn(i).getData("fieldName"); FieldInfo field = (FieldInfo) table.getColumn(i).getData("field"); Object defaultValue = document.getFieldValue(fieldName); // Add editor dialog: // - list widget if we are dealing with a multi-valued // field. // - datepicker if we field type contains "date". // - text if we are dealing with any other field type. EditValueDialog dialog; if (SolrUtils.getFlags(field).contains(FieldFlag.MULTI_VALUED)) { dialog = new EditListValueDialog(composite.getShell(), (AbstractList<?>) defaultValue); } else if (StringUtils.containsIgnoreCase(field.getType(), "date")) { dialog = new EditDateValueDialog(composite.getShell(), (Date) defaultValue); } else { String oldValueString = Objects.toString(defaultValue, StringUtils.EMPTY); dialog = new EditTextValueDialog(composite.getShell(), oldValueString); } dialog.open(); if (dialog.getReturnCode() != IDialogConstants.OK_ID) { return; } Object value = dialog.getValue(); if (!Objects.equals(defaultValue, value)) { updateDocument(item, i, value); } } } } }); }
From source file:org.dspace.util.SolrImportExport.java
License:BSD License
/** * Determine the names of all multi-valued fields from the data in the index. * @param solr the solr server to query. * @return A list containing all multi-valued fields, or an empty list if none are found / there aren't any. *///from w w w .j ava 2s . com private static List<String> getMultiValuedFields(HttpSolrServer solr) { List<String> result = new ArrayList<>(); try { LukeRequest request = new LukeRequest(); // this needs to be a non-schema request, otherwise we'll miss dynamic fields LukeResponse response = request.process(solr); Map<String, LukeResponse.FieldInfo> fields = response.getFieldInfo(); for (LukeResponse.FieldInfo info : fields.values()) { if (info.getSchema().contains(FieldFlag.MULTI_VALUED.getAbbreviation() + "")) { result.add(info.getName()); } } } catch (IOException | SolrServerException e) { log.fatal("Cannot determine which fields are multi valued: " + e.getMessage(), e); } return result; }
From source file:org.teiid.translator.solr.SolrMetadataProcessor.java
License:Open Source License
public void getConnectorMetadata(SolrConnection conn, MetadataFactory metadataFactory) throws TranslatorException { int count = 0; LukeRequest request = new LukeRequest(); request.setShowSchema(true);// w ww .j av a2 s . co m LukeResponse response = conn.metadata(request); Map<String, FieldInfo> fields = response.getFieldInfo(); Table table = metadataFactory.addTable(conn.getCoreName()); table.setSupportsUpdate(true); for (String name : fields.keySet()) { FieldInfo field = fields.get(name); EnumSet<FieldFlag> flags = field.getFlags(); if ((!name.startsWith("_") && !name.endsWith("_")) || name.startsWith("*") || name.endsWith("*")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ if (flags.contains(FieldFlag.INDEXED) && flags.contains(FieldFlag.STORED)) { Column column = null; // array type if (flags.contains(FieldFlag.MULTI_VALUED)) { column = metadataFactory.addColumn(field.getName(), resolveType(field.getType()) + "[]", //$NON-NLS-1$ table); } else { column = metadataFactory.addColumn(field.getName(), resolveType(field.getType()), table); } column.setUpdatable(true); column.setSearchType(SearchType.Searchable); // create primary key; and unique keys if (field.getDistinct() > 0 || field.getName().equals("id")) { //$NON-NLS-1$ if (table.getPrimaryKey() == null) { metadataFactory.addPrimaryKey("PK0", Arrays.asList(field.getName()), table); //$NON-NLS-1$ } else { metadataFactory.addIndex("UI" + count, true, Arrays.asList(field.getName()), table); //$NON-NLS-1$ count++; } } } } } }
From source file:org.teiid.translator.solr.TestSolrMetadataProcessor.java
License:Open Source License
@Test public void testMetadata() throws TranslatorException { SolrMetadataProcessor mp = new SolrMetadataProcessor(); MetadataFactory mf = new MetadataFactory("vdb", 1, "solr", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null); SolrConnection conn = Mockito.mock(SolrConnection.class); Mockito.stub(conn.getCoreName()).toReturn("SomeTable"); LinkedHashMap<String, FieldInfo> fields = new LinkedHashMap<String, LukeResponse.FieldInfo>(); fields.put("col1", buildField("col1", "string", EnumSet.of(FieldFlag.STORED, FieldFlag.INDEXED))); fields.put("col2", buildField("col2", "int", EnumSet.of(FieldFlag.STORED, FieldFlag.INDEXED))); fields.put("col3", buildField("col3", "int", EnumSet.of(FieldFlag.STORED, FieldFlag.INDEXED, FieldFlag.MULTI_VALUED))); fields.put("id", buildField("id", "long", EnumSet.of(FieldFlag.STORED, FieldFlag.INDEXED))); LukeResponse response = Mockito.mock(LukeResponse.class); ;//from w w w .j av a2s . c om Mockito.stub(response.getFieldInfo()).toReturn(fields); Mockito.stub(conn.metadata(Mockito.any(LukeRequest.class))).toReturn(response); mp.process(mf, conn); String metadataDDL = DDLStringVisitor.getDDLString(mf.getSchema(), null, null); String expected = "CREATE FOREIGN TABLE SomeTable (\n" + " col1 string OPTIONS (SEARCHABLE 'Searchable'),\n" + " col2 integer OPTIONS (SEARCHABLE 'Searchable'),\n" + " col3 integer[] OPTIONS (SEARCHABLE 'Searchable'),\n" + " id long OPTIONS (SEARCHABLE 'Searchable'),\n" + " CONSTRAINT PK0 PRIMARY KEY(id)\n" + ") OPTIONS (UPDATABLE TRUE);"; assertEquals(expected, metadataDDL); }