How to Query search index on cloudant using java? - java

I am newbie for cloudant and trying to learn full text search on cloudant through tutorial video. I am successful in searching on the cloudant.com through http request ,Now I want that code to be in java as i am working on GWT framework with java. Till now , I am just able to create connection with cloudant.com by studying the particular github project GITHUBLINK
There its given for search like this
Search search = db.search("views101/animals");
SearchResult<Animal> rslt = search
.limit(10)
.includeDocs(true)
.counts(new String[] {"class","diet"})
.querySearchResult("l*", Animal.class);
My Questions:
1. what exactly is this Animal.class refer to?
2. If this not the way what are the steps for full text search on cloudant.
I have created the view and the search index manually on cloudant.com under a designdoc of a database.

Animal.class refers to the class that the documents found will be deserialised into, if you do not have a class to deserialise the data into, you should be able to a HashMap or similar class to access the data returned.

You can find the example source code for the Animal class in this location: https://github.com/cloudant/java-cloudant/blob/88202a1bd7b9b04d96c4b7b8498a1b8f7f99c9e5/src/test/java/com/cloudant/tests/Animal.java.
Like the previous answer indicated, you could also have the results returned as a generic JsonObject that provides access to the properties and values.

Related

Azure Function (Java) add attribute to CustomDimensions

I am desperatly searching on how to add a new attribute to the custom dimensions collection in the request table of the log analytics in the context of a Java function.
I know in C# you can do it using Activity and ITelementryInitializer but for Java I can not get it to work.
Any hints are appreciated. ;)
Azure Function (Java) add attribute to CustomDimensions
In Java, we have the Span attributes concept for adding the optional (extra) fields to the App Insights Schema that populates with the customDimensions in the form of various tables such as traces, exceptions, dependencies.
For that, one of the dependencies is required which is opentelemetry-api-1.jar.
AttributeKey newAttributeKey= AttributeKey.stringKey("resourcecustomDimension"); Span.current().setAttribute(newAttributeKey, "customDimValue");
This brings us the custom attributes for the custom dimensions that will be added to the Telemetry data.
Refer to this MS Doc for more information on adding the attributes to the customDimensions and found the GitHub issue 13310 regarding the user seeking for the Java Code on ITelemetryInitializer where the sample code on it provided by #dhaval24 user.

Gremlin: getting json response in Java with gremlin-driver

I have the following query:
g
.V("user-11")
.repeat(bothE().subgraph("subGraph").outV())
.times(2)
.cap("subGraph")
.next()
When I run it using gremlin-python, I receive the following response:
{'#type': 'tinker:graph',
'#value': {'vertices': [v[device-3], v[device-1], v[user-11], v[card-1]],
'edges': [e[68bad734-db2b-bffc-3e17-a0813d2670cc][user-11-uses_device->device-1],
e[14bad735-2b70-860f-705f-4c0b769a7849][user-11-uses_device->device-3],
e[f0bb3b6d-d161-ec60-5e6d-068272297f24][user-11-uses_card->card-1]]}}
Which is a Graphson representation of the subgraph obtained by the query.
I want to get the same response using Java and gremlin-driver but I haven't been able to figure how.
My best try was:
ObjectMapper mapper = GraphSONMapper.build().version(GraphSONVersion.V3_0).create().createMapper();
Object a = graphTraversalSource
.V(nodeId)
.repeat(bothE().subgraph("subGraph").outV())
.times(2)
.cap("subGraph")
.next();
return mapper.writeValueAsString(a);
But that gave me the following error:
io.netty.handler.codec.DecoderException: org.apache.tinkerpop.gremlin.driver.ser.SerializationException: org.apache.tinkerpop.shaded.kryo.KryoException: Encountered unregistered class ID: 65536
I am using AWS Neptune, but I doubt that makes a difference given that I receive the answer I want through gremlin-python.
I appreciate any help you can give! Thanks
As mentioned in the comments
When using Java what you get back will be an actual TinkerGraph
Using the GraphBinary or GraphSONV3D0 serializer is recommended.
The Gyro one is older and is likely causing the error you saw if you did not specify one of the others serializers.
Note that even if you use one of the other serializers, to get the graph to deserialize into JSON you will need to use the specific TinkerGraph serializer (see the end of this answer for an example). Otherwise you will just get {} returned.
However, you may not need to produce JSON at all in the case of the Java Gremlin client ....
Given you have an actual TinkerGraph back you can run real Gremlin queries against the in-memory subgraph - just create a new traversal source for it. You can also use the graph.io classes to write the graph to file should you wish to. The TinkerGraph will include properties as well as edges and vertices.
You can also access the TinkerGraph object directly using statements such as
a.vertices and a.edges
By means of a concrete example, if you have a query of the form
TinkerGraph tg = (TinkerGraph)g.V().bothE().subgraph("sg").cap("sg").next();
Then you can do
GraphTraversalSource g2 = tg.traversal();
Long cv = g2.V().count().next();
Long ce = g2.E().count().next();
Or you can just access the TinkerGraph data structure directly using statements of the form:
Vertex v = tg.vertices[<some-id>]
Or
List properties = tg.vertices[<some-id>].properties()
This actually means you have a lot more power available to you in the Java client when working with subgraphs.
If you still feel that you need a JSON version of your subgraph, the IO reference is a handy bookmark to have: https://tinkerpop.apache.org/docs/3.4.9/dev/io/#_io_reference
EDITED: - to save you a lot of reading the docs, this code will print a TinkerGraph as JSON
mapper = GraphSONMapper.build().
addRegistry(TinkerIoRegistryV3d0.instance()).
version(GraphSONVersion.V3_0).create().createMapper();
mapper.writeValueAsString(tg)

How to retrieve from Azure mobile services using android studio

I am new to Android and Windows Azure. I have successfully inserted data from Android application but how do I retrieve single data and post that data on a TextView?
The read function after the gettable class is also not working. What is the exact function use for it? I have followed these instructions but they did not work for me, also I do not understand the documentation.
Currently, I just can provide some tutorials about how to use query data from azure database. I recommend you can refer to this official document about how to use Azure Client Library using Java: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-android-how-to-use-client-library . You can focus on two part: “how to query data from a mobile service” and “how to bind data to the UI”.
At the same time, you can view this video from Channel 9: https://channel9.msdn.com/Series/Windows-Azure-Mobile-Services/Android-Getting-Started-With-Data-Connecting-your-app-to-Windows-Azure-Mobile-Services.
The sample code project of this tutorial, please go to the GitHub link https://github.com/Azure/mobile-services-samples/tree/master/GettingStartedWithData .
For the ‘getTable(Class )’ function is not working, please double check whether the class name is same as table name. If they are same, you can use it like below:
MobileServiceTable<ToDoItem> mToDoTable = mClient.getTable(ToDoItem.class);
If not, you can write you code like this:
MobileServiceTable<ToDoItem> mToDoTable = mClient.getTable("ToDoItemBackup", ToDoItem.class);
For further better support, please share more detail about your code snippet .

How t set FieldType.USER in sharepoint file property with Java - Invalid data has been used to update the list item

I'm trying o use method CopyIntoItems and add to uploaded file owner property. Field Owner should be type USER. am setting up it like this:
FieldInformation fieldInformationUser = new FieldInformation();
fieldInformationUser.setDisplayName("Owner");
fieldInformationUser.setInternalName("Owner");
fieldInformationUser.setType(FieldType.USER);
fieldInformationUser.setValue("domain//username");
I'm using this library: Sharepoint library link
If TEXT type field is updated in presented above way - it passes, but does't update field at SharePoint server. Problem occurs when i'm using type USER - server returns
Invalid data has been used to update the list item. The field you are trying to update may be read only.
WSDL specifies fieldType.USER as a string field. he question is, how this string should look like... Anyone knows?
You must make sure that the user exists in the users table in SharePoint. It may be that it exists in AD but it hasn't been added to SharePoint yet.
If it were C#, then you would first issue the EnsureUser command:
//C# CSOM code
SPUser user=web.EnsureUser(userName);
listItem[fieldName] = user;
You should search for a similar method in the library you're using

CouchbaseClient how to get list of all DesignDocuments in the bucket

I'm trying programmatically retrieve list of all design documents in the given bucket via CouchbaseClient. I have followed creating-views-from-sdk documentation but its only explains how to create view. What I need it a way to retrieve all design documents and their views. Any solution out there?
So far I was able to get only one design document...but the name is not coming from the server, e.g.
CouchbaseClient client = new CouchbaseClient(urls, bucketName, bucketPassword);
DesignDocument dc = client.getDesignDocument("MY-HARDCODED-DOC-NAME");
List<View> views = (List<View>) dc.getViews();
for (View view : views)
{
// process view data
}
What I'm trying to accomplish is to write an utility to import/export views from a given couchbase bucket. Since, strangely enough this basic function can't be found anywhere in the admin tools that come with couchbase.
I don't think you can do this with the java client, but there is an endpoint you can hit with an HTTP client from java to get this info:
http://localhost:8091/pools/default/buckets/mybucketname/ddocs
Just replace mybucketname with the bucket you want to get ddocs for. You will need to supply the basic auth header to hit this endpoint so be sure to not forget that part. You will get back json that you can then parse to get the names of the ddocs in the bucket.

Categories

Resources