cancel
Showing results for 
Search instead for 
Did you mean: 

Advanced search

jordiv
Champ on-the-rise
Champ on-the-rise
Hi,

Anyone knows if there is an easy way to create an advanced search for a Web Quick Start website?
I would like to have a search form where I could search documents using custom metadata fields.

I suppose that this should be done using a webscript, but I don't know how to launch a search query in the .js file.
Any help will be appreciated.


Thanks,
Jordi.
13 REPLIES 13

bremmington
Champ on-the-rise
Champ on-the-rise
Do you get anything back if you point your browser directly at your advsearch webscript?

jordiv
Champ on-the-rise
Champ on-the-rise
Testing the advsearch webscript I realised that was returning a 401 error.

I've solved it by calling the webscript with the guest=true parameter:

var data = connector.get("/mysearch/advsearch?guest=true&q=" + url.args['phrase']);

I can get the response to my WQS webscript! Thanks a lot bremmington Smiley Happy

Now I'll try to build the lucene query with my custom metadata. When I finish I'll post it here.

jordiv
Champ on-the-rise
Champ on-the-rise
Done  Smiley Happy
Just an update about this.

I had some more problems because I needed to call the repository webscript being authenticated.
To do it I used an alf_ticket. So the call to my repository webscript from the WQS webscript is:


var connector = remote.connect("alfresco");
  // Get an XML ticket to authenticate
  var raw_ticket = connector.get("/api/login?u=USER_NAME&pw=USER_PASSWORD");
  raw_ticket = raw_ticket.toString();
  var string_from = raw_ticket.indexOf("<ticket>");
  var string_to = raw_ticket.indexOf("</ticket>");
  // Get only the content inside <ticket> tag
  var ticket = raw_ticket.substring(string_from + 8, string_to);
  // URL to the advsearch webscript
  var s_url = "/mysearch/advsearch.html?alf_ticket=" + ticket + "&guest=false";

  // Append the parameters…
  if(var1 != null) s_url += "&var1=" + encodeURI(var1);
  // …

  // Call the webscript
  var data = connector.get(s_url);

And to query by custom metadata, I did it like this in the lucene query:

+@myaspect\\:myMetadata:(' + var1 + ')

I made a small tutorial with all the steps I followed.


Cheers,
Jordi.

bremmington
Champ on-the-rise
Champ on-the-rise
Excellent. Well done! Thanks for posting an update back here  Smiley Happy