Giter Site home page Giter Site logo

Comments (8)

kcoleman-marklogic avatar kcoleman-marklogic commented on June 11, 2024
// Sample code demonstrating the bug. I don't think it matters what docs you have in the db.
package examples;

import com.marklogic.client.io.*;
import com.marklogic.client.query.QueryManager;
import com.marklogic.client.query.RawQueryByExampleDefinition;
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.DatabaseClient;


public class bug {
    // replace with your MarkLogic Server connection information
    static String HOST = "localhost";
    static int PORT = 8003;
    static String USER = "user";
    static String PASSWORD = "password";
    static  DatabaseClient client = DatabaseClientFactory.newClient(
            HOST, PORT, 
            USER, PASSWORD, 
            DatabaseClientFactory.Authentication.DIGEST);

    public static void xmlQBE() {
        QueryManager qm = client.newQueryManager();
        String queryAsString = 
            "<q:qbe xmlns:q='http://marklogic.com/appservices/querybyexample'>"+
                "<q:query>" +
                  "<kind>bird</kind>" +
                "</q:query>" +
              "</q:qbe>";
        RawQueryByExampleDefinition query = 
                qm.newRawQueryByExampleDefinition(new StringHandle(queryAsString));

        StringHandle report = qm.validate(query, new StringHandle());
        System.out.println(report.toString());

        SearchHandle results = qm.search(query, new SearchHandle());
        System.out.println(results.getTotalResults());
    }

    public static void jsonQBE() {
        QueryManager qm = client.newQueryManager();
        String queryAsString = "{ \"$format\": \"xml\", \"$query\": { \"kind\": \"bird\" }  }";
        StringHandle handle = new StringHandle();
        handle.withFormat(Format.JSON).set(queryAsString);      
        RawQueryByExampleDefinition query = 
                qm.newRawQueryByExampleDefinition(handle);

        StringHandle report = qm.validate(query, new StringHandle());
        System.out.println(report.toString());

        SearchHandle results = qm.search(query, new SearchHandle());        
        System.out.println(results.getTotalResults());

        // StringHandle works and returns JSON output
//      StringHandle results = qm.search(query, new StringHandle());
//      System.out.println(results);
    }


    public static void main(String[] args) {
        xmlQBE();   // works
        jsonQBE();  // doesn't work
    }

}

from java-client-api.

grechaw avatar grechaw commented on June 11, 2024

Hi Kim, I ran into a similar error with JSON and bulk read/search.

I wanted to get back JSON search results, so reached into the implementation class:

    JacksonHandle searchHandle = new JacksonHandle();
    JSONDocumentManager docMgr = newJSONDocumentManager(role);
    ((JSONDocumentImpl) docMgr).setResponseFormat(Format.JSON);

    DocumentPage page = docMgr.search(qdef, start, searchHandle);

This results in the "repeated parameter" error.

I would have liked JacksonHandle to simply work .. this also throws an error:

java.lang.UnsupportedOperationException: The format supported by your handle:[JSON] does not match your setResponseFormat:[XML]
at com.marklogic.client.impl.DocumentManagerImpl.search(DocumentManagerImpl.java:363)

from java-client-api.

kcoleman-marklogic avatar kcoleman-marklogic commented on June 11, 2024

I have run into the repeated param error as well, in a context that doesn't involve JacksonHandle. it was previously filed as issue #30.

from java-client-api.

sammefford avatar sammefford commented on June 11, 2024

Looks like the issue here is the format parameter I'm sending to /v1/qbe. If you change your example, Kim, to use JacksonHandle in place of SearchHandle, it works fine. It sends a request to REST equivalent to this curl command:

curl --digest --user rest-writer:x -H "Content-Type: application/json" -H "Accept: multipart/mixed" -d '{ "$query": { "kind": "bird" } }' -X POST http://localhost:8012/v1/qbe?pageLength=50&format=json&view=results

But that means you won't get the convenience methods of SearchHandle. If we weren't doing a bulk request I could change the accept header to "application/xml" and we'd get xml results as desired. But with bulk I need my accept header to be "multipart/mixed". If I remove the format parameter I get the desired behavior:

curl --digest --user rest-writer:x -H "Content-Type: application/json" -H "Accept: multipart/mixed" -d '{ "$query": { "kind": "bird" } }' -X POST http://localhost:8012/v1/qbe?pageLength=50&view=results

But I struggle with this because it's not explicit. If I wanted it, I'm not sure how I would get back a JSON search response if my documents were XML and therefore my QBE was XML. Let's see what Erik thinks.

from java-client-api.

kcoleman-marklogic avatar kcoleman-marklogic commented on June 11, 2024

I think I backed into this problem while trying to figure out why I was having problems with a bulk read using QBE and trying to return search results, but my example isn't intended to be a bulk read. Notice it is using QueryManager.search() rather than DocumentManager.search(). It's a regression on a plain ol' QBE search.

The Accept header probably shouldn't be multipart/mixed at all..That's one problem.

The other, perhaps lesser, problem is that we used to only support returning search results as XML, so SearchHandle.withFormat will not let you set the results to JSON, even though we now seem to want to return them as JSON by default with a JSON query.

from java-client-api.

sammefford avatar sammefford commented on June 11, 2024

Thanks, Kim. That's what I get for visually inspecting your code --I thought I'd seen the differences between this and #30, but I obviously missed some.

from java-client-api.

kcoleman-marklogic avatar kcoleman-marklogic commented on June 11, 2024

Reassigning to QA for testing.

from java-client-api.

sravanr avatar sravanr commented on June 11, 2024

Verified with bulk search.

from java-client-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.