cancel
Showing results for 
Search instead for 
Did you mean: 

Trigger search via Webscript

kingkong
Champ in-the-making
Champ in-the-making
Hi,

is it possible to trigger the search (e.g. via Lucene) from a custom HTML page?
If yes, how can I do that? Is there a webscript that I can call with a search parameter e.g. for the document title that returns a json with all documents that match my search string?

Thanks in advance!

Kind regards

KingKong
4 REPLIES 4

gawadesk
Star Contributor
Star Contributor
Yes you can perform Lucene search by using Scripting API provided by Alfresco.



var nodes = search.luceneSearch("TEXT:alfresco");


 
You can provide additional filter to search like sort, column mentioned in this <a herf="http://docs.alfresco.com/5.1/references/API-JS-luceneSearch.html"> Document </a>

kingkong
Champ in-the-making
Champ in-the-making
Thanks a lot for your answer!!

I found another possibility, maybe you could help me with this?
/alfresco/service/slingshot/search?term={term?}&tag={tag?}&site={site?}&container={container?}&sort={sort?}&query={query?}&repo={repo?}

As far as I understand, it should return a json containing all information about documents matching the search.
Could you please give me an example of how to fill the parameters in such a way, that the search is working correctly?
I tried different things, but the script is not working.

It would be great if you could just 'build' an example URL.

Thank you very much in advance!!

Kind regards

KingKong

gawadesk
Star Contributor
Star Contributor
Yes, your understanding is correct.  This web script returns result in json format. Here is one example containing result.

http://127.0.0.1:8080/alfresco/s/slingshot/search?term=tulips&site=testside



{
   "totalRecords": 2,
   "totalRecordsUpper": 2,
   "startIndex": 0,
   "numberFound": 2,
   "facets":
   {
      "@{http:\/\/www.alfresco.org\/model\/content\/1.0}content.size":
      [
      ],
      "@{http:\/\/www.alfresco.org\/model\/content\/1.0}modified":
      [
      ],
      "@{http:\/\/www.alfresco.org\/model\/content\/1.0}created":
      [
      ]
   },
   "items":
   [
      {
         "nodeRef": "workspace:\/\/SpacesStore\/f0910cbb-9f2b-42f2-a944-53a21400e1a6",
         "type": "document",
         "name": "Tulips.jpg",
         "displayName": "Tulips.jpg",
         "title": "",
         "description": "",
         "modifiedOn": "2016-08-16T11:51:07.071+05:30",
         "modifiedByUser": "admin",
         "modifiedBy": "Administrator ",
         "size": 620888,
         "mimetype": "image\/jpeg",
         "site":
         {
            "shortName": "testside",
            "title": "testside"
         },
         "container": "documentLibrary",
         "path": "MyFolder",
         "lastThumbnailModification":
         [
          "doclib:1471328433680"
          ,
          "imgpreview:1471328436433"
         
         ],
         "tags": ["pic"]
      },
      {
         "nodeRef": "workspace:\/\/SpacesStore\/49a7fc66-aa51-4d37-bd67-cf162937fc58",
         "type": "document",
         "name": "Tulips.jpg",
         "displayName": "Tulips.jpg",
         "description": "",
         "modifiedOn": "2016-08-16T11:54:18.561+05:30",
         "modifiedByUser": "admin",
         "modifiedBy": "Administrator ",
         "size": 620888,
         "mimetype": "image\/jpeg",
         "site":
         {
            "shortName": "testside",
            "title": "testside"
         },
         "container": "documentLibrary",
         "path": "OtherFolder",
         "lastThumbnailModification":
         [
          "doclib:1471328659013"
         
         ],
         "tags": []
      }
   ],
   "spellcheck":
   {
   }
}



So all search parameters are not mandatory. Parameters will get change as per your search criteria.

In above example I am searching all documents which contains term 'tulips' and which are belongs to only with site 'testside'  likewise you can have your parameter depending on your need.

Here is brief about each parameter :

term : Text which you want to search.
tag : tag name for which associated document you want search.
site : name of site to restrict search for particular site.
container : restrict search for particular container (e.g. documentLibrary)
repo : true, in case you want to get result from repository.
sort : order of sort

Let me know if this is helpful. If you search not fitting above criteria then let me know so I can help you further.

kingkong
Champ in-the-making
Champ in-the-making
Thank you very much. This was really helpful.
I have some further questions. What do you mean by 'in case you want to get results form repository' (for the repo parameter)?
And is it possible to search document / folder titles or names only? If I understand it correctly, term is used to do a fulltext search?

Thank you very much in advance!

Regards

KingKong