Замените устаревший KeyValueQueryDefinition в MarkLogic, чтобы использовать Query By Example

У меня есть документ, сохраненный в MarkLogic, как показано ниже:

<?xml  version="1.0" encoding="UTF-8"?>
<user>
  <userName>Vikram</userName>
  <password>password</password>
  <firstName>Vikram</firstName>
  <lastName>Swaminathan</lastName>
  <emailAddress>vikram@gmail.com</emailAddress>
</user>

Код, который работает с устаревшим (KeyValueQueryDefinition), выглядит следующим образом:

    // create a manager for searching
    QueryManager queryMgr = client.newQueryManager();

    KeyValueQueryDefinition query = queryMgr.newKeyValueDefinition();
    query.put(queryMgr.newElementLocator(new QName("emailAddress")),"vikram@gmail.com");

    // create a handle for the search results
    SearchHandle resultsHandle = new SearchHandle();

    // run the search
    queryMgr.search(query, resultsHandle);        

    // Get the list of matching documents in this page of results
    MatchDocumentSummary[] results = resultsHandle.getMatchResults();

    // Iterate over the results
    for (MatchDocumentSummary result: results) {

        // get the list of match locations for this result
        MatchLocation[] locations = result.getMatchLocations();
        System.out.println("Matched "+locations.length+" locations in "+result.getUri()+":");

        // iterate over the match locations
        for (MatchLocation location: locations) {

            // iterate over the snippets at a match location
            for (MatchSnippet snippet : location.getSnippets()) {
                boolean isHighlighted = snippet.isHighlighted();

                if (isHighlighted)
                    System.out.print("[");
                System.out.print(snippet.getText());
                if (isHighlighted)
                    System.out.print("]");
            }
            System.out.println();
        }
        System.out.println();
    }
}

и результат, который я получаю:

Matched 1 locations in user/vikram:
[vikram@gmail.com]

Я воспользовался помощью ссылки ниже, чтобы она работала с новой версией Marklogic 9, так как KeyValueQueryDefinition устарела в последней версии.

https://docs.marklogic.com/guide/relnotes/chap4

Есть ли вариант для изменения кода KeyValueQueryDefinition здесь

 KeyValueQueryDefinition query = queryMgr.newKeyValueDefinition();
        query.put(queryMgr.newElementLocator(new QName("emailAddress")),"vikram@gmail.com");

использовать QBE для поиска документов, как упомянуто здесь в ссылке ниже:

https://docs.marklogic.com/guide/java/searches

Любые предложения о том, как подойти к этому??

1 ответ

Решение

Я не могу понять вопрос. Разве вы не будете просто следовать инструкциям по предоставленной вами ссылке?

String rawXMLQuery =
  "<q:qbe xmlns:q='http://marklogic.com/appservices/querybyexample'>"+
    "<q:query>" +
      "<emailAddress>vikram@gmail.com</emailAddress>" +
    "</q:query>" +
  "</q:qbe>";
StringHandle rawHandle = 
    new StringHandle(rawXMLQuery).withFormat(Format.XML);
RawQueryByExampleDefinition query =
    queryMgr.newRawQueryByExampleDefinition(rawHandle);
Другие вопросы по тегам