简体   繁体   中英

Creation of search using JAVA API from Marklogic

Here I am creating a java program which connects to a Marklogic Database and retrieves the documents using the string Keyword. Below is the program created.

import com.marklogic.client.DatabaseClient;
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.DatabaseClientFactory.Authentication;
import com.marklogic.client.document.BinaryDocumentManager;
import com.marklogic.client.document.JSONDocumentManager;
import com.marklogic.client.document.TextDocumentManager;
import com.marklogic.client.document.XMLDocumentManager;
import com.marklogic.client.io.Format;
import com.marklogic.client.io.StringHandle;
import com.marklogic.client.query.QueryManager;
import com.marklogic.client.query.StringQueryDefinition;

public class dcb_conn {
  public static void main(String args[]){
    DatabaseClient client = DatabaseClientFactory.newClient("localhost", 8004, "venkatesh", "F1mas", Authentication.DIGEST);
    BinaryDocumentManager binDocMgr = client.newBinaryDocumentManager();
    XMLDocumentManager XMLdocMgr = client.newXMLDocumentManager();
    JSONDocumentManager JSONDocMgr = client.newJSONDocumentManager();
    TextDocumentManager TextDocMgr = client.newTextDocumentManager();
    QueryManager queryMgr = client.newQueryManager();
    StringQueryDefinition query = queryMgr.newStringDefinition();
    StringHandle resultsHandle = new StringHandle().withFormat(Format.XML);
    query.setCriteria("Venkatesh");
    queryMgr.search(query, resultsHandle);
  }
}

I am not getting any document results (such as ABC.xml) instead I am getting the below mentioned result. Could you please advise what I am missing here?

10:24:36.139 [main] DEBUG c.m.client.DatabaseClientFactory - Creating new   database client for server at localhost:8004
10:24:36.155 [main] DEBUG c.m.client.impl.JerseyServices - Connecting to localhost at 8004 as venkatesh
10:24:36.319 [main] DEBUG c.m.client.impl.JerseyServices - Searching for Venkatesh

In cases like this, first ensure that you are able to READ the documents in question with the user you are using for searching. I usually do this sanity check with cURL to the document get REST API, for instance

IF you are able to GET the document, then the search fails, this could also be due to language settings.

So, the short suggestion is -remove as many moving parts as possible and test directly against ML with the user (query console and/or REST, etc)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM