Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Star Invader
Custom search from 6.0.6 to 6.1
April 24, 2012 4:31 AM
Answer

Star Invader

Rank: New Member

Posts: 18

Join Date: September 26, 2011

Recent Posts

Hello, i was having a custom portlet with search capabilities working fine on liferay 6.0.6

I have installed that portlet into liferay 6.1.0-ce-ga1 and everything seems to work fine, but when I make a search I get no results for my custom portlet (show opensearch results is activated)

For being able to use my old custom opensearch class extending HistOpenSearchImpl I have to add a method called getIndexer() becouse with liferay 6.0.6 it was not needed

Any help or example would be appreciated

I have spent a lot of time looking at liferay source code for examples but nothing seems to help
Jan Geißler
RE: Custom search from 6.0.6 to 6.1
April 24, 2012 4:41 AM
Answer

Jan Geißler

Community Moderator

Rank: Liferay Master

Posts: 735

Join Date: July 5, 2011

Recent Posts

the Api changed somehow on the Indexer Interface.
you have to implement:

doGetSummary and so on.
Short example:

public Summary getSummary(Document document, String snippet,PortletURL portletURL)
^^ 6.0.6 Method
Interface says:
@Override
protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) throws Exception

so I just did:
return getSummary(document, locale, snippet, portletURL);


  1
  2public class OrganisationProfileIndexer extends BaseIndexer {
  3
  4     public static final String[] CLASS_NAMES = {OrganisationProfile.class.getName()};
  5
  6     public static final String PORTLET_ID = WebKeys.PORTLET_ID;
  7    
  8    /*
  9     * (non-Javadoc)
 10     *
 11     * @see
 12     * com.liferay.portal.kernel.search.Indexer#getSummary(com.liferay.portal
 13     * .kernel.search.Document, java.lang.String, javax.portlet.PortletURL)
 14     */
 15    public Summary getSummary(Document document, String snippet,
 16            PortletURL portletURL) {
 17        String title = document.get(Field.TITLE);
 18        String content = snippet;
 19        if (Validator.isNull(snippet)) {
 20            content = document.get(Field.DESCRIPTION);
 21            content += StringUtil.shorten(document.get(Field.CONTENT), 400);
 22            if (Validator.isNull(content)) {
 23                content = StringUtil.shorten(document.get(Field.CONTENT), 400);
 24            }
 25        }
 26        String resourcePrimaryKey = document.get(Field.ENTRY_CLASS_PK);
 27        portletURL.setParameter("jspPage", "/jsp/view_profile");
 28        portletURL.setParameter("jspresourcePrimKey", resourcePrimaryKey);
 29        return new Summary(title, content, portletURL);
 30    }
 31
 32    /*
 33     * (non-Javadoc)
 34     *
 35     * @see
 36     * com.liferay.portal.kernel.search.BaseIndexer#doDelete(java.lang.Object)
 37     */
 38    @Override
 39    protected void doDelete(Object object) throws Exception {
 40        OrganisationProfile organisationProfile = (OrganisationProfile) object;
 41        Document document = new DocumentImpl();
 42        document.addUID(WebKeys.PORTLET_ID, organisationProfile.getPrimaryKey());
 43        SearchEngineUtil.deleteDocument(organisationProfile.getCompanyId(), document.getUID());
 44    }
 45
 46    /*
 47     * (non-Javadoc)
 48     *
 49     * @see
 50     * com.liferay.portal.kernel.search.BaseIndexer#doGetDocument(java.lang.
 51     * Object)
 52     */
 53    @Override
 54    protected Document doGetDocument(Object object) throws Exception {
 55        OrganisationProfile organisationProfile = (OrganisationProfile) object;
 56        Organization orga = OrganizationLocalServiceUtil.getOrganization(organisationProfile.getOrganisationId());
 57        Document document = new DocumentImpl();
 58        document.addUID(WebKeys.PORTLET_ID, organisationProfile.getPrimaryKey());
 59        document.addModifiedDate(organisationProfile.getAenderungsdatum());
 60        document.addKeyword(Field.COMPANY_ID, organisationProfile.getCompanyId());
 61        document.addKeyword(Field.PORTLET_ID, WebKeys.PORTLET_ID);
 62       
 63        document.addText(Field.TITLE, orga.getName());
 64        document.addText("profiltitel", organisationProfile.getProfiltitel());
 65       
 66       
 67        if(Validator.isNotNull(organisationProfile.getFachbereich())){
 68            document.addText("fachbereich", organisationProfile.getFachbereich());   
 69        }
 70        if(Validator.isNotNull(organisationProfile.getGesellschaftsform())){
 71            document.addText("gesellschaftsform", organisationProfile.getGesellschaftsform());   
 72        }
 73        if(Validator.isNotNull(organisationProfile.getSpezialisierung())){
 74            document.addText("spezialisierung", organisationProfile.getSpezialisierung());
 75        }
 76        if(Validator.isNotNull(organisationProfile.getInteresse())){
 77            document.addText("interesse", organisationProfile.getInteresse());
 78        }
 79       
 80        if(Validator.isNotNull(organisationProfile.getBeschreibung())){
 81            document.addText(Field.CONTENT, organisationProfile.getBeschreibung());
 82        }
 83        if(Validator.isNotNull(organisationProfile.getLehrstuhl())){
 84            document.addText("lehrstuhl", organisationProfile.getLehrstuhl());
 85        }
 86        if(Validator.isNotNull(organisationProfile.getHauptgeschaeftsbereiche())){
 87            document.addText("hauptgeschaeftsbereiche", organisationProfile.getHauptgeschaeftsbereiche());
 88        }
 89       
 90        if(Validator.isNotNull(organisationProfile.getReferenzen())){
 91            document.addText("referenzen", organisationProfile.getReferenzen());
 92        }
 93       
 94        document.addText("orgaType", orga.getType());
 95        document.addKeyword(Field.ENTRY_CLASS_NAME, OrganisationProfile.class.getName());
 96        document.addKeyword(Field.ENTRY_CLASS_PK, organisationProfile.getPrimaryKey());
 97        document.addDate(Field.MODIFIED, organisationProfile.getAenderungsdatum());
 98        document.addText(Field.URL, "/web" + orga.getGroup().getFriendlyURL());
 99        return document;
100    }
101
102    /*
103     * (non-Javadoc)
104     *
105     * @see
106     * com.liferay.portal.kernel.search.BaseIndexer#doReindex(java.lang.Object)
107     */
108    @Override
109    protected void doReindex(Object object) throws Exception {
110        OrganisationProfile organisationProfile = (OrganisationProfile) object;
111        SearchEngineUtil.updateDocument(organisationProfile.getCompanyId(), getDocument(organisationProfile));
112    }
113
114    /*
115     * (non-Javadoc)
116     *
117     * @see
118     * com.liferay.portal.kernel.search.BaseIndexer#doReindex(java.lang.String
119     * [])
120     */
121    @Override
122    protected void doReindex(String[] ids) throws Exception {
123           long companyId = GetterUtil.getLong(ids[0]);
124            reindexProfiles(companyId);
125       
126    }
127   
128    protected void reindexProfiles(long companyId) throws Exception {
129        int count = OrganisationProfileLocalServiceUtil.getOrganisationProfilesCount();
130        int pages = count / Indexer.DEFAULT_INTERVAL;
131        for(int i = 0; i<= pages; i++) {
132            int start = (i * Indexer.DEFAULT_INTERVAL);
133            int end = start + Indexer.DEFAULT_INTERVAL;
134            reindex(companyId, start, end);
135        }
136    }
137
138    protected void reindex(long companyId, int start, int end) throws Exception {
139        List<OrganisationProfile> profiles = OrganisationProfileLocalServiceUtil.getReleasedOrganisationProfiles(start, end);
140        if(profiles.isEmpty()) {
141            return;
142        }
143        Collection<Document> documents = new ArrayList<Document>();
144        for (OrganisationProfile organisationProfile : profiles) {
145            Document doc = getDocument(organisationProfile);
146            documents.add(doc);
147        }
148        SearchEngineUtil.updateDocuments(companyId, documents);
149    }
150   
151    /*
152     * (non-Javadoc)
153     *
154     * @see
155     * com.liferay.portal.kernel.search.BaseIndexer#doReindex(java.lang.String,
156     * long)
157     */
158    @Override
159    protected void doReindex(String className, long classPk) throws Exception {
160        OrganisationProfile organisationProfile = OrganisationProfileLocalServiceUtil.getOrganisationProfile(classPk);
161        reindex(organisationProfile);
162    }
163
164    @Override
165    public String[] getClassNames() {
166        return CLASS_NAMES;
167    }
168
169    @Override
170    protected String getPortletId(SearchContext searchContext) {
171        return WebKeys.PORTLET_ID;
172    }
173
174    @Override
175    public void postProcessContextQuery(BooleanQuery contextQuery,
176            SearchContext searchContext) throws Exception {
177    }
178
179    @Override
180    public void postProcessSearchQuery(BooleanQuery searchQuery,
181            SearchContext searchContext) throws Exception {       
182        searchQuery.addTerm("spezialisierung", searchContext.getKeywords());
183        searchQuery.addTerm("gesellschaftsform", searchContext.getKeywords());
184        searchQuery.addTerm("fachbereich", searchContext.getKeywords());
185        searchQuery.addTerm("orgaType", searchContext.getKeywords());
186        searchQuery.addTerm("interesse", searchContext.getKeywords());
187        searchQuery.addTerm("lehrstuhl", searchContext.getKeywords());
188        searchQuery.addTerm("profiltitel", searchContext.getKeywords());
189        searchQuery.addTerm("referenzen", searchContext.getKeywords());
190        searchQuery.addTerm("hauptgeschaeftsbereiche", searchContext.getKeywords());
191        super.postProcessSearchQuery(searchQuery, searchContext);
192    }
193
194    @Override
195    public String getPortletId() {       
196        return PORTLET_ID;
197    }
198
199    @Override
200    protected Summary doGetSummary(Document document, Locale locale, String snippet, PortletURL portletURL) throws Exception {
201        return getSummary(document, locale, snippet, portletURL);
202    }


Hope this helps.

Jan
Star Invader
RE: Custom search from 6.0.6 to 6.1
April 24, 2012 4:52 AM
Answer

Star Invader

Rank: New Member

Posts: 18

Join Date: September 26, 2011

Recent Posts

thank you very much, I have added it but I still get no results

this is my indexer code
  1public class TestIndexer extends BaseIndexer {
  2   
  3    public static final String[] CLASS_NAMES = {Actividad.class.getName()};
  4   
  5    public static final String PORTLET_ID = "test_WAR_testportlet";
  6   
  7    private long companyId;
  8
  9    @Override
 10    public String[] getClassNames() {
 11        return CLASS_NAMES;
 12    }
 13   
 14    @Override
 15    public Hits search(SearchContext searchContext) throws SearchException {
 16        return super.search(searchContext);
 17    }
 18   
 19    @Override
 20    public boolean hasPermission(PermissionChecker permissionChecker, long entryClassPK, String actionId) throws Exception {
 21        return super.hasPermission(permissionChecker, entryClassPK, actionId);
 22    }
 23
 24    @Override
 25    public String getPortletId() {
 26        return PORTLET_ID;
 27    }
 28
 29    @Override
 30    protected void doDelete(Object obj) throws Exception {
 31        Actividad actividad = (Actividad)obj;
 32       
 33        Document document = getDocument(actividad);
 34       
 35        SearchEngineUtil.deleteDocument(companyId, document.getUID());
 36    }
 37
 38    @Override
 39    protected Document doGetDocument(Object obj) throws Exception {
 40        Actividad actividad = (Actividad)obj;
 41       
 42        Document document = new DocumentImpl();
 43       
 44        String titulo = actividad.getNomb_acti();
 45        titulo += " - Fecha: ";
 46        titulo += (actividad.getRango_fecha() != null) ? actividad.getRango_fecha() : actividad.getFech_desc();
 47       
 48        String contenido = "";
 49        if (actividad.getDesc_acti() != null) contenido = actividad.getDesc_acti();
 50       
 51        String descripcion = actividad.getNomb_acti() +
 52                " " + actividad.getDesc_acti() +
 53                " " + actividad.getCome_acti() +
 54                " Fecha " + actividad.getRango_fecha();
 55       
 56        for (Organizador organizador : actividad.getListaOrganizadores()) descripcion += " " + organizador.getNomb_orga();
 57        for (Ciudad ciudad : actividad.getListaCiudades()) descripcion += " " + ciudad.getDen_ciudad() + " " + ciudad.getDen_pais();
 58        for (Pais pais : actividad.getListaPaises()) descripcion += " " + pais.getDen_pais();
 59        for (Sector sector : actividad.getListaSectores()) descripcion += " " + sector.getDenominacion();
 60       
 61        document.addUID(PORTLET_ID, actividad.getCodi_acti());
 62        //document.addModifiedDate();
 63        document.addText(Field.TITLE, titulo);
 64        document.addText(Field.CONTENT, contenido);
 65        document.addText(Field.DESCRIPTION, StringUtils.normalizar(descripcion));
 66        document.addKeyword(Field.COMPANY_ID, companyId);
 67        document.addKeyword(Field.PORTLET_ID, PORTLET_ID);
 68        document.addKeyword(Field.ENTRY_CLASS_NAME, Actividad.class.getName());
 69        document.addKeyword(Field.ENTRY_CLASS_PK, actividad.getCodi_acti());
 70        document.addKeyword(Field.FOLDER_ID, actividad.getCodi_serv());
 71        document.addKeyword(Field.URL, actividad.getNomb_acti_url());
 72       
 73        return document;
 74    }
 75
 76    @Override
 77    protected Summary doGetSummary(Document document, Locale locale,
 78            String snippet, PortletURL portletURL) throws Exception {
 79        portletURL.setParameter("action", "verResultado");
 80        portletURL.setParameter("actividad", document.get(Field.ENTRY_CLASS_PK));
 81        portletURL.setParameter("servicio", document.get(Field.FOLDER_ID));
 82        portletURL.setParameter("titulo", document.get(Field.URL));
 83       
 84        String titulo = document.get(Field.TITLE);
 85        String contenido = snippet;
 86       
 87        if (Validator.isNull(snippet)) contenido = StringUtil.shorten(document.get(Field.CONTENT),200);
 88       
 89        return new Summary(titulo,contenido,portletURL);
 90    }
 91
 92    @Override
 93    protected void doReindex(Object obj) throws Exception {
 94        Actividad actividad = (Actividad)obj;
 95       
 96        Document document = getDocument(actividad);
 97       
 98        SearchEngineUtil.updateDocument(companyId, document);
 99    }
100
101    @Override
102    protected void doReindex(String className, long classPK) throws Exception {
103        // TODO Auto-generated method stub
104
105    }
106
107    @Override
108    protected void doReindex(String[] ids) throws Exception {
109        companyId = GetterUtil.getLong(ids[0]);
110       
111        FactoriaDAO factoriaDAO = (FactoriaDAO)PortletUtils.getBean(Constantes.BEAN_FACTORIA_DAO);
112       
113        List<Actividad> listaActividades = (List<Actividad>)factoriaDAO.getActividadDAO().selectAll();
114       
115        SearchEngineUtil.deletePortletDocuments(companyId, PORTLET_ID);
116       
117        for (Actividad actividad : listaActividades) {
118            actividad.setListaOrganizadores(factoriaDAO.getActividadOrganizadorDAO().selectByCodiActi(actividad.getCodi_acti()));
119            actividad.setListaCiudades(factoriaDAO.getCiudadDAO().selectByCodiActi(actividad.getCodi_acti()));
120            actividad.setListaPaises(factoriaDAO.getPaisDAO().selectByCodiActi(actividad.getCodi_acti()));
121            actividad.setListaSectores(factoriaDAO.getSectorDAO().selectByCodiActi(actividad.getCodi_acti()));
122            Document document = getDocument(actividad);
123            SearchEngineUtil.updateDocument(companyId, document);
124        }
125    }
126
127    @Override
128    protected String getPortletId(SearchContext searchContext) {
129        return PORTLET_ID;
130    }
131
132}



and this my opensearch class
 1public class TestOpenSearch extends HitsOpenSearchImpl {
 2   
 3    public static final String SEARCH_PATH = "/c/test/open_search";
 4
 5    public static final String TITLE = "Test Search: ";
 6
 7    @Override
 8    public String getPortletId() {
 9        return TestIndexer.PORTLET_ID;
10    }
11
12    @Override
13    public String getSearchPath() {
14        return SEARCH_PATH;
15    }
16
17    @Override
18    public String getTitle(String keywords) {
19        return TITLE + keywords;
20    }
21
22    @Override
23    public Indexer getIndexer() {
24        return IndexerRegistryUtil.getIndexer(Actividad.class);
25    }
26
27}
Star Invader
RE: Custom search from 6.0.6 to 6.1
April 24, 2012 5:49 AM
Answer

Star Invader

Rank: New Member

Posts: 18

Join Date: September 26, 2011

Recent Posts

I'm doing a lot of test and the contents are being indexed but not retrieved by the search
Jan Geißler
RE: Custom search from 6.0.6 to 6.1
April 25, 2012 2:36 AM
Answer

Jan Geißler

Community Moderator

Rank: Liferay Master

Posts: 735

Join Date: July 5, 2011

Recent Posts

@Override
public boolean hasPermission(PermissionChecker permissionChecker, long entryClassPK, String actionId) throws Exception {
//sysout for the permissio9ns, maybe there is something wrong.
return super.hasPermission(permissionChecker, entryClassPK, actionId);
}
Star Invader
RE: Custom search from 6.0.6 to 6.1
April 25, 2012 3:47 AM
Answer

Star Invader

Rank: New Member

Posts: 18

Join Date: September 26, 2011

Recent Posts

thanks, I'm debugging that method but its not triggered

the problem is that the search() method at the indexer returns no results
Jan Geißler
RE: Custom search from 6.0.6 to 6.1
April 25, 2012 5:57 AM
Answer

Jan Geißler

Community Moderator

Rank: Liferay Master

Posts: 735

Join Date: July 5, 2011

Recent Posts

But the files are indexed, right?
The search method is fired in your indexer?
The keywords correct?

So many questions emoticon
Star Invader
RE: Custom search from 6.0.6 to 6.1
April 26, 2012 4:23 AM
Answer

Star Invader

Rank: New Member

Posts: 18

Join Date: September 26, 2011

Recent Posts

Hi, the files are being indexed
The search method y called but no results are returned
The keywords are correct

My portlets are using spring mvc, could it be library incompatibility?

I'm using the following libraries

commons-dbcp-1.2.2.jar
commons-fileupload.jar
commons-io.jar
commons-logging.jar
commons-pool-1.3.jar
jstl.jar
log4j-1.2.15.jar
ojdbc14-10.2.0.2.jar
org.springframework.aop-3.0.5.RELEASE.jar
org.springframework.asm-3.0.5.RELEASE.jar
org.springframework.aspects-3.0.5.RELEASE.jar
org.springframework.beans-3.0.5.RELEASE.jar
org.springframework.context-3.0.5.RELEASE.jar
org.springframework.context.support-3.0.5.RELEASE.jar
org.springframework.core-3.0.5.RELEASE.jar
org.springframework.expression-3.0.5.RELEASE.jar
org.springframework.instrument-3.0.5.RELEASE.jar
org.springframework.instrument.tomcat-3.0.5.RELEASE.jar
org.springframework.jdbc-3.0.5.RELEASE.jar
org.springframework.jms-3.0.5.RELEASE.jar
org.springframework.orm-3.0.5.RELEASE.jar
org.springframework.oxm-3.0.5.RELEASE.jar
org.springframework.spring-library-3.0.5.RELEASE.libd
org.springframework.test-3.0.5.RELEASE.jar
org.springframework.transaction-3.0.5.RELEASE.jar
org.springframework.web-3.0.5.RELEASE.jar
org.springframework.web.portlet-3.0.5.RELEASE.jar
org.springframework.web.servlet-3.0.5.RELEASE.jar
org.springframework.web.struts-3.0.5.RELEASE.jar
standard.jar
Jan Geißler
RE: Custom search from 6.0.6 to 6.1
April 26, 2012 5:17 AM
Answer

Jan Geißler

Community Moderator

Rank: Liferay Master

Posts: 735

Join Date: July 5, 2011

Recent Posts

Nope. Using Spring MVC and all the goodies as well.
Oliver Bayer
RE: Custom search from 6.0.6 to 6.1
April 26, 2012 6:00 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 883

Join Date: February 18, 2009

Recent Posts

Hi,

do you've checked if the files are really indexed correctly? You can use tools like luke to check the lucene index. If the files are indexed correctly use luke and check the lucene-query to see if you get the results lowlevel.

HTH Oli
Star Invader
RE: Custom search from 6.0.6 to 6.1
April 26, 2012 6:12 AM
Answer

Star Invader

Rank: New Member

Posts: 18

Join Date: September 26, 2011

Recent Posts

thanks, i'm trying it
Star Invader
RE: Custom search from 6.0.6 to 6.1
April 30, 2012 12:39 AM
Answer

Star Invader

Rank: New Member

Posts: 18

Join Date: September 26, 2011

Recent Posts

Hi, using luke I found the problem

At my indexer I'm not adding the groupId and the lucene query build by Liferay 6.1 seems to always add a groupId but 6.0.6 it's not doing it

once the groupId was solved I found another problem, the modified date. If you do not add it the search portlet throws an exception while adding the result documents to the hits list maybe this could be controlled by checking the null value before parsing it

Thanks for your time and I hope this could help someone else
Oliver Bayer
RE: Custom search from 6.0.6 to 6.1
May 2, 2012 2:01 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 883

Join Date: February 18, 2009

Recent Posts

I'm glad to hear that luke helped you to solve the indexer issue, thanks for the feedback emoticon.
Oli