Search code examples
javasearchmetadataliferay-6

search contents with metadata in liferay


I want to search contents in a document and media portlet using custom metadata,currently I am searching the contents with following code:

            Query queryutil = StringQueryFactoryUtil.create(queryToSearch);
            long folderids = projectsFolder.getFolderId();
            Sort[] defaultsorts = SortFactoryUtil.getDefaultSorts();
            SearchContext search = new SearchContext();
            search.setAttribute("paginationType", "regular");
            search.setEnd(-1);
            List<Long> ids = new ArrayList<Long>();
            ids.add(projectsFolder.getFolderId());
            search.setFolderIds(ids);
            search.setIncludeDiscussions(true);
            search.setKeywords("title:abc.png");
            search.setCompanyId(companyid);
            QueryConfig queryConfig = new QueryConfig();
            queryConfig.setHighlightEnabled(true);
            queryConfig.setSearchSubfolders(false);
            search.setQueryConfig(queryConfig);
            search.setStart(-1);
            Hits hits = DLAppServiceUtil.search(scopeid, search);

hits is returning me total number of search contents but I want the same mechanism with custom metadata search .If I type in the search bar of document and media portlet of liferay with keywords title:admin* or content:test it will show all the contents with title containing admin and have content with test. My point of interest is how to search contents with custom metadata or what keyword is used by liferay to search contents with metadata in document and media portlet of liferay.


Solution

  • I solved my problem: the key point to solve this problem is you have to associate the metadata with the required document type than the above mention code can search the required metadata other wise it is not possible,no keywords is required to access the metadata in document and media portlet just associate the metadata with the contents results will be in front of you.