cancel
Showing results for 
Search instead for 
Did you mean: 

lucene in java

gokceng
Champ in-the-making
Champ in-the-making
hi everyone,
i did a lucene search in javascript in alfresco.
I've constructed a search string and




model.searchString = searchString;

var results = search.luceneSearch(searchString);
model.documents = results;

was enough. But in java side how can i do that?  I've seen some codes for lucene search in Java.
Under org.alfresco.service.cmr.search.searchservice some functions exists for search process named query:

ResultSet   query(SearchParameters searchParameters)
          Search using the given SearchParameters
ResultSet   query(StoreRef store, QName queryId, QueryParameter[] queryParameters)
          Execute a canned query
ResultSet   query(StoreRef store, java.lang.String language, java.lang.String query)
          Search against a store.
ResultSet   query(StoreRef store, java.lang.String language, java.lang.String query, QueryParameterDefinition[] queryParameterDefintions)
          Search against a store.

for the 3rd query function: is query parameter of that function same of the search string constructed in javascript side or do i need to generate a new one? Also for Company Home\abc space what will be the my storeRef parameter?
4 REPLIES 4

rliu
Champ in-the-making
Champ in-the-making
The query parameter should resemble the syntax referenced here. I'm not sure about the JavaScript side of things as I've tried to stay away from server side JavaScript.

gokceng
Champ in-the-making
Champ in-the-making
hi thanks for reply,
I've found the solution:
after constructing the search string saying
model.searchstring = searchString;

and then in a different place I could call
myFunction(searchstring);

this myFunction is a function that i wrote in Java. Now i'm able to use searchstring that I've constructed in javascript, in Java side. As a result it is the same string that you use in:

var results = search.luceneSearch(searchString);  //javascript

results = serviceRegistry.getSearchService().query(companyHome.getStoreRef(), "lucene", searchString);    //Java

May it helps others…

sgomez
Champ in-the-making
Champ in-the-making
Hi gokceng (and rliu),

Do you know what the difference would be to using java-search versus javascript-search?  It seems if we prepared the search string before we even reach server side, will it even matter? 

I'm asking because I am not sure where I should parse my search query while still on the front end or send everything to server (most likely as JSON) and parse query from there.

Thanks,
sgomez

openpj
Elite Collaborator
Elite Collaborator
Javascript API is a server-side implementation that Alfresco implemented with Mozilla Rhino.
This means that whenever you invoke a Javascript search, in the Alfresco back-end will be invoke the Java Search service of Alfresco.

So the Alfresco Javascript API is a wrapper of the Alfresco Java API, but you don't have all the methods and objects scope with all the capabilities of the Java API.

Javascript API is a wrapper of a subgroup of functionality available in the Java API.

Another difference is that in Javascript whenever you would like to invoke a search, you need to escape special characters two times for your query ("\\").
Otherwise if you are using Java API you need only to escape special character one time ("\").

Hope this helps.