-
Type: Bug
-
Status: Resolved
-
Priority: Minor
-
Resolution: Fixed
-
Affects Version/s: 6.0-HF29, 7.10-HF08, 8.2
-
Fix Version/s: 8.3
-
Component/s: Core MongoDB
In class DocumentLookupSuggester, it seems that appending a * wildcard breaks the search (no result) when using a MongoDB repository.
A workaround is to define a custom suggester with the following class:
import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.lang.BooleanUtils; import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.platform.query.api.PageProvider; import org.nuxeo.ecm.platform.query.api.PageProviderService; import org.nuxeo.ecm.platform.query.nxql.CoreQueryDocumentPageProvider; import org.nuxeo.ecm.platform.query.nxql.NXQLQueryBuilder; import org.nuxeo.ecm.platform.suggestbox.service.DocumentSuggestion; import org.nuxeo.ecm.platform.suggestbox.service.Suggester; import org.nuxeo.ecm.platform.suggestbox.service.Suggestion; import org.nuxeo.ecm.platform.suggestbox.service.SuggestionContext; import org.nuxeo.ecm.platform.suggestbox.service.SuggestionException; import org.nuxeo.ecm.platform.suggestbox.service.descriptors.SuggesterDescriptor; import org.nuxeo.runtime.api.Framework; public class DocumentParameterLookupSuggester implements Suggester { protected String providerName = "DEFAULT_DOCUMENT_SUGGESTION"; protected SuggesterDescriptor descriptor; protected boolean appendWildcard = true; @Override public void initWithParameters(SuggesterDescriptor descriptor) { this.descriptor = descriptor; String providerName = descriptor.getParameters().get("providerName"); if (providerName != null) { this.providerName = providerName; } String appendWildcard = descriptor.getParameters().get("appendWildcard"); if (appendWildcard != null) { this.appendWildcard = BooleanUtils.toBoolean(appendWildcard); } } @Override public List<Suggestion> suggest(String userInput, SuggestionContext context) throws SuggestionException { PageProviderService ppService = Framework.getLocalService(PageProviderService.class); if (ppService == null) { throw new SuggestionException("PageProviderService is not active"); } Map<String, Serializable> props = new HashMap<String, Serializable>(); props.put(CoreQueryDocumentPageProvider.CORE_SESSION_PROPERTY, (Serializable) context.session); userInput = NXQLQueryBuilder.sanitizeFulltextInput(userInput); if (userInput.trim().isEmpty()) { return Collections.emptyList(); } if (!userInput.endsWith(" ") && appendWildcard) { // perform a prefix search on the last typed word userInput += "*"; } try { List<Suggestion> suggestions = new ArrayList<Suggestion>(); PageProvider<DocumentModel> pp = (PageProvider<DocumentModel>) ppService.getPageProvider( providerName, null, null, null, props, new Object[] { userInput }); for (DocumentModel doc : pp.getCurrentPage()) { suggestions.add(DocumentSuggestion.fromDocumentModel(doc)); } return suggestions; } catch (ClientException e) { throw new SuggestionException(String.format( "Suggester '%s' failed to perform query with input '%s'", descriptor.getName(), userInput), e); } } }
and the following contributions:
<require>org.nuxeo.ecm.platform.suggestbox.core.defaultSuggesters</require> <extension target="org.nuxeo.ecm.platform.suggestbox.service.SuggestionService" point="suggesters"> <suggester class="org.nuxeo.ecm.platform.suggestbox.service.suggesters.DocumentParameterLookupSuggester" name="customDocumentLookupByTitle"> <parameters> <parameter name="providerName">DEFAULT_DOCUMENT_SUGGESTION</parameter> <parameter name="appendWildcard">false</parameter> </parameters> </suggester> </extension> <require>org.nuxeo.ecm.platform.suggestbox.core.defaultSuggesters</require> <extension point="suggesterGroups" target="org.nuxeo.ecm.platform.suggestbox.service.SuggestionService"> <suggesterGroup name="searchbox"> <suggesters> <suggesterName remove="true">documentLookupByTitle</suggesterName> <suggesterName >customDocumentLookupByTitle</suggesterName> <suggesterName >searchByUsersAndGroups</suggesterName> </suggesters> </suggesterGroup> </extension>