On 09/09/2009 2:01:09 AM, "Jan Haderka" <[email protected]> wrote:
It might help if you could provide details on how exactly did you
perform your tests in Magnolia (did you run xpath query in the
Tools/Query in the AdminCentral, or did you use query manager? ... the
snippet of code perhaps?).
Here is the code that performs the search.
>From my page bean/controller:
long index = start;
if ( position > 0 ) index = position;
searchResult = authorDAO.nameSearch( clause, session,
( index > 0 ) ? index + 1 : 0 );
builder.append( "<ul>" );
for ( final Node node : searchResult.results )
{
createLink( builder, node );
}
builder.append( "</ul>" );
Here is the nameSeach implementation:
public SearchResult nameSearch( final String term, final Session session,
long... indices ) throws RepositoryException
{
final long start = currentTimeMillis();
final QueryManager qm =
sessionFactory.getSession().getWorkspace().getQueryManager();
final String query = format( "//*[jcr:contains(@%s, '%s') and @%s = '%s']",
DISPLAY_NAME, term, NODE_TYPE, AUTHOR_PREFIX );
final Query q = qm.createQuery( query, Query.XPATH );
final QueryResult result = q.execute();
final long end = currentTimeMillis();
System.out.format( "Query time: %g%n", ( end - start ) / 1000.0 );
return getResult( result.getNodes(), indices );
}
protected SearchResult getResult( final NodeIterator iter,
final long... indices ) throws RepositoryException
{
final long s = System.currentTimeMillis();
final ArrayList<Node> collection =
new ArrayList<Node>( getModule().getPageSize() );
final long start = ( indices.length > 0 ) ? indices[0] : 0;
final long end = ( indices.length > 1 ) ? indices[1] :
start + getModule().getPageSize();
iter.skip( start );
long count = start;
while ( iter.hasNext() )
{
collection.add( iter.nextNode() );
if ( ++count >= end ) break;
}
final long e = System.currentTimeMillis();
System.out.format( "Search time: %g seconds %n", ( e - s ) / 1000.0 );
return new SearchResult( collection, start, iter.getPosition(),
iter.getSize() );
}
The SessionFactory.getSession is implemented as:
public Session getSession()
{
HierarchyManager manager = MgnlContext.getHierarchyManager(
getModule().getRepository() );
Workspace ws = manager.getWorkspace();
return ws.getSession();
}
My initial suspicion was that MgnlContext.getHierarchyManager(
getModule().getRepository() ) is perhaps expensive and I need to cache that. I
will try that out.
Thanks
Rakesh
----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------