RE: How to search documents other than published

thumbnail
Marco Azzalini, modified 7 Years ago. Regular Member Posts: 146 Join Date: 11/18/14 Recent Posts
In Liferay 6.2, I need to make some users (that are also Portal Content reviewer) be able to search for documents with status different from published (for example, Expired, Incomplete, etc). The search portlet by default inserts +(status:0) in all queries, so only published entries are returned.
I have an hook for the FileEntry indexer
public class MyFileEntryIndexerPostProcessor extends BaseIndexerPostProcessor {
  @Override
      public void postProcessContextQuery(BooleanQuery booleanQuery, SearchContext sc) throws Exception {
  }


but I can't modify the booleanQuery object, removing unwanted clause on the status.... well, I can remove clauses from the collection (booleanQuery.clauses()) but it is useless, the underlying query doesn't change.
How can I modify the generated query?

Thanks, in advance,
Marco
thumbnail
Andrew Jardine, modified 7 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hi Marco,

I might be able to help with this one but I have a couple of questions.

1. When you say that they are able to search, do you mean they are searching in the control panel? or are they searching in the main site (using the search portlet)?

2. Are they using the search portlet or the web content search portlet?
thumbnail
Marco Azzalini, modified 7 Years ago. Regular Member Posts: 146 Join Date: 11/18/14 Recent Posts
Andrew Jardine:
Hi Marco, I might be able to help with this one but I have a couple of questions. 1. When you say that they are able to search, do you mean they are searching in the control panel? or are they searching in the main site (using the search portlet)? 2. Are they using the search portlet or the web content search portlet?

Hi Andrew, sorry for the delay.... too much work and stuff to do!! :-)

My users are searching documents through the Search Portlet but, in the meantime, I solved my problem.

Here the solution,  if it could help someone else...

Looking at the source code of the BaseIndexer I noted the method addStatus and the solution has come easily ;-)

 

protected void addStatus(BooleanQuery contextQuery, SearchContext searchContext) throws Exception {
....
if (<strong>status != WorkflowConstants.STATUS_ANY</strong>) {
   contextQuery.addRequiredTerm(Field.STATUS, status);
} else {
   BooleanQuery statusQuery = BooleanQueryFactoryUtil.create(searchContext);
   statusQuery.addTerm(Field.STATUS, WorkflowConstants.STATUS_IN_TRASH);
   contextQuery.add(statusQuery, BooleanClauseOccur.MUST_NOT);
}

 

Has been sufficient to insert Field.STATUS=WorkflowStatus.STATUS_ANY  in the SearchContext in the main_search.jspf page

Indexer indexer = FacetedSearcher.getInstance();
if (specialUser) {
    searchContext.setAttribute(Field.STATUS, WorkflowConstants.STATUS_ANY);
}
Hits hits =   indexer.search(searchContext);

 

and the Search Portlet now find all documents, as I need.

Anyway now I have a different problem :-) because the new documents are not indexed until they reach the Approved state so the question is: how to make a document get indexed just after it is inserted in the DL? 

Regards,
Marco