Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Lucene: Java-User

eXist, Lucene and XQuery

 

 

Lucene java-user RSS feed   Index | Next | Previous | View Threaded


gustavo.corral at gmail

Sep 20, 2008, 2:10 PM

Post #1 of 4 (274 views)
Permalink
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


adam.saltiel at gmail

Sep 22, 2008, 2:20 AM

Post #2 of 4 (243 views)
Permalink
Re: eXist, Lucene and XQuery [In reply to]

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 <gustavo.corral[at]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
>


gustavo.corral at gmail

Sep 22, 2008, 7:40 AM

Post #3 of 4 (242 views)
Permalink
Re: eXist, Lucene and XQuery [In reply to]

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


adam.saltiel at gmail

Sep 22, 2008, 4:26 PM

Post #4 of 4 (238 views)
Permalink
Re: eXist, Lucene and XQuery [In reply to]

OK, right, that figures.

Adam

2008/9/22 Gustavo Corral <gustavo.corral[at]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
>

Lucene java-user RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.