Querys through JAVA (SOLVED)
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2009 02:58 PM
Hello everyone, firstly, sorry for repeating theme if it is already asked.
The problem is that I need to search from a Java program to Content in Alfresco. I must say that the only thing I have made are references to nodes, upload and download files.
I've been all afternoon reading the wiki, this forum (in English and Spanish) and I don´t know how to reference metadata in searches. I must be a little awkward.
I found some code, but I have lot of problems to understand it and make it run without errors.
I need a simple example of a query, wich I can use to make my code.
I thank you for help, bye!
The problem is that I need to search from a Java program to Content in Alfresco. I must say that the only thing I have made are references to nodes, upload and download files.
I've been all afternoon reading the wiki, this forum (in English and Spanish) and I don´t know how to reference metadata in searches. I must be a little awkward.
I found some code, but I have lot of problems to understand it and make it run without errors.
I need a simple example of a query, wich I can use to make my code.
I thank you for help, bye!
Labels:
- Labels:
-
Archive
4 REPLIES 4

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2009 03:44 AM
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2009 07:10 AM
Hi JayJayECL, thanks for ask me.
Yes, this wiki helps me writing querys with Lucene, but my problem is to bring it to my Java code.
Now I have this code:
In "rows" I have all the Content, but now I don´t know how to access to information.
I read in this forum, someone who do something like:
But I don´t know what is a "ContentResult"???? In eclipse, it seems to not be in the Alfresco libraries. What happend with that Object?? What pakage is from??
Thanks in advance.
Yes, this wiki helps me writing querys with Lucene, but my problem is to bring it to my Java code.
Now I have this code:
RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService(); String searchText = "my_node_and_query_to_use_for_example"; // Create a query object, looking for all items with alfresco in the name of text Query query = new Query(Constants.QUERY_LANG_LUCENE, "PATH:\"/app:company_home/cm:" +searchText +"//*\""); // Execute the queryfinal Store STORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore"); QueryResult queryResult = repositoryService.query(STORE, query, false); // Display the resultsResultSet results = queryResult.getResultSet();ResultSetRow[] rows = results.getRows();
In "rows" I have all the Content, but now I don´t know how to access to information.
I read in this forum, someone who do something like:
for(ResultSetRow row : rows){ ResultSetRowNode nodo = rows[i].getNode(); String nodeId = row.getNode().getId(); ContentResult contentResult = new ContentResult(nodeId); …. ….}
But I don´t know what is a "ContentResult"???? In eclipse, it seems to not be in the Alfresco libraries. What happend with that Object?? What pakage is from??
Thanks in advance.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2009 07:24 AM
rhakaro,
You can use the below code to access the row contents:
Hope it helps you.
In "rows" I have all the Content, but now I don´t know how to access to information.
You can use the below code to access the row contents:
if (rows != null) { for (int x = 0; x < rows.length; x++) { ResultSetRow row = rows[x]; NamedValue[] columns = row.getColumns(); for (int y = 0; y < columns.length; y++) { System.out.println("row " + x + ": " + row.getColumns(y).getName() + " = " + row.getColumns(y).getValue()); } } }
Hope it helps you.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2009 09:49 AM
Thank you very much, I was lost in all the possibles. I tried a code like this:
To see what was inside rows…
I was really blind with this.
Thank you!!
ResultSetRowNode nodo = rows[i].getNode(); System.out.println("Type: " + nodo.getType()); System.out.println("\tRecorrido de aspects:"); String[] a = nodo.getAspects(); for(int j=0; j<a.length; j++) System.out.println("\t\t" + j + ": " +a[j]); System.out.println("\tIdentificador: " + nodo.getId()); System.out.println("\tCampos typeDesc:"); FieldDesc[] b = nodo.getTypeDesc().getFields(); for(int z=0; z<b.length; z++) System.out.println("\t\t" + z + b[z].getFieldName());
To see what was inside rows…
I was really blind with this.
Thank you!!
