cancel
Showing results for 
Search instead for 
Did you mean: 

How to search metadata of documents

mohan_jha23
Champ in-the-making
Champ in-the-making
Hi All,

I am new to alfresco, I need to search metadata (like Filetitle) of documents stored in alfresco. Is there any rest API for this or I need to write the web script for this. If I need to write the web script then please tell how to write the web script for the same.

Thanks in advance,

Mohan
8 REPLIES 8

rliu
Champ in-the-making
Champ in-the-making
If you're looking to search on a specific field, yes, then you'll have to write a custom webscript. Their may be other ways of doing it, but I had to construct a Java-backed controller and utilize the SearchService with Lucene query to achieve the desired functionality.

mohan_jha23
Champ in-the-making
Champ in-the-making
Thanks for your reply,yes I am looking to search on a specific field(like author,title,description).Can You share with me how to write the custom webscript to use SearchService with Lucene query for achieving the desired functionality.

Thanks,

Mohan

lista
Star Contributor
Star Contributor
A good place to start:

http://wiki.alfresco.com/wiki/Web_Scripts
http://wiki.alfresco.com/wiki/Java-backed_Web_Scripts_Samples

In general, always take a look at the Wiki, it's really helpful.

Cheers!

tonyc
Champ in-the-making
Champ in-the-making
I have just made a custom search web script and had struggled so let me help a  little…

assuming your search term is args.query and you want to search on the title of content, the js could be something along these lines..

query = '+@cm\\:title:\"' + args.query + '"';
var results = search.luceneSearch(query);
model.results = results;

You may or may not have realized how finicky lucene syntax is, it took me a bit to grasp.  But it is quite easy once you are used to it.
Hope that helps! Good Luck

rliu
Champ in-the-making
Champ in-the-making
I agree with tonyc. Lucene query syntax is not very forgiving. Most of search errors were due to improper use of the right query and its respective syntax.

jenim
Champ in-the-making
Champ in-the-making
var def =
    {
     query: "+@cm\\:title:" + args.keyword,
     store: "workspace://SpacesStore",
     language: "Lucene",
     locale: "BG_"
    };
    var results = search.query(def);

It works for me.

francoist
Champ in-the-making
Champ in-the-making
Hi, firstly, thank you very much for this post, it has helped a lot.

One question though - what would be in the variable "results" after the search has been performed?

invictus9
Champ in-the-making
Champ in-the-making
Hi, firstly, thank you very much for this post, it has helped a lot.

One question though - what would be in the variable "results" after the search has been performed?
I'm pretty sure that you get a list of nodes that match the query.

Another point to note: Always clean up your search terms before constructing the Lucene query. If you have stray quotes, or strops, you may end up with something that is not what was intended. Ideally, the Alfresco library would have a luceneCleanUp() function to make sure you can pass the data in without mishap.