You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Gustavo Corral <gu...@gmail.com> on 2008/09/20 23:10:21 UTC

eXist, Lucene and XQuery

Hi list,

I have some days with a problem and I hope anybody can help me. I have
developed an extension module to search documents in an eXist collection
using Lucene. The module works fine and returns a Sequence with all the
documents matching a query sorted by the score of Lucene, but when I call
the function of the module in an XQuery script, the documents don't appear
in the same order.

I have this function which take an array with the document's names as
argument and returns a NodeSet with this documents from eXist collection:

protected static NodeSet getDocuments(String[] cgDocNames, DBBroker broker)
throws XPathException
    {
        //Creamos una Secuencia para almacenar los resultados
        ExtArrayNodeSet documents = new ExtArrayNodeSet(cgDocNames.length,
1);

        //obtiene la coleccion de reportes
        Collection cdData =
broker.getCollection(XmldbURI.create(JReportsModule.REPORTSDIRECTORY_DATA_COLLECTION));

        //itera sobre los nombres de reportes
        for(int i = 0; i < cgDocNames.length; i ++)
        {
            //System.out.println(cgDocNames[i]);

            DocumentImpl cgDoc = cdData.getDocument(broker,
XmldbURI.create(cgDocNames[i].substring(cgDocNames[i].indexOf("
")+1,cgDocNames[i].length())));
            if(cgDoc != null){
                //añade el reporte a la secuencia de resultados
                documents.add(new NodeProxy(cgDoc));
            }
        }
        documents.sort(true);
        return (NodeSet) documents;
    }

In the eval function of the extension module I call this getDocuments
function and that's the Sequence eval returns. Until this moment it seems
the documents are in the correct order, but when I call the function of the
extension module in an XQuery script the documents are returned in unorder.

Is the description clear? because my english is not very good.

Thanks

Re: eXist, Lucene and XQuery

Posted by adasal <ad...@gmail.com>.
OK, right, that figures.

Adam

2008/9/22 Gustavo Corral <gu...@gmail.com>

> Thanks a lot Adam,
>
> actually I'm returning now a plain ValueSequence instead a NodeSet and all
> is working great now. It seems like NodeSet needs a predefined order to all
> the algorithms work in the correct way.
>
> Gustavo
>

Re: eXist, Lucene and XQuery

Posted by Gustavo Corral <gu...@gmail.com>.
Thanks a lot Adam,

actually I'm returning now a plain ValueSequence instead a NodeSet and all
is working great now. It seems like NodeSet needs a predefined order to all
the algorithms work in the correct way.

Gustavo

Re: eXist, Lucene and XQuery

Posted by adasal <ad...@gmail.com>.
Ah, hi Gustavo,
I actually don't know this, but it seems that the implementation of XQuery
in eXist places your results in an unsorted list! Or possibly it is placed
in a hashmap with its own bindings representing, for instance, data types
and so on?
Thinking about this, I believe it is possible to sort your returned results
using XQuery, and I think that must be your best alternative since your
function returns strings, which is what you want to display immiediately.
There is the option of further wrapping the results. I guess you have the
problem of how to sort though, i.e. on what basis. Once again I don't know,
but you may have to circumvent the whole problem with a sort of wrapper,
placing your results in a hashmap and calling a further XQuery function on
that hashmap for each result you want. If so not very pretty and leads me to
think there must be a "proper" way of doing this!
Does this make sense?

Adam

2008/9/20 Gustavo Corral <gu...@gmail.com>

> Hi list,
>
> I have some days with a problem and I hope anybody can help me. I have
> developed an extension module to search documents in an eXist collection
> using Lucene. The module works fine and returns a Sequence with all the
> documents matching a query sorted by the score of Lucene, but when I call
> the function of the module in an XQuery script, the documents don't appear
> in the same order.
>
> I have this function which take an array with the document's names as
> argument and returns a NodeSet with this documents from eXist collection:
>
> protected static NodeSet getDocuments(String[] cgDocNames, DBBroker broker)
> throws XPathException
>    {
>        //Creamos una Secuencia para almacenar los resultados
>        ExtArrayNodeSet documents = new ExtArrayNodeSet(cgDocNames.length,
> 1);
>
>        //obtiene la coleccion de reportes
>        Collection cdData =
>
> broker.getCollection(XmldbURI.create(JReportsModule.REPORTSDIRECTORY_DATA_COLLECTION));
>
>        //itera sobre los nombres de reportes
>        for(int i = 0; i < cgDocNames.length; i ++)
>        {
>            //System.out.println(cgDocNames[i]);
>
>            DocumentImpl cgDoc = cdData.getDocument(broker,
> XmldbURI.create(cgDocNames[i].substring(cgDocNames[i].indexOf("
> ")+1,cgDocNames[i].length())));
>            if(cgDoc != null){
>                //añade el reporte a la secuencia de resultados
>                documents.add(new NodeProxy(cgDoc));
>            }
>        }
>        documents.sort(true);
>        return (NodeSet) documents;
>    }
>
> In the eval function of the extension module I call this getDocuments
> function and that's the Sequence eval returns. Until this moment it seems
> the documents are in the correct order, but when I call the function of the
> extension module in an XQuery script the documents are returned in unorder.
>
> Is the description clear? because my english is not very good.
>
> Thanks
>