Skip to content

Commit

Permalink
Restore analyzeField method signature; use of Map
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmiley committed Jan 8, 2025
1 parent ae9c5bb commit 5d63220
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.apache.solr.client.solrj.impl.BinaryResponseParser;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.InputStreamResponseParser;
import org.apache.solr.client.solrj.impl.JsonMapResponseParser;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.request.schema.FieldTypeDefinition;
Expand Down Expand Up @@ -118,19 +119,20 @@ class SchemaDesignerConfigSetHelper implements SchemaDesignerConstants {
}

@SuppressWarnings("unchecked")
NamedList<Object> analyzeField(String configSet, String fieldName, String fieldText)
Map<String, Object> analyzeField(String configSet, String fieldName, String fieldText)
throws IOException {
final String mutableId = getMutableId(configSet);
var solrParams = new ModifiableSolrParams();
solrParams.add("analysis.showmatch", "true");
solrParams.add("analysis.fieldname", fieldName);
solrParams.add("analysis.fieldvalue", "POST");
solrParams.set("analysis.showmatch", true);
solrParams.set("analysis.fieldname", fieldName);
solrParams.set("analysis.fieldvalue", "POST");
var request = new GenericSolrRequest(SolrRequest.METHOD.POST, "/analysis/field", solrParams);
request.withContent(fieldText.getBytes(StandardCharsets.UTF_8), "text/plain");
request.setRequiresCollection(true);
request.setResponseParser(new JsonMapResponseParser());
try {
var resp = request.process(cloudClient(), mutableId).getResponse();
return (NamedList<Object>) resp.get("analysis");
return (Map<String, Object>) resp.get("analysis");
} catch (SolrServerException e) {
throw new SolrException(ErrorCode.SERVER_ERROR, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.cloud.SolrCloudTestCase;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.common.util.Utils;
import org.apache.solr.core.CoreContainer;
import org.apache.solr.core.SolrConfig;
import org.apache.solr.schema.FieldType;
Expand Down Expand Up @@ -281,11 +281,14 @@ public void testAnalyzeField() throws Exception {
helper.addSchemaObject(configSet, Collections.singletonMap("add-field", addField));
assertEquals("title", addedFieldName);

NamedList<Object> analysis =
Map<String, Object> analysis =
helper.analyzeField(configSet, "title", "The Pillars of the Earth");

var indexNl = (NamedList<Object>) analysis.findRecursive("field_names", "title", "index");
assertTrue(indexNl.size() > 0);
var index =
(List<Object>)
Utils.getObjectByPath(analysis, false, List.of("field_names", "title", "index"));
assertNotNull(index);
assertFalse(index.isEmpty());
}

@Test
Expand Down

0 comments on commit 5d63220

Please sign in to comment.