Question

For search i use liferay-ui:search in the dockbar. User should be able to define search scope (specific private page) by choosing it from dropdown list.

How can i implement search on specific private page?

And 1 more question. Seems it's a bug, but user is able to search only while he is on specific private page. If he move to another page - search button is "disabled" - nothing happens when he clic it. For admin account everything works fine - i am able to search being on any page.

Thanks!

Was it helpful?

Solution

OK. 1st step was to place hook on [b]html/taglib/search/start.jsp[/b]. I passed an extra id parameter to define on which private page i gonna search.

<input name="<%= namespace %>keywords" size="30" title="<liferay-ui:message key="search" />" type="text" value="<%= HtmlUtil.escapeAttribute(keywords) %>" />
<input name="<%= namespace %>groupid" value="0" type="hidden" />

<select name="<%= namespace %>scopeId" title="<liferay-ui:message key="scope" /> ">
    <option value="0" <%= selected == 0 ? "selected" : ""%>><liferay-ui:message key="everything" /></option>
    <option value="1" <%= selected == 1 ? "selected" : ""%>>Новости</option>
    <option value="2" <%= selected == 2 ? "selected" : ""%>>Сотрудники</option>
    <option value="3" <%= selected == 3 ? "selected" : ""%>>Новому сотруднику</option>
    <option value="4" <%= selected == 4 ? "selected" : ""%>>Корпоративные правила</option>
    <option value="5" <%= selected == 5 ? "selected" : ""%>>Продукты</option>
    <option value="6" <%= selected == 6 ? "selected" : ""%>>Wiki</option>
    <option value="7" <%= selected == 7 ? "selected" : ""%>>События</option>
    <option value="8" <%= selected == 8 ? "selected" : ""%>>Форум</option>
</select>

2nd step was to hook on [b]html/portlet/search/main_search.jsp[/b]. There i was going to filter [b]ALL[/b] search results and display only those which needed by request from [b]select field[/b]. It's OK for non instanceble custom portlets with have different id, i just filter by portletId and display result.

Hits hits = indexer.search(searchContext);

List<Document> documents = new ArrayList<Document>();
documents = hits.toList();
...
if (documents.size() != 0) {
    List<Document> toDelete = new ArrayList<Document>();
    for (Document document : documents) {
                String id = document.getPortletId();
        id = document.get(Field.PORTLET_ID);

        switch (scopeId) {
            case 0:
                break;
            case 1:
                if (!id.equals(NEWS_PORTLET_ID)) {
                    toDelete.add(document);
                }
                break;
                        ....

                if (toDelete.size() != 0) {
        documents.removeAll(toDelete);      
        hits.setDocs(documents.toArray(new Document[documents.size()]));
        if (documents.size() == 0) {
            hits.setLength(0);
        }
    }

All fine. But 3 of my pages all have asset publisher portlet (portletId = 15), so if i filter by portlet id - i will get results from all 3 pages. Maybe i can get instance id of portlet which document belongs to. Or maybe there is some other way to do search.

Atm i try to implement my CustomJournalArticleIndexer. The idea is Indexer adds field containing portlet's instance id. So later in main_search.jsp i can do something like document.getPortletInstanceId and compare it with a constant paired with scopeId of my request.

Any suggestions here? Thanks and... from Russia with love!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top