Hello,

I've run into another problem in my program. After fixing the Seam issues I had
asked about earlier, I had a problem running my search properly. I decided from
the beginning that I want to run searches for my "keyword" type under the NXQL
requests. When I found the NXQL search at the bottom of the Advanced Search 
page, I thought I could take the method it used - 
SearchActionsBean.performSearch(), to be exact - I thought I could replicate 
the
feature when searching for documents with a particular keyword. A user would 
type in a keyword and hit the search button, MyFileManagerBean would append 
that
to the end of an NXQL request, and perform the proper method calls, resulting 
in
the results shown on search_results_nxql.xhtml.

The Bean accepted the query on the first attempt. But when I got to the results
page, I got a search query error that went like this:

======

ERROR [QueryModel] sorted query failed: SELECT * FROM Document WHERE
ecm:fulltext LIKE '' AND
     ecm:mixinType != 'HiddenInNavigation' AND
     ecm:isCheckedInVersion = 0 AND
     ecm:currentLifeCycleState != 'deleted'
org.nuxeo.ecm.core.search.api.client.SearchException: org.nuxeo.ecm.core.api.
client.SearchException: org.nuxeo.ecm.core.api.WrappedException: Exception: org
.nuxeo.ecm.core.search.api.client.query.QueryException. message: Failed to
parse query [all:()]: nested exception is org.apache.lucene.queryParser.ParseEx
ception: Encountered ")" at line 1, column 5.
Was expecting one of:
    <NOT> ...
    " +" ...
    " - " ...
    "(" ...
    <QUOTED> ...
    <TERM> ...
    <PREFIXTERM> ...
    <WILDTERM> ...
    "[" ...
    "{" ...
    <NUMBER> ...

======

The query they gave me was not the query I create in the method. I even tested
it out on the NXQL line in the Advanced Search page, and it worked perfectly.
When I ran the method, I'd ask the log to print out my results on the terminal,
and it outputted properly, so I know that my portion is working. I've
discovered the error occurs on this line:

resultsProvider = resultsProvidersCache.get(PROV_NXQL);

I took that line of code from the SearchActionsBean's performSearch() method, 
and since my NXQL request works with regular NXQL searches from the Advanced 
Search page and SearchActionBean, I figured something obscure was causing a 
problem. Something I might have forgotten to add or am unaware of including.

The source code is below - how would I fix it to prevent the error from
occuring as well as performing successful NXQL searches?

Thanks,

Chris

=======

import javax.ejb.PostActivate;
import javax.ejb.PrePassivate;
import javax.ejb.Remove;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.contexts.Context;
import org.jboss.seam.core.FacesMessages;
import org.nuxeo.ecm.core.api.ClientException;
import org.nuxeo.ecm.core.api.CoreSession;
import org.nuxeo.ecm.core.api.PagedDocumentsProvider;
import org.nuxeo.ecm.core.search.api.client.SearchService;
import org.nuxeo.ecm.core.search.api.client.query.ComposedNXQuery;
import org.nuxeo.ecm.core.search.api.client.search.results.ResultSet;
import 
org.nuxeo.ecm.core.search.api.client.search.results.document.SearchPageProvider
;
import org.nuxeo.ecm.platform.ui.web.api.NavigationContext;
import org.nuxeo.ecm.platform.ui.web.api.SortNotSupportedException;
import org.nuxeo.ecm.platform.ui.web.api.WebActions;
import org.nuxeo.ecm.platform.util.ECInvalidParameterException;
import org.nuxeo.ecm.webapp.helpers.ResourcesAccessor;
import org.nuxeo.ecm.webapp.pagination.ResultsProvidersCache;
import org.nuxeo.runtime.api.Framework;

@Scope(ScopeType.CONVERSATION)
@Name("myFileManager")
public class myFileManagerBean {
    private static final Log log = 
        LogFactory.getLog(myFileManagerBean.class);

    @PrePassivate
    public void prePassivate() {
        log.debug("prePassivate");
    }

    @PostActivate
    public void postActivate() {
        log.debug("postActivate");
    }

    @Remove
    @Destroy
    public void destroy() {
        log.debug("destroy");
    }

    private static final String ACTION_PAGE_SEARCH_NXQL = 
            "search_results_nxql";

    private static final String PROV_NXQL = "SEARCH_BEAN_NXQL_PROVIDER";

    private static final String ACTION_PAGE_SEARCH_QUERY_ERROR = null;

    private static final String ACTION_PAGE_SEARCH_NO_KEYWORDS = null;

    private String queryErrorMsg;

    @In(required = false, create = true)
    private transient ResultsProvidersCache resultsProvidersCache;

    @In(create = true)
    private transient Context conversationContext;

    @In(create = true)
    protected transient NavigationContext navigationContext;

    @In(create = true)
    protected transient WebActions webActions;

    @In(create = true)
    protected transient CoreSession documentManager;

    @In(create = true)
    protected transient FacesMessages facesMessages;

    @In(create = true)
    protected transient ResourcesAccessor resourcesAccessor;

    private String keyword;

    public String getKeyword() {
        if (keyword == null) {
            keyword="";
        }
        return keyword;
    }

    public void setKeyword(String k) {
        keyword = k;
    }

    public String performSearch() throws ClientException,
                ECInvalidParameterException {
        if (log.isDebugEnabled()) {
            log.debug("performing searchType: NXQL");
        }
        try {
            String page;
            PagedDocumentsProvider resultsProvider = null;
            if (tag == null) {
                log.warn("Tagging search: no tag query has been provided");
                return ACTION_PAGE_SEARCH_NO_KEYWORDS;
            }

            String nxql = new String("SELECT * FROM myFile WHERE ht:keywords ="
                                    +" '" + keyword + "'");
            log.info("Search query: " + nxql);
            log.debug("Query: " + nxql);
            resultsProvidersCache.invalidate(PROV_NXQL);
            resultsProvider = resultsProvidersCache.get(PROV_NXQL);
            page = ACTION_PAGE_SEARCH_NXQL;
            if (resultsProvider instanceof SearchPageProvider) {
                String lastQuery = ((SearchPageProvider) 
                        resultsProvider).getQuery();
                conversationContext.set("search.lastQuery", lastQuery);
            } else {
                conversationContext.set("search.lastQuery", null);
            }

            return page;
        } catch (SortNotSupportedException e) {
            queryErrorMsg = e.getMessage();
            log.debug("Search error " + e.getMessage(), e);
            return ACTION_PAGE_SEARCH_QUERY_ERROR;
        } catch (ClientException e) {
            queryErrorMsg = e.getMessage();
            log.debug("Search error: " + e.getMessage(), e);
            return ACTION_PAGE_SEARCH_QUERY_ERROR;
        }
    }


    //this method is not in use
    public ResultSet getSearchResults() throws Exception {
        SearchService searchService = 
            Framework.getService(SearchService.class);
        ComposedNXQuery query = new ComposedNXQueryImpl("SELECT * FROM myFile"
                                                       +" WHERE ht:keywords ="
                                                       +" '" + keyword + "'");
        ResultSet resultSet = searchService.searchQuery(query, 0, 10);
        return resultSet;
    }
}

_______________________________________________
ECM mailing list
[email protected]
http://lists.nuxeo.com/mailman/listinfo/ecm

Reply via email to