[lucy-user] Getting search results as json objects

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[lucy-user] Getting search results as json objects

serkanmulayim@gmail.com
Hi guys,

I am using the Lucy C library.

I would like to ask if it is possible to get the HitDocs as Json Strings.

I see that there is a dump method "LUCY_Doc_Dump" in Doc.c and HitDoc, can
this be used for this. Can you elaborate on what "dump"  does? There is
also S_to_json in json.c which expects a dump object to create a
JsonString. Can I use them. If so how?

Also what do serialize functions do in Doc classes.  Can I use them for
this purpose?

Thanks,
Serkan
Reply | Threaded
Open this post in threaded view
|

Re: [lucy-user] Getting search results as json objects

Nick Wellnhofer
On 01/12/2016 02:52, Serkan Mulayim wrote:

> I am using the Lucy C library.
>
> I would like to ask if it is possible to get the HitDocs as Json Strings.
>
> I see that there is a dump method "LUCY_Doc_Dump" in Doc.c and HitDoc, can
> this be used for this. Can you elaborate on what "dump"  does? There is
> also S_to_json in json.c which expects a dump object to create a
> JsonString. Can I use them. If so how?
>
> Also what do serialize functions do in Doc classes.  Can I use them for
> this purpose?

Dump/Load and Serialize/Deserialize are private methods that are only used
internally. The C library doesn't even implement Dump/Load. Serialization is
used for Lucy's on-disk format and unlikely to be useful for anything else.

Lucy has an internal JSON encoder/decoder in Lucy::Util::Json. This is also a
private API and only supports a subset of JSON. But you should be able to
convert a Doc or HitDoc into a JSON string with the C library using
Doc_Get_Fields:

     #include <Lucy/Util/Json.h>

     // Get_Fields returns a (non-incremented) Hash for the C bindings.
     Obj *hash = (Obj*)HitDoc_Get_Fields(doc);
     String *json = Json_to_json(hash);

The usual caveats for private APIs apply. They aren't supported officially and
can change without notice. You can find some documentation for private APIs in
the .cfh files.

Nick

Reply | Threaded
Open this post in threaded view
|

Re: [lucy-user] Getting search results as json objects

serkanmulayim@gmail.com
Thank you very much Nick.

I understand that those private APIs can change. Can you explain what the format of the "dump" is? When I print it as a string I simply get "Lucy::Search::Hits@0x00007f9119703d10". It makes me think that it is doing something in memory (I could not find any hooks in disk) to map the hash to the Json object. This would be something that I would like to avoid.

The other option is simply generating my own json by escaping the field values.

Thanks again...

On 2016-12-01 06:00 (-0800), Nick Wellnhofer <[hidden email]> wrote:

> On 01/12/2016 02:52, Serkan Mulayim wrote:
> > I am using the Lucy C library.
> >
> > I would like to ask if it is possible to get the HitDocs as Json Strings.
> >
> > I see that there is a dump method "LUCY_Doc_Dump" in Doc.c and HitDoc, can
> > this be used for this. Can you elaborate on what "dump"  does? There is
> > also S_to_json in json.c which expects a dump object to create a
> > JsonString. Can I use them. If so how?
> >
> > Also what do serialize functions do in Doc classes.  Can I use them for
> > this purpose?
>
> Dump/Load and Serialize/Deserialize are private methods that are only used
> internally. The C library doesn't even implement Dump/Load. Serialization is
> used for Lucy's on-disk format and unlikely to be useful for anything else.
>
> Lucy has an internal JSON encoder/decoder in Lucy::Util::Json. This is also a
> private API and only supports a subset of JSON. But you should be able to
> convert a Doc or HitDoc into a JSON string with the C library using
> Doc_Get_Fields:
>
>      #include <Lucy/Util/Json.h>
>
>      // Get_Fields returns a (non-incremented) Hash for the C bindings.
>      Obj *hash = (Obj*)HitDoc_Get_Fields(doc);
>      String *json = Json_to_json(hash);
>
> The usual caveats for private APIs apply. They aren't supported officially and
> can change without notice. You can find some documentation for private APIs in
> the .cfh files.
>
> Nick
>
>
Reply | Threaded
Open this post in threaded view
|

Re: [lucy-user] Getting search results as json objects

Nick Wellnhofer
On 01/12/2016 20:39, [hidden email] wrote:
> Can you explain what the format of the "dump" is?

You mean the argument to Json_to_json? It can be either a Hash or Vector.

> When I print it as a string I simply get "Lucy::Search::Hits@0x00007f9119703d10".

When you print what as a string? I don't follow.

Nick

Reply | Threaded
Open this post in threaded view
|

Re: [lucy-user] Getting search results as json objects

serkanmulayim@gmail.com
In reply to this post by serkanmulayim@gmail.com
Thanks Nick, I understand it now.

On 2016-11-30 17:52 (-0800), Serkan Mulayim <[hidden email]> wrote:

> Hi guys,
>
> I am using the Lucy C library.
>
> I would like to ask if it is possible to get the HitDocs as Json Strings.
>
> I see that there is a dump method "LUCY_Doc_Dump" in Doc.c and HitDoc, can
> this be used for this. Can you elaborate on what "dump"  does? There is
> also S_to_json in json.c which expects a dump object to create a
> JsonString. Can I use them. If so how?
>
> Also what do serialize functions do in Doc classes.  Can I use them for
> this purpose?
>
> Thanks,
> Serkan
>