Fulltext Search by All Properties in Node

Fulltext Search by All Properties in Node

Find nodes with mixin type 'mix:title' where any property contains 'break' string.

Repository structure:

Repository filled with different nodes with mixin type 'mix:title' and different values of 'jcr:title' and 'jcr:description' properties.

  • root
    • document1 (mix:title) jcr:title ='Star Wars' jcr:description = 'Dart rules!!'
    • document2 (mix:title) jcr:title ='Prison break' jcr:description = 'Run, Forest, run ))'
    • document3 (mix:title) jcr:title ='Titanic' jcr:description = 'An iceberg breaks a ship.'

Query execution

SQL

// make SQL query
QueryManager queryManager = workspace.getQueryManager();
String sqlStatement = "SELECT * FROM mix:title WHERE CONTAINS(*,'break')";
// create query
Query query = queryManager.createQuery(sqlStatement, Query.SQL);
// execute query and fetch result
QueryResult result = query.execute();

XPath

// make SQL query
QueryManager queryManager = workspace.getQueryManager();
// we want find 'document1'
String xpathStatement = "//element(*,mix:title)[jcr:contains(.,'break')]";
// create query
Query query = queryManager.createQuery(xpathStatement, Query.XPATH);
// execute query and fetch result
QueryResult result = query.execute();

Fetch result

Let's get nodes:

NodeIterator it = result.getNodes();

while(it.hasNext())
{
   Node findedNode = it.nextNode();
}

NodeIterator will return "document1" and "document2".

We can also get a table:

String[] columnNames = result.getColumnNames();
RowIterator rit = result.getRows();
while (rit.hasNext())
{
   Row row = rit.nextRow();
   // get values of the row
   Value[] values = row.getValues();
}

Table content is:

jcr:titlejcr:description...jcr:path
Prison break.Run, Forest, run )).../document2
TitanicAn iceberg breaks a ship..../document3
Tags:
Created by Sergey Karpenko on 10/07/2009
Last modified by Sören Schmidt on 12/03/2009

Products

generated on Fri Jul 30 18:53:00 UTC 2010

eXo Optional Modules

eXo Core Foundations


Copyright (c) 2000-2010. All Rights Reserved - eXo platform SAS
2.4.30451