You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Oliver Wehrens <we...@aei.mpg.de> on 2006/03/21 16:11:52 UTC

Updating Nodes and searchindex...

Hi,

I create a Node (example here let's say a wikientry). I can find it by
searching through with

QueryManager qm = ws.getQueryManager();
Query q = 
qm.createQuery("//wiki:entry[jcr:contains(@wiki:content,'"+searchString+"')]
", Query.XPATH);
QueryResult qr = q.execute();

Very good.

If I now get (assume we just have one result) the node, change the content
to not to contain my searchString anymore with:

 NodeIterator ni = qr.getNodes();
 node = ni.nextNode();
 node.setProperty("wiki:title", title);
 node.setProperty("wiki:content", new StringValue(newValue));
 session.save();


I'm still able to find this node with my keyword although it does not
contain it anymore. Somehow this looks to my that the lucene index is not
Updated. Is there another method to update a node or do I have to update the
lucence index by myself? I'm using the svn version from 2 days ago.

It also works the other way around, if I create a node, save it, retrieve
it, and ADD a keyword, this will not be found by the searchquery, only the
initial value of a node is stored in the searchindex. I could not find
anything in the spec update the index (and I don't think I would have to
worry about that).

I'm pretty new to JSR 170 and forgive me if I'm doing something totally
stupid ;-). 

Thanks, Oliver

-- 
Oliver Wehrens
+49 170 785 1323
http://wehrens.net/oliver







Re: Updating Nodes and searchindex...

Posted by Marcel Reutegger <ma...@gmx.net>.
Hi Oliver,

Oliver Wehrens wrote:
> Hi,
> 
> I create a Node (example here let's say a wikientry). I can find it by
> searching through with
> 
> QueryManager qm = ws.getQueryManager();
> Query q = 
> qm.createQuery("//wiki:entry[jcr:contains(@wiki:content,'"+searchString+"')]
> ", Query.XPATH);
> QueryResult qr = q.execute();
> 
> Very good.
> 
> If I now get (assume we just have one result) the node, change the content
> to not to contain my searchString anymore with:
> 
>  NodeIterator ni = qr.getNodes();
>  node = ni.nextNode();
>  node.setProperty("wiki:title", title);
>  node.setProperty("wiki:content", new StringValue(newValue));
>  session.save();
> 
> 
> I'm still able to find this node with my keyword although it does not
> contain it anymore. Somehow this looks to my that the lucene index is not
> Updated. Is there another method to update a node or do I have to update the
> lucence index by myself? I'm using the svn version from 2 days ago.

This is very weird. Are you able to reproduce this behaviour with a 
simple test case?

The only thing I can imagine why your code does not work as expected is 
that the session you use to save is not the same session where you do 
your modifications. Can you please check that the query manager is 
acquired from the session that you later use to save your changes?

> It also works the other way around, if I create a node, save it, retrieve
> it, and ADD a keyword, this will not be found by the searchquery, only the
> initial value of a node is stored in the searchindex. I could not find
> anything in the spec update the index (and I don't think I would have to
> worry about that).

The spec just says that a query will only match nodes based on their 
persistent state. That means you have to save your changes first before 
a query will find it. But I assume that's what you do. Or is it possible 
that you use XA transactions? In that case the changes would only be 
visible after a commit and not right after a save.

regards
  marcel