cancel
Showing results for 
Search instead for 
Did you mean: 

exporting search results to file

kranthi
Star Contributor
Star Contributor

I want to perform operation like storing the search results to file for this we need search query from where we will get the query.After that we will pass this query into webscript.If any done with this guide me how to perform.

1 ACCEPTED ANSWER

openpj
Elite Collaborator
Elite Collaborator

You could solve this requirement in two main ways using WebScripts:

1. Implementing a DeclarativeWebScript using Alfresco JavaScript API

You can implement your JavaScript controller executing the query and then iterating results for creating a CSV or XML content file, for example you can take a look at the following snippet:

var luceneQuery = "TYPE:\"cm:content\" AND @cm\\:name:\"yourContentName*\"";

var results = search.luceneSearch(luceneQuery);

var csvOutputContent = "Name;Description"; //csv header

for (var i=0; i<results.length; i++) {

   var currentResult = results[i]; //this is the result node reference

   csvOutputContent += currentResult.name+";"+currentResults.properties["cm:description"]+"\n"; //create the single row for the CSV content

}

var outputContentNode = companyhome.createFile("report.csv"); //create the report node in the repo

outputContentNode.content = csvOutputContent; //write the content in the node

Other informations about WebScript Script controller here:

Web script controller script | Alfresco Documentation

2. Implementing a Declarative WebScript using Alfresco Java API

In this way you can implement your own Java Controller using for example Apache POI for creating any kind of Microsoft Office files such as Word or Excel and dropping it into the repository.

Java approach to web scripts | Alfresco Documentation

Hope this helps Smiley Happy

View answer in original post

6 REPLIES 6

afaust
Legendary Innovator
Legendary Innovator

If you are talking about the faceted search page (you really should provide a bit more detailed information), then you can add a custom Aikau widget which listens to the ALF_SET_SEARCH_TERM and/or ALF_ADVANCED_SEARCH topics to extract the current search term / query. Such a widget could be a button you add to the toolbar of the result list. If the user clicks that button you can use the search term / query you previously extracted from those events to call a custom web script of yours that executes the query and generates the list document in the format you require.

kranthi
Star Contributor
Star Contributor

Actually what I am trying to do is adding export search button at out of box search operation after performing the search operation who can I get the search query in search-min.js to write the java backend.

afaust
Legendary Innovator
Legendary Innovator

Which Alfresco version are you using? Because out-of-the-box search action in current Alfresco versions is not provided by search-min.js - that file was last used in 4.x as far as I know.

kranthi
Star Contributor
Star Contributor

I am using community 4.2 version

openpj
Elite Collaborator
Elite Collaborator

You could solve this requirement in two main ways using WebScripts:

1. Implementing a DeclarativeWebScript using Alfresco JavaScript API

You can implement your JavaScript controller executing the query and then iterating results for creating a CSV or XML content file, for example you can take a look at the following snippet:

var luceneQuery = "TYPE:\"cm:content\" AND @cm\\:name:\"yourContentName*\"";

var results = search.luceneSearch(luceneQuery);

var csvOutputContent = "Name;Description"; //csv header

for (var i=0; i<results.length; i++) {

   var currentResult = results[i]; //this is the result node reference

   csvOutputContent += currentResult.name+";"+currentResults.properties["cm:description"]+"\n"; //create the single row for the CSV content

}

var outputContentNode = companyhome.createFile("report.csv"); //create the report node in the repo

outputContentNode.content = csvOutputContent; //write the content in the node

Other informations about WebScript Script controller here:

Web script controller script | Alfresco Documentation

2. Implementing a Declarative WebScript using Alfresco Java API

In this way you can implement your own Java Controller using for example Apache POI for creating any kind of Microsoft Office files such as Word or Excel and dropping it into the repository.

Java approach to web scripts | Alfresco Documentation

Hope this helps Smiley Happy

kranthi
Star Contributor
Star Contributor

Actually what I am trying to do is adding export search button at out of box search operation after performing the search operation who can I get the search query in search-min.js to write the java backend.