08-17-2023 06:27 PM
I was trying to follow EV Search API to use EV web service search, created proxy classes, the search run and return results, however it only return the default fields, even I set the return fields include durl, it not return the property.
This part of the test search code :
public String[] rfields = { "snum", "date", "auth", "subj", "durl" };
09-14-2023 04:51 AM
try this, dont know if it helps:
import com.example.ArrayOfstring;
import com.example.ArrayOfSource;
import com.example.Field;
import com.example.ObjectFactory;
import com.example.QueryOptions;
import com.example.Result;
import com.example.ResultOptions;
import com.example.ResultsFormat;
import com.example.SearchRequest;
import com.example.SearchResponse;
import com.example.Source;
import javax.xml.bind.JAXBElement;
public class YourClassName { // Replace with your actual class name
public static void main(String[] args) {
String[] rfields = { "snum", "date", "auth", "subj", "durl" };
String vaultid = "your_vault_id"; // Replace with your actual vault ID
String keyword = "your_keyword"; // Replace with your actual keyword
String format = "xml"; // Replace with your desired format
// Create a SearchRequest
SearchRequest request = new SearchRequest();
request.setID(vaultid);
// Create an ArrayOfSource and add a Source
ArrayOfSource sources = new ArrayOfSource();
Source source1 = new Source();
source1.setArchiveID(vaultid);
sources.getSource().add(source1);
request.setSources(sources);
request.setBooleanTextQuery(keyword);
// Create ResultOptions and set fields
ResultOptions resultoption = new ResultOptions();
ArrayOfstring fields = new ArrayOfstring();
for (String rfield : rfields) {
fields.getString().add(rfield);
}
resultoption.setIncludeServerQuery(true);
// Create JAXBElement for fields
JAXBElement<ArrayOfstring> resultfields = new ObjectFactory().createArrayOfstring(fields);
resultoption.setFields(resultfields);
if (format.equalsIgnoreCase("xml")) {
resultoption.setFormat(ResultsFormat.XML);
resultoption.setIncludeExtraInfo(true);
}
request.setResultOptions(resultoption);
// Create QueryOptions and set administrative search
QueryOptions queryOptions = new QueryOptions();
queryOptions.setAdministrativeSearch(true);
request.setQueryOptions(queryOptions);
// Perform the search
SearchResponse searchResponse = searchService.search(request);
if (format.equalsIgnoreCase("xml")) {
System.out.println(searchResponse.getXMLResults().getValue());
} else {
System.out.println(searchResponse.getResults().getValue().getTotalMatches() + " hits " +
searchResponse.getResults().getValue().getResultsCollection().getResult().size() + " results");
// Display each field/value pair for each result
for (Result result : searchResponse.getResults().getValue().getResultsCollection().getResult()) {
System.out.println("-----");
for (Field field : result.getFields().getField()) {
System.out.println(field.getName() + "=" + field.getValue() + "(" + field.getType() + ")");
}
}
}
}
}