[lucy-user] GO (aka golang) Client Bindings for Lucy

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

[lucy-user] GO (aka golang) Client Bindings for Lucy

Philip Southam
Hi,

First, thanks for making a project that gives us something with the
power of lucene in a C library. It's nice to have alternatives to
xapian, to work with.

So I've taken the last couple hours to utilize the power cgo to get the
sample/getting_started.c ported and "running" in Go. Every thing seems
to be working great, but I'm at a sticking point. How do I get the
values out of the document once it they are found? Meaning the print
statement returns something like this when the found results iterate
through the loop.

        Result 0 %!s(*main._Ctype_uint8_t=0x263c710)

Any ideas on how to get the value from the CB_Get_Ptr8 to return
something meaningful in Go?

I can provide the code or any other details if anybody needs.

Thanks,
--
Philip Southam
Chief Architect / Яeverse Эngineer
http://zefr.com
http://youtu.be/28BXqQWqYJU


signature.asc (817 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [lucy-user] GO (aka golang) Client Bindings for Lucy

Philip Southam
Had some time to think about it on my long drive home and got it figured
out. The key was to add my own "conversion" function in the comment
preceding the `import "C"` deceleration as trying to cast from
`uint8_t*` to `char*` in the Go code wouldn't work.

        /*
        ...Some imports and cgo flags up here...
       
        extern char* cfish_cb_ptr2char(const cfish_CharBuf * field) {
            return (char*)CFISH_CB_Get_Ptr8(field);
        }
        */
        import "C"


Now in the loop I have access to it like so.

        value_cb := C.LUCY_HitDoc_Extract(hit, field_cb, nil)
        key := C.cfish_cb_ptr2char(value_cb)
        fmt.Printf("Result %d %s\n", i, C.GoString(key))


Now it's time to see if I can implement a "real world" scenario.
--
Philip Southam
Chief Architect / Яeverse Эngineer
http://zefr.com
http://youtu.be/28BXqQWqYJU


signature.asc (817 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [lucy-user] GO (aka golang) Client Bindings for Lucy

Marvin Humphrey
Hello, Philip,

On Thu, Aug 22, 2013 at 10:14 PM, Philip Southam <[hidden email]> wrote:
> Had some time to think about it on my long drive home and got it figured
> out. The key was to add my own "conversion" function in the comment
> preceding the `import "C"` deceleration as trying to cast from
> `uint8_t*` to `char*` in the Go code wouldn't work.

Glad to hear that you were able to fight through the problem, and thank you
for following up to let us know.  In retrospect, having Get_Ptr8() return
`uint8_t*` rather than `char*` was a questionable judgment call.  :)

> Now it's time to see if I can implement a "real world" scenario.

Please keep us posted!

Marvin Humphrey
Reply | Threaded
Open this post in threaded view
|

Re: [lucy-user] GO (aka golang) Client Bindings for Lucy

Philip Southam
At the risk of embarrassing myself, I've put a small client library with
just a subset of the functionality I was originally after on github.

        https://github.com/philipsoutham/golucy

I'm new to Go, so I'm still not sure what is "go-thonic" way of doing
things is yet. I would love for it to be as complete as the perl
bindings one day, but I'm struggling with tracking down where the magic
happens in the C code for some (actually, a lot of) things. When I get
some more free time, I'll ping the list with specific requests in terms
of where to find certain pieces of functionality. I also took the
liberty of using the Lucy logo in the README.md. Please let me know if I
wasn't supposed to do that or if anyone objects.


Regards,
On 08/23/2013 01:42 PM, Marvin Humphrey wrote:

> Hello, Philip,
>
> On Thu, Aug 22, 2013 at 10:14 PM, Philip Southam <[hidden email]> wrote:
>> Had some time to think about it on my long drive home and got it figured
>> out. The key was to add my own "conversion" function in the comment
>> preceding the `import "C"` deceleration as trying to cast from
>> `uint8_t*` to `char*` in the Go code wouldn't work.
>
> Glad to hear that you were able to fight through the problem, and thank you
> for following up to let us know.  In retrospect, having Get_Ptr8() return
> `uint8_t*` rather than `char*` was a questionable judgment call.  :)
>
>> Now it's time to see if I can implement a "real world" scenario.
>
> Please keep us posted!
>
> Marvin Humphrey
>

--
Philip Southam
Chief Architect / Яeverse Эngineer
http://zefr.com


signature.asc (853 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [lucy-user] GO (aka golang) Client Bindings for Lucy

Marvin Humphrey
On Tue, Aug 27, 2013 at 3:33 PM, Philip Southam <[hidden email]> wrote:
> At the risk of embarrassing myself, I've put a small client library with
> just a subset of the functionality I was originally after on github.
>
>         https://github.com/philipsoutham/golucy

Cool!

First pull request sent.

I got the sample to build but I'm getting a strange error where it seems that
libcfish may have been loaded twice.  (Gory details: there appear to be two
CHARBUF VTables, as there's a CharBuf whose vtable member claims to have the
class name "Clownfish::CharBuf" but isn't at the same pointer value as
CHARBUF, so `Obj_Is_A(charbuf, CHARBUF)` fails.) I'm out of time for
troubleshooting today but I'll look again tomorrow.

> I'm new to Go, so I'm still not sure what is "go-thonic" way of doing
> things is yet. I would love for it to be as complete as the perl
> bindings one day, but I'm struggling with tracking down where the magic
> happens in the C code for some (actually, a lot of) things. When I get
> some more free time, I'll ping the list with specific requests in terms
> of where to find certain pieces of functionality.

We'll be here. :)

> I also took the
> liberty of using the Lucy logo in the README.md. Please let me know if I
> wasn't supposed to do that or if anyone objects.

I'm a lot more interested in what you're coding than trademark stuff right
now, but since you asked I am now probably obligated to send you to
<http://www.apache.org/foundation/marks/>, where you'll find guidance about
usage of Apache trademarks.

Marvin Humphrey