Forum Discussion

truezjz's avatar
truezjz
Level 2
12 months ago

Not getting durl property using EV Search API

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" };

 

SearchRequest request = new SearchRequest();
request.setID(vaultid);
ArrayOfSource sources = new ArrayOfSource();
Source source1 = new Source();
source1.setArchiveID(vaultid);
sources.getSource().add(source1);
request.setSources(sources);
request.setBooleanTextQuery(keyword);
ResultOptions resultoption = new ResultOptions();
ArrayOfstring fields = new ArrayOfstring();
for (String rfield : rfields) {
  fields.getString().add(rfield);
}
resultoption.setIncludeServerQuery(true);
 
// fields
 
JAXBElement<ArrayOfstring> resultfields = new ObjectFactory().createArrayOfstring(fields);
// resultfields.setValue(fields);
System.out.println("resultfields is " + resultfields.isNil() + " " + resultfields.isTypeSubstituted());
resultoption.setFields(resultfields);
 
if (format.equalsIgnoreCase("xml")) {
resultoption.setFormat(ResultsFormat.XML);
resultoption.setIncludeExtraInfo(true);
}
 
// System.out.println(resultoption.getFields().getValue().getString());
 
request.setResultOptions(resultoption);
 
QueryOptions QueryOptions = new QueryOptions();
QueryOptions.setAdministrativeSearch(true);
request.setQueryOptions(QueryOptions);
 
System.out.println(request.getResultOptions().getFields().getValue().getString());
 
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() + ")");
}
 
}
}

 

1 Reply

  • 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() + ")");
    }
    }
    }
    }
    }