cancel
Showing results for 
Search instead for 
Did you mean: 

Querys through JAVA (SOLVED)

rhakaro
Champ in-the-making
Champ in-the-making
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!
4 REPLIES 4

jayjayecl
Confirmed Champ
Confirmed Champ
Didn't the examples here (http://wiki.alfresco.com/wiki/Search#Simple_Queries) help you ?

rhakaro
Champ in-the-making
Champ in-the-making
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:
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.

maqsood
Confirmed Champ
Confirmed Champ
rhakaro,

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. Smiley Happy

rhakaro
Champ in-the-making
Champ in-the-making
Thank you very much, I was lost in all the possibles. I tried a code like this:
                        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!!