org.apache.solr.client.solrj.request.schema.SchemaRequest Java Examples
The following examples show how to use
org.apache.solr.client.solrj.request.schema.SchemaRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SolrColumnMetadataDao.java From metron with Apache License 2.0 | 6 votes |
protected List<Map<String, Object>> getIndexFields(String index) throws IOException, SolrServerException { List<Map<String, Object>> indexFields = new ArrayList<>(); // Get all the fields in use, including dynamic fields LukeRequest lukeRequest = new LukeRequest(); LukeResponse lukeResponse = lukeRequest.process(client, index); for (Entry<String, LukeResponse.FieldInfo> field : lukeResponse.getFieldInfo().entrySet()) { Map<String, Object> fieldData = new HashMap<>(); fieldData.put("name", field.getValue().getName()); fieldData.put("type", field.getValue().getType()); indexFields.add(fieldData); } // Get all the schema fields SchemaRepresentation schemaRepresentation = new SchemaRequest().process(client, index) .getSchemaRepresentation(); indexFields.addAll(schemaRepresentation.getFields()); return indexFields; }
Example #2
Source File: SchemaTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testDeleteDynamicFieldAccuracy() throws Exception { String dynamicFieldName = "*_del"; Map<String, Object> fieldAttributes = new LinkedHashMap<>(); fieldAttributes.put("name", dynamicFieldName); fieldAttributes.put("type", "string"); SchemaRequest.AddDynamicField addFieldUpdateSchemaRequest = new SchemaRequest.AddDynamicField(fieldAttributes); SchemaResponse.UpdateResponse addDynamicFieldResponse = addFieldUpdateSchemaRequest.process(getSolrClient()); assertValidSchemaResponse(addDynamicFieldResponse); SchemaRequest.DynamicField dynamicFieldSchemaRequest = new SchemaRequest.DynamicField(dynamicFieldName); SchemaResponse.DynamicFieldResponse initialDFieldResponse = dynamicFieldSchemaRequest.process(getSolrClient()); assertValidSchemaResponse(initialDFieldResponse); Map<String, Object> fieldAttributesResponse = initialDFieldResponse.getDynamicField(); assertThat(dynamicFieldName, is(equalTo(fieldAttributesResponse.get("name")))); SchemaRequest.DeleteDynamicField deleteFieldRequest = new SchemaRequest.DeleteDynamicField(dynamicFieldName); SchemaResponse.UpdateResponse deleteDynamicFieldResponse = deleteFieldRequest.process(getSolrClient()); assertValidSchemaResponse(deleteDynamicFieldResponse); expectThrows(SolrException.class, () -> dynamicFieldSchemaRequest.process(getSolrClient())); }
Example #3
Source File: SchemaTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void addFieldTypeShouldntBeCalledTwiceWithTheSameName() throws Exception { Map<String, Object> fieldTypeAttributes = new LinkedHashMap<>(); String fieldName = "failureInt"; fieldTypeAttributes.put("name", fieldName); fieldTypeAttributes.put("class", RANDOMIZED_NUMERIC_FIELDTYPES.get(Integer.class)); fieldTypeAttributes.put("omitNorms", true); fieldTypeAttributes.put("positionIncrementGap", 0); FieldTypeDefinition fieldTypeDefinition = new FieldTypeDefinition(); fieldTypeDefinition.setAttributes(fieldTypeAttributes); SchemaRequest.AddFieldType addFieldTypeRequest = new SchemaRequest.AddFieldType(fieldTypeDefinition); SchemaResponse.UpdateResponse addFieldTypeFirstResponse = addFieldTypeRequest.process(getSolrClient()); assertValidSchemaResponse(addFieldTypeFirstResponse); assertFailedSchemaResponse(() -> addFieldTypeRequest.process(getSolrClient()), "Field type '" + fieldName + "' already exists."); }
Example #4
Source File: SchemaTest.java From lucene-solr with Apache License 2.0 | 6 votes |
private static SchemaRequest.AddFieldType createFieldTypeRequest(String fieldTypeName) { FieldTypeDefinition fieldTypeDefinition = new FieldTypeDefinition(); Map<String, Object> fieldTypeAttributes = new LinkedHashMap<>(); fieldTypeAttributes.put("name", fieldTypeName); fieldTypeAttributes.put("class", "solr.TextField"); fieldTypeDefinition.setAttributes(fieldTypeAttributes); AnalyzerDefinition indexAnalyzerDefinition = new AnalyzerDefinition(); Map<String, Object> iTokenizerAttributes = new LinkedHashMap<>(); iTokenizerAttributes.put("class", "solr.PathHierarchyTokenizerFactory"); iTokenizerAttributes.put("delimiter", "/"); indexAnalyzerDefinition.setTokenizer(iTokenizerAttributes); fieldTypeDefinition.setIndexAnalyzer(indexAnalyzerDefinition); AnalyzerDefinition queryAnalyzerDefinition = new AnalyzerDefinition(); Map<String, Object> qTokenizerAttributes = new LinkedHashMap<>(); qTokenizerAttributes.put("class", "solr.KeywordTokenizerFactory"); queryAnalyzerDefinition.setTokenizer(qTokenizerAttributes); fieldTypeDefinition.setQueryAnalyzer(queryAnalyzerDefinition); return new SchemaRequest.AddFieldType(fieldTypeDefinition); }
Example #5
Source File: TestManagedSchemaAPI.java From lucene-solr with Apache License 2.0 | 6 votes |
private void testModifyField(String collection) throws IOException, SolrServerException { CloudSolrClient cloudClient = cluster.getSolrClient(); SolrInputDocument doc = new SolrInputDocument("id", "3"); cloudClient.add(collection, doc); cloudClient.commit(collection); String fieldName = "id"; SchemaRequest.Field getFieldRequest = new SchemaRequest.Field(fieldName); SchemaResponse.FieldResponse getFieldResponse = getFieldRequest.process(cloudClient, collection); Map<String, Object> field = getFieldResponse.getField(); field.put("docValues", true); SchemaRequest.ReplaceField replaceRequest = new SchemaRequest.ReplaceField(field); SchemaResponse.UpdateResponse replaceResponse = replaceRequest.process(cloudClient, collection); assertNull(replaceResponse.getResponse().get("errors")); CollectionAdminRequest.Reload reloadRequest = CollectionAdminRequest.reloadCollection(collection); CollectionAdminResponse response = reloadRequest.process(cloudClient); assertEquals(0, response.getStatus()); assertTrue(response.isSuccess()); }
Example #6
Source File: SchemaTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testDeleteFieldAccuracy() throws Exception { String fieldName = "fieldToBeDeleted"; Map<String, Object> fieldAttributesRequest = new LinkedHashMap<>(); fieldAttributesRequest.put("name", fieldName); fieldAttributesRequest.put("type", "string"); SchemaRequest.AddField addFieldUpdateSchemaRequest = new SchemaRequest.AddField(fieldAttributesRequest); SchemaResponse.UpdateResponse addFieldResponse = addFieldUpdateSchemaRequest.process(getSolrClient()); assertValidSchemaResponse(addFieldResponse); SchemaRequest.Field fieldSchemaRequest = new SchemaRequest.Field(fieldName); SchemaResponse.FieldResponse initialFieldResponse = fieldSchemaRequest.process(getSolrClient()); assertValidSchemaResponse(initialFieldResponse); Map<String, Object> fieldAttributesResponse = initialFieldResponse.getField(); assertThat(fieldName, is(equalTo(fieldAttributesResponse.get("name")))); SchemaRequest.DeleteField deleteFieldRequest = new SchemaRequest.DeleteField(fieldName); SchemaResponse.UpdateResponse deleteFieldResponse = deleteFieldRequest.process(getSolrClient()); assertValidSchemaResponse(deleteFieldResponse); expectThrows(SolrException.class, () -> fieldSchemaRequest.process(getSolrClient())); }
Example #7
Source File: SchemaTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testCopyFieldAccuracy() throws Exception { SchemaRequest.CopyFields copyFieldsSchemaRequest = new SchemaRequest.CopyFields(); SchemaResponse.CopyFieldsResponse initialCopyFieldsResponse = copyFieldsSchemaRequest.process(getSolrClient()); List<Map<String, Object>> initialCopyFieldsAttributes = initialCopyFieldsResponse.getCopyFields(); String srcFieldName = "copyfield"; String destFieldName1 = "destField1", destFieldName2 = "destField2"; createStoredStringField(srcFieldName, getSolrClient()); createStoredStringField(destFieldName1, getSolrClient()); createStoredStringField(destFieldName2, getSolrClient()); SchemaRequest.AddCopyField addCopyFieldRequest = new SchemaRequest.AddCopyField(srcFieldName, Arrays.asList(destFieldName1, destFieldName2)); SchemaResponse.UpdateResponse addCopyFieldResponse = addCopyFieldRequest.process(getSolrClient()); assertValidSchemaResponse(addCopyFieldResponse); SchemaResponse.CopyFieldsResponse currentCopyFieldsResponse = copyFieldsSchemaRequest.process(getSolrClient()); List<Map<String, Object>> currentCopyFields = currentCopyFieldsResponse.getCopyFields(); assertEquals(initialCopyFieldsAttributes.size() + 2, currentCopyFields.size()); }
Example #8
Source File: TestBulkSchemaAPI.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testAddNewFieldAndQuery() throws Exception { getSolrClient().add(Arrays.asList( sdoc("id", "1", "term_s", "tux"))); getSolrClient().commit(true, true); Map<String,Object> attrs = new HashMap<>(); attrs.put("name", "newstringtestfield"); attrs.put("type", "string"); new SchemaRequest.AddField(attrs).process(getSolrClient()); SolrQuery query = new SolrQuery("*:*"); query.addFacetField("newstringtestfield"); int size = getSolrClient().query(query).getResults().size(); assertEquals(1, size); }
Example #9
Source File: SchemaTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testDeleteCopyFieldAccuracy() throws Exception { String srcFieldName = "copyfield"; String destFieldName1 = "destField1", destFieldName2 = "destField2"; createStoredStringField(srcFieldName, getSolrClient()); createStoredStringField(destFieldName1, getSolrClient()); createStoredStringField(destFieldName2, getSolrClient()); SchemaRequest.AddCopyField addCopyFieldRequest = new SchemaRequest.AddCopyField(srcFieldName, Arrays.asList(destFieldName1, destFieldName2)); SchemaResponse.UpdateResponse addCopyFieldResponse = addCopyFieldRequest.process(getSolrClient()); System.out.println(addCopyFieldResponse); assertValidSchemaResponse(addCopyFieldResponse); SchemaRequest.DeleteCopyField deleteCopyFieldRequest1 = new SchemaRequest.DeleteCopyField(srcFieldName, Arrays.asList(destFieldName1)); assertValidSchemaResponse(deleteCopyFieldRequest1.process(getSolrClient())); SchemaRequest.DeleteCopyField deleteCopyFieldRequest2 = new SchemaRequest.DeleteCopyField(srcFieldName, Arrays.asList(destFieldName2)); assertValidSchemaResponse(deleteCopyFieldRequest2.process(getSolrClient())); }
Example #10
Source File: SchemaTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void addFieldTypeWithSimilarityAccuracy() throws Exception { FieldTypeDefinition fieldTypeDefinition = new FieldTypeDefinition(); Map<String, Object> fieldTypeAttributes = new LinkedHashMap<>(); String fieldTypeName = "fullClassNames"; fieldTypeAttributes.put("name", fieldTypeName); fieldTypeAttributes.put("class", "org.apache.solr.schema.TextField"); fieldTypeDefinition.setAttributes(fieldTypeAttributes); AnalyzerDefinition analyzerDefinition = new AnalyzerDefinition(); Map<String, Object> charFilterAttributes = new LinkedHashMap<>(); charFilterAttributes.put("class", "solr.PatternReplaceCharFilterFactory"); charFilterAttributes.put("replacement", "$1$1"); charFilterAttributes.put("pattern", "([a-zA-Z])\\\\1+"); analyzerDefinition.setCharFilters(Collections.singletonList(charFilterAttributes)); Map<String, Object> tokenizerAttributes = new LinkedHashMap<>(); tokenizerAttributes.put("class", "solr.WhitespaceTokenizerFactory"); analyzerDefinition.setTokenizer(tokenizerAttributes); fieldTypeDefinition.setAnalyzer(analyzerDefinition); Map<String, Object> similarityAttributes = new LinkedHashMap<>(); similarityAttributes.put("class", "org.apache.lucene.misc.SweetSpotSimilarity"); fieldTypeDefinition.setSimilarity(similarityAttributes); SchemaRequest.AddFieldType addFieldTypeRequest = new SchemaRequest.AddFieldType(fieldTypeDefinition); SchemaResponse.UpdateResponse addFieldTypeResponse = addFieldTypeRequest.process(getSolrClient()); assertValidSchemaResponse(addFieldTypeResponse); // similarity is not shown by default for the fieldType SchemaRequest.FieldType fieldTypeRequest = new SchemaRequest.FieldType(fieldTypeName); SchemaResponse.FieldTypeResponse newFieldTypeResponse = fieldTypeRequest.process(getSolrClient()); assertValidSchemaResponse(newFieldTypeResponse); FieldTypeRepresentation newFieldTypeRepresentation = newFieldTypeResponse.getFieldType(); assertThat(fieldTypeName, is(equalTo(newFieldTypeRepresentation.getAttributes().get("name")))); assertThat(similarityAttributes.get("class"), is(equalTo(newFieldTypeRepresentation.getSimilarity().get("class")))); }
Example #11
Source File: SchemaTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testReplaceDynamicFieldAccuracy() throws Exception { // Given String fieldName = "*_replace"; Map<String, Object> fieldAttributes = new LinkedHashMap<>(); fieldAttributes.put("name", fieldName); fieldAttributes.put("type", "string"); fieldAttributes.put("stored", false); fieldAttributes.put("indexed", true); SchemaRequest.AddDynamicField addDFieldUpdateSchemaRequest = new SchemaRequest.AddDynamicField(fieldAttributes); SchemaResponse.UpdateResponse addFieldResponse = addDFieldUpdateSchemaRequest.process(getSolrClient()); assertValidSchemaResponse(addFieldResponse); // When : update the field definition Map<String, Object> replaceFieldAttributes = new LinkedHashMap<>(fieldAttributes); replaceFieldAttributes.put("stored", true); replaceFieldAttributes.put("indexed", false); SchemaRequest.ReplaceDynamicField replaceFieldRequest = new SchemaRequest.ReplaceDynamicField(replaceFieldAttributes); SchemaResponse.UpdateResponse replaceFieldResponse = replaceFieldRequest.process(getSolrClient()); assertValidSchemaResponse(replaceFieldResponse); // Then SchemaRequest.DynamicField dynamicFieldSchemaRequest = new SchemaRequest.DynamicField(fieldName); SchemaResponse.DynamicFieldResponse newFieldResponse = dynamicFieldSchemaRequest.process(getSolrClient()); assertValidSchemaResponse(newFieldResponse); Map<String, Object> newFieldAttributes = newFieldResponse.getDynamicField(); assertThat(fieldName, is(equalTo(newFieldAttributes.get("name")))); assertThat("string", is(equalTo(newFieldAttributes.get("type")))); assertThat(true, is(equalTo(newFieldAttributes.get("stored")))); assertThat(false, is(equalTo(newFieldAttributes.get("indexed")))); }
Example #12
Source File: SchemaTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void addFieldTypeWithAnalyzerClassAccuracy() throws Exception { Map<String, Object> fieldTypeAttributes = new LinkedHashMap<>(); String fieldTypeName = "nameText"; fieldTypeAttributes.put("name", fieldTypeName); fieldTypeAttributes.put("class", "solr.TextField"); FieldTypeDefinition fieldTypeDefinition = new FieldTypeDefinition(); fieldTypeDefinition.setAttributes(fieldTypeAttributes); Map<String, Object> analyzerAttributes = new LinkedHashMap<>(); analyzerAttributes.put("class", "org.apache.lucene.analysis.core.WhitespaceAnalyzer"); analyzerAttributes.put("luceneMatchVersion", "5.0.0"); AnalyzerDefinition analyzerDefinition = new AnalyzerDefinition(); analyzerDefinition.setAttributes(analyzerAttributes); fieldTypeDefinition.setAnalyzer(analyzerDefinition); SchemaRequest.AddFieldType addFieldTypeRequest = new SchemaRequest.AddFieldType(fieldTypeDefinition); SchemaResponse.UpdateResponse addFieldTypeResponse = addFieldTypeRequest.process(getSolrClient()); assertValidSchemaResponse(addFieldTypeResponse); SchemaRequest.FieldType fieldTypeRequest = new SchemaRequest.FieldType(fieldTypeName); SchemaResponse.FieldTypeResponse newFieldTypeResponse = fieldTypeRequest.process(getSolrClient()); assertValidSchemaResponse(newFieldTypeResponse); FieldTypeRepresentation newFieldTypeRepresentation = newFieldTypeResponse.getFieldType(); assertThat(fieldTypeName, is(equalTo(newFieldTypeRepresentation.getAttributes().get("name")))); assertThat(analyzerAttributes.get("class"), is(equalTo(newFieldTypeRepresentation.getAnalyzer().getAttributes().get("class")))); assertThat(analyzerAttributes.get("luceneMatchVersion"), is(equalTo(newFieldTypeRepresentation.getAnalyzer().getAttributes().get("luceneMatchVersion")))); }
Example #13
Source File: SchemaTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testDeleteFieldTypeAccuracy() throws Exception { Map<String, Object> fieldTypeAttributes = new LinkedHashMap<>(); String fieldTypeName = "delInt"; fieldTypeAttributes.put("name", fieldTypeName); fieldTypeAttributes.put("class", RANDOMIZED_NUMERIC_FIELDTYPES.get(Integer.class)); fieldTypeAttributes.put("omitNorms", true); fieldTypeAttributes.put("positionIncrementGap", 0); FieldTypeDefinition fieldTypeDefinition = new FieldTypeDefinition(); fieldTypeDefinition.setAttributes(fieldTypeAttributes); SchemaRequest.AddFieldType addFieldTypeRequest = new SchemaRequest.AddFieldType(fieldTypeDefinition); SolrClient c = getSolrClient(); SchemaResponse.UpdateResponse addFieldTypeResponse = addFieldTypeRequest.process(c); assertValidSchemaResponse(addFieldTypeResponse); SchemaRequest.FieldType fieldTypeRequest = new SchemaRequest.FieldType(fieldTypeName); SchemaResponse.FieldTypeResponse initialFieldTypeResponse = fieldTypeRequest.process(getSolrClient()); assertValidSchemaResponse(initialFieldTypeResponse); FieldTypeRepresentation responseFieldTypeRepresentation = initialFieldTypeResponse.getFieldType(); assertThat(fieldTypeName, is(equalTo(responseFieldTypeRepresentation.getAttributes().get("name")))); SchemaRequest.DeleteFieldType deleteFieldTypeRequest = new SchemaRequest.DeleteFieldType(fieldTypeName); SchemaResponse.UpdateResponse deleteFieldTypeResponse = deleteFieldTypeRequest.process(getSolrClient()); assertValidSchemaResponse(deleteFieldTypeResponse); try { fieldTypeRequest.process(getSolrClient()); fail(String.format(Locale.ROOT, "after removal, the field type %s shouldn't be anymore available over Schema API", fieldTypeName)); } catch (SolrException e) { //success } }
Example #14
Source File: SchemaTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void deletingAFieldTypeThatDoesntExistInTheSchemaShouldFail() throws Exception { String fieldType = "fieldTypeToBeDeleted"; SchemaRequest.DeleteFieldType deleteFieldTypeRequest = new SchemaRequest.DeleteFieldType(fieldType); assertFailedSchemaResponse(() -> deleteFieldTypeRequest.process(getSolrClient()), "The field type '" + fieldType + "' is not present in this schema, and so cannot be deleted."); }
Example #15
Source File: SchemaTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testCopyFieldWithMaxCharsAccuracy() throws Exception { SchemaRequest.CopyFields copyFieldsSchemaRequest = new SchemaRequest.CopyFields(); SchemaResponse.CopyFieldsResponse initialCopyFieldsResponse = copyFieldsSchemaRequest.process(getSolrClient()); List<Map<String, Object>> initialCopyFieldsAttributes = initialCopyFieldsResponse.getCopyFields(); String srcFieldName = "copyfield"; String destFieldName1 = "destField1", destFieldName2 = "destField2"; createStoredStringField(srcFieldName, getSolrClient()); createStoredStringField(destFieldName1, getSolrClient()); createStoredStringField(destFieldName2, getSolrClient()); Integer maxChars = 200; SchemaRequest.AddCopyField addCopyFieldRequest = new SchemaRequest.AddCopyField(srcFieldName, Arrays.asList(destFieldName1, destFieldName2), maxChars); SchemaResponse.UpdateResponse addCopyFieldResponse = addCopyFieldRequest.process(getSolrClient()); assertValidSchemaResponse(addCopyFieldResponse); SchemaResponse.CopyFieldsResponse currentCopyFieldsResponse = copyFieldsSchemaRequest.process(getSolrClient()); List<Map<String, Object>> currentCopyFields = currentCopyFieldsResponse.getCopyFields(); assertEquals(initialCopyFieldsAttributes.size() + 2, currentCopyFields.size()); for (Map<String, Object> currentCopyField : currentCopyFields) { if (srcFieldName.equals(currentCopyField.get("source"))) { String currentDestFieldName = (String) currentCopyField.get("dest"); int currentMaxChars = (Integer) currentCopyField.get("maxChars"); assertThat(currentDestFieldName, anyOf(is(equalTo(destFieldName1)), is(equalTo(destFieldName2)))); assertTrue(maxChars == currentMaxChars); } } }
Example #16
Source File: SchemaTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void copyFieldsShouldFailWhenOneOfTheFieldsDoesntExistInTheSchema() throws Exception { String srcFieldName = "srcnotexist"; String destFieldName1 = "destNotExist1", destFieldName2 = "destNotExist2"; SchemaRequest.AddCopyField addCopyFieldRequest = new SchemaRequest.AddCopyField(srcFieldName, Arrays.asList(destFieldName1, destFieldName2)); assertFailedSchemaResponse(() -> addCopyFieldRequest.process(getSolrClient()), "copyField source :'" + srcFieldName + "' is not a glob and doesn't match any explicit field or dynamicField."); }
Example #17
Source File: SchemaTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void deleteCopyFieldShouldFailWhenOneOfTheFieldsDoesntExistInTheSchema() throws Exception { String srcFieldName = "copyfield"; String destFieldName1 = "destField1", destFieldName2 = "destField2"; SchemaRequest.DeleteCopyField deleteCopyFieldsRequest = new SchemaRequest.DeleteCopyField(srcFieldName, Arrays.asList(destFieldName1, destFieldName2)); assertFailedSchemaResponse(() -> deleteCopyFieldsRequest.process(getSolrClient()), "Copy field directive not found: '" + srcFieldName + "' -> '" + destFieldName1 + "'"); }
Example #18
Source File: TestEmbeddedSolrServerSchemaAPI.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testSchemaAddFieldAndVerifyExistence() throws Exception { assumeTrue("it needs to ammend schema", Boolean.getBoolean("managed.schema.mutable")); SchemaResponse.UpdateResponse addFieldResponse = new SchemaRequest.AddField(fieldAttributes).process(server); assertEquals(addFieldResponse.toString(), 0, addFieldResponse.getStatus()); // This asserts that the field was actually created // this is due to the fact that the response gave OK but actually never created the field. Map<String,Object> foundFieldAttributes = new SchemaRequest.Field(fieldName).process(server).getField(); assertEquals(fieldAttributes, foundFieldAttributes); assertEquals("removing " + fieldName, 0, new SchemaRequest.DeleteField(fieldName).process(server).getStatus()); }
Example #19
Source File: TestEmbeddedSolrServerSchemaAPI.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testSchemaAddFieldAndFailOnImmutable() { assumeFalse("it needs a readonly schema", Boolean.getBoolean("managed.schema.mutable")); SchemaRequest.AddField addFieldUpdateSchemaRequest = new SchemaRequest.AddField(fieldAttributes); assertFailedSchemaResponse(() -> addFieldUpdateSchemaRequest.process(server), "schema is not editable"); }
Example #20
Source File: DocValuesNotIndexedTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private static AddFieldType getType(String... args) { FieldTypeDefinition ftd = new FieldTypeDefinition(); Map<String, Object> ftas = new LinkedHashMap<>(); for (int idx = 0; idx < args.length; idx += 2) { ftas.put(args[idx], args[idx + 1]); } ftd.setAttributes(ftas); return new SchemaRequest.AddFieldType(ftd); }
Example #21
Source File: ManagedSchemaRoundRobinCloudTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private void addField(SolrClient client, Map<String,Object> field) throws Exception { SchemaResponse.UpdateResponse addFieldResponse = new SchemaRequest.AddField(field).process(client, COLLECTION); assertNotNull(addFieldResponse); assertEquals(0, addFieldResponse.getStatus()); assertNull(addFieldResponse.getResponse().get("errors")); String fieldName = field.get("name").toString(); SchemaResponse.FieldResponse fieldResponse = new SchemaRequest.Field(fieldName).process(client, COLLECTION); assertNotNull(fieldResponse); assertEquals(0, fieldResponse.getStatus()); }
Example #22
Source File: SchemaApiFailureTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test // commented 4-Sep-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 23-Aug-2018 public void testAddTheSameFieldTwice() throws Exception { CloudSolrClient client = cluster.getSolrClient(); SchemaRequest.Update fieldAddition = new SchemaRequest.AddField (Utils.makeMap("name","myfield", "type","string")); SchemaResponse.UpdateResponse updateResponse = fieldAddition.process(client, COLLECTION); BaseHttpSolrClient.RemoteExecutionException ex = expectThrows(BaseHttpSolrClient.RemoteExecutionException.class, () -> fieldAddition.process(client, COLLECTION)); assertTrue("expected error message 'Field 'myfield' already exists'.",Utils.getObjectByPath(ex.getMetaData(), false, "error/details[0]/errorMessages[0]").toString().contains("Field 'myfield' already exists.") ); }
Example #23
Source File: TestManagedSchemaAPI.java From lucene-solr with Apache License 2.0 | 5 votes |
private void addStringField(String fieldName, String collection, CloudSolrClient cloudClient) throws IOException, SolrServerException { Map<String, Object> fieldAttributes = new LinkedHashMap<>(); fieldAttributes.put("name", fieldName); fieldAttributes.put("type", "string"); SchemaRequest.AddField addFieldUpdateSchemaRequest = new SchemaRequest.AddField(fieldAttributes); SchemaResponse.UpdateResponse addFieldResponse = addFieldUpdateSchemaRequest.process(cloudClient, collection); assertEquals(0, addFieldResponse.getStatus()); assertNull(addFieldResponse.getResponse().get("errors")); log.info("added new field={}", fieldName); }
Example #24
Source File: PreAnalyzedFieldManagedSchemaCloudTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private void addField(Map<String,Object> field) throws Exception { CloudSolrClient client = cluster.getSolrClient(); UpdateResponse addFieldResponse = new SchemaRequest.AddField(field).process(client, COLLECTION); assertNotNull(addFieldResponse); assertEquals(0, addFieldResponse.getStatus()); assertNull(addFieldResponse.getResponse().get("errors")); FieldResponse fieldResponse = new SchemaRequest.Field(field.get("name").toString()).process(client, COLLECTION); assertNotNull(fieldResponse); assertEquals(0, fieldResponse.getStatus()); }
Example #25
Source File: SolrTarget07.java From datacollector with Apache License 2.0 | 5 votes |
private void getRequiredFieldNames() throws SolrServerException, IOException { SchemaRequest schemaRequest = new SchemaRequest(); SchemaResponse schemaResponse = schemaRequest.process(solrClient); SchemaRepresentation schemaRepresentation = schemaResponse.getSchemaRepresentation(); List<Map<String, Object>> fields = schemaRepresentation.getFields(); for (Map<String, Object> field : fields) { if (field.containsKey(REQUIRED) && field.get(REQUIRED).equals(true)) { requiredFieldNamesMap.add(field.get(NAME).toString()); } } }
Example #26
Source File: SolrTarget07.java From datacollector with Apache License 2.0 | 5 votes |
private void getOptionalFieldNames() throws SolrServerException, IOException { SchemaRequest schemaRequest = new SchemaRequest(); SchemaResponse schemaResponse = schemaRequest.process(solrClient); SchemaRepresentation schemaRepresentation = schemaResponse.getSchemaRepresentation(); List<Map<String, Object>> fields = schemaRepresentation.getFields(); for (Map<String, Object> field : fields) { if (!field.containsKey(REQUIRED) || field.get(REQUIRED).equals(false)) { requiredFieldNamesMap.add(field.get(NAME).toString()); } } }
Example #27
Source File: SolrTarget06.java From datacollector with Apache License 2.0 | 5 votes |
private void getRequiredFieldNames() throws SolrServerException, IOException { SchemaRequest schemaRequest = new SchemaRequest(); SchemaResponse schemaResponse = schemaRequest.process(solrClient); SchemaRepresentation schemaRepresentation = schemaResponse.getSchemaRepresentation(); List<Map<String, Object>> fields = schemaRepresentation.getFields(); for (Map<String, Object> field : fields) { if (field.containsKey(REQUIRED) && field.get(REQUIRED).equals(true)) { requiredFieldNamesMap.add(field.get(NAME).toString()); } } }
Example #28
Source File: SolrTarget06.java From datacollector with Apache License 2.0 | 5 votes |
private void getOptionalFieldNames() throws SolrServerException, IOException { SchemaRequest schemaRequest = new SchemaRequest(); SchemaResponse schemaResponse = schemaRequest.process(solrClient); SchemaRepresentation schemaRepresentation = schemaResponse.getSchemaRepresentation(); List<Map<String, Object>> fields = schemaRepresentation.getFields(); for (Map<String, Object> field : fields) { if (!field.containsKey(REQUIRED) || field.get(REQUIRED).equals(false)) { optionalFieldNamesMap.add(field.get(NAME).toString()); } } }
Example #29
Source File: MCRSolrSchemaReloader.java From mycore with GNU General Public License v3.0 | 5 votes |
private static void deleteFields(SolrClient solrClient) throws SolrServerException, IOException { SchemaRequest.Fields fieldsReq = new SchemaRequest.Fields(); for (Map<String, Object> field : fieldsReq.process(solrClient).getFields()) { String fieldName = field.get("name").toString(); if (!SOLR_DEFAULT_FIELDS.contains(fieldName)) { LOGGER.debug("remove SOLR Field " + fieldName); SchemaRequest.DeleteField delField = new SchemaRequest.DeleteField(fieldName); delField.process(solrClient); } } }
Example #30
Source File: MCRSolrSchemaReloader.java From mycore with GNU General Public License v3.0 | 5 votes |
private static void deleteCopyFields(SolrClient solrClient) throws SolrServerException, IOException { SchemaRequest.CopyFields copyFieldsReq = new SchemaRequest.CopyFields(); for (Map<String, Object> copyField : copyFieldsReq.process(solrClient).getCopyFields()) { String fieldSrc = copyField.get("source").toString(); List<String> fieldDest = new ArrayList<>(); fieldDest.add(copyField.get("dest").toString()); LOGGER.debug("remove SOLR CopyField " + fieldSrc + " --> " + fieldDest.get(0)); SchemaRequest.DeleteCopyField delCopyField = new SchemaRequest.DeleteCopyField(fieldSrc, fieldDest); delCopyField.process(solrClient); } }