[opencms-dev] How can search general in more perspective/multisite?

Deiverson Silveira deiverson at solutioncms.com
Mon Oct 13 21:55:34 CEST 2014


Hi experts opencmsman´s,

I have problem now, I dont access contentload other perspective for example:

*for*(*Iterator* iterator = listaResultado.iterator(); iterator.hasNext();){

      CmsSearchResult result = (CmsSearchResult)iterator.next();

      out.println("result = " + result.getPath() + "<br>");

      String pathRecurso = result.getPath();

      pathRecurso = pathRecurso.substring(7, pathRecurso.length());

      pathRecurso = pathRecurso.substring(pathRecurso.indexOf("/"),
pathRecurso.length());

      CmsJspXmlContentBean contentBean = *new*
CmsJspXmlContentBean(cms.getJspContext(), cms.getRequest(),
cms.getResponse());

      *for*(CmsJspTagContentLoad contentList =
(CmsJspTagContentLoad)contentBean.contentload("singleFile", pathRecurso,
*false*); contentList.hasMoreResources();){

              *if*(contentBean.contentshow(contentList,"Titulo").length() >
0 && !contentBean.contentshow(contentList,"Titulo").startsWith("???")){

                    out.println("titulo = " +
contentBean.contentshow(contentList,"Titulo"));

             }

      }

%>

       <cms:contentload collector=*"singleFile"* param=*"*<%=pathRecurso%>
*"* editable=*"false"*>

             <cms:contentcheck ifexists=*"Titulo"*>

                    <c:set var=*"tituloNoticia"*><cms:contentshow element=
*"Titulo"* locale=*"*${locale}*"*/></c:set>

             </cms:contentcheck>

             ${tituloNoticia}

       </cms:contentload>

<%}%>

I belive my problem is this:
      CmsJspXmlContentBean contentBean = *new*
CmsJspXmlContentBean(cms.getJspContext(), cms.getRequest(),
cms.getResponse());

I set current context, and no other context in other perspective =[, very
sad.

I debug opencms, stay way change permission in CmsSecurityManager, function
readResource.
Somebody idea more simple for I read contentload in other content other
perspective?

How can I see content in other perspective? What class I use for this?

Thank you for help,

Deiverson


2014-10-07 12:40 GMT-03:00 Schliemann, Kai <K.Schliemann at comundus.com>:

>  Hi Deiverson,
>
> glad, that you found a solution.
>
> I would say most of the magic is the while loop below this comment
> “//Realizando a iteração de todos os multisites existentes”.
>
>
>
> What I do not understand is, what the following line is needed for:
>
> parametros.setParsedQuery("z* OR x* OR c* OR v* OR b* OR n* OR m* OR l* OR
> k* OR j* OR h* OR g* OR f* OR d* OR s* OR a* OR q* OR w* OR e* OR r* OR t*
> OR y* OR u* OR i* OR o* OR p*");
>
> Additionally this looks to me like some kind of a performance killer, when
> this query is really executed with each search request.
>
>
>
> But never mind. It works and that is important.
>
>
>
> Best regards
>
> Kai
>
>
>
> *Von:* opencms-dev-bounces at opencms.org [mailto:
> opencms-dev-bounces at opencms.org] *Im Auftrag von *Deiverson Silveira
> *Gesendet:* Dienstag, 7. Oktober 2014 14:36
>
> *An:* The OpenCms mailing list
> *Betreff:* Re: [opencms-dev] How can search general in more
> perspective/multisite?
>
>
>
> Hi Kai,
>
> Success with this code, xD... see (sorry comment with portuguese), shared
> and "viva o software livre":
>
> <%@page import="org.opencms.file.CmsObject"%>
> <%@page import="org.opencms.search.fields.CmsSearchFieldConfiguration"%>
> <%@ page session="true" %>
> <%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms"%>
> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
> <%@page import="org.opencms.search.CmsSearchManager"%>
> <%@page import="org.opencms.search.CmsSearchParameters"%>
> <%@page import="org.opencms.main.OpenCms"%>
> <%@page import="java.util.*"%>
> <%@page import="java.util.ArrayList"%>
> <%@page import="org.opencms.jsp.CmsJspActionElement"%>
> <%@page import="org.opencms.search.CmsSearchResult"%>
> <%@page import="org.opencms.search.*"%>
> <%
>     CmsJspActionElement cms = new CmsJspActionElement(pageContext,
> request, response);
>
>     //Criando o Objeto que será alternado via multisites
>     CmsObject obj = cms.getCmsObject();
>     //Seta o site do contexto atual para rollback
>     String siteRollBack =
> OpenCms.getSiteManager().getDefaultSite().getSiteRoot();
>     //Setando os parametros de busca
>     CmsSearchParameters parametros = new CmsSearchParameters();
>     //Criando uma busca geral
>     CmsSearch searchGeral = new CmsSearch();
>     //Setando o indice de busca geral
>     parametros.setIndex("Offline project EN (VFS)");
>     //Passando o parametro de consulta, no exemplo abaixo busca por todo o
> site
>     parametros.setParsedQuery("z* OR x* OR c* OR v* OR b* OR n* OR m* OR
> l* OR k* OR j* OR h* OR g* OR f* OR d* OR s* OR a* OR q* OR w* OR e* OR r*
> OR t* OR y* OR u* OR i* OR o* OR p*");
>     //Setando resultados por pagina
>     parametros.setMatchesPerPage(99999);
>     //Setando os parametros para a busca geral
>     searchGeral.setParameters(parametros);
>     //Preparando a lista de Resultados de Busca Geral
>     List<CmsSearchResult> listaResultado = null;
>     //Criando a lista de todos os multisites que serão iterados,
> dinamicamente
>     Set<String> listaSites = OpenCms.getSiteManager().getSiteRoots();
>
>     //Realizando a iteração de todos os multisites existentes
>     Iterator i = listaSites.iterator();
>     while(i.hasNext()){
>         //Nesse momento é identificado um dos sites da lista existente
>         String multiSite = i.next().toString();
>         //Definindo o site raiz, referente a outra perspectiva
>         obj.getRequestContext().setSiteRoot(multiSite);
>         //Setando o objeto de busca geral com o objeto instanciado
> anteriormente
>         searchGeral.init(obj);
>         //Se for a primeira iteração, o objeto será null ao tentar
> adicionar a lista de resultados concatenando, portanto foi necessario
> adicionar o else
>         //para ser adicionado na primeira iteracao uma lista de resultado
>         if(listaResultado != null){
>             listaResultado.addAll(searchGeral.getSearchResult());
>         }else{
>             listaResultado = searchGeral.getSearchResult();
>         }
>     }
>     //Setando o site corrente de modo rollBack
>     obj.getRequestContext().setSiteRoot(siteRollBack);
>
>     //Exibindo o resultado da busca geral, que foi agregado de todos os
> multisites
>     for(Iterator iterator = listaResultado.iterator(); iterator.hasNext();)
>     {
>         CmsSearchResult result = (CmsSearchResult)iterator.next();
>         out.println(result.getPath() + "<br>");
>     }
> %>
>
> Thank you for Fabian and Kai!
>
> Success!
>
> Deiverson
>
>
>
>
>
> 2014-10-06 14:30 GMT-03:00 Schliemann, Kai <K.Schliemann at comundus.com>:
>
> Hi Deiverson,
>
> ok, too bad. I used that once in a project to distinguish between folders
> but within one site. I thought that would work with multi sites too.
>
> Coming back to the index solution.
>
> Is it possible for you to define three indices:
>
> 1.       Index siteA
>
> 2.       Index siteB
>
> 3.       Index global
>
> If someone does a global search (e.g. by ticking a checkbox “global
> search”) you use that index. Otherwise you are using the site indices.
>
> I think, this would be the easiest solution, if suitable for you.
>
>
>
> Another approach, which needs changes in data structure:
>
> Move all your news to the shared site and add categories to your news xsd.
> Categories would be “siteA”, “siteB”, “global”.
>
> Filter your search results by categories.
>
> Only works, if your just want to search news content.
>
>
>
> HTH
>
> Best regards
>
> Kai
>
>
>
>
>
> *Von:* opencms-dev-bounces at opencms.org [mailto:
> opencms-dev-bounces at opencms.org] *Im Auftrag von *Deiverson Silveira
> *Gesendet:* Montag, 6. Oktober 2014 18:45
>
>
> *An:* The OpenCms mailing list
> *Betreff:* Re: [opencms-dev] How can search general in more
> perspective/multisite?
>
>
>
> Hi Kai,
>
> I try setSearchRoots but problem with multisites, I dont see other
> perspective.=/
>
> I can /news/, /faq/, but my search dont see /sites/siteb/othernews/ for
> exemplo, only one perspective.
>
> I use setSearchRoots in jsp.
>
> Regards,
>
> Deiverson
>
>
>
> 2014-10-06 11:11 GMT-03:00 Schliemann, Kai <K.Schliemann at comundus.com>:
>
> Hi Deiverson,
>
> for a global search you probably need this:
>
>
>
>     /**
>
>      * Sets the search root list.<p>
>
>      *
>
>      * Only resources that are sub-resources of one of the search roots
>
>      * are included in the search result.<p>
>
>      *
>
>      * The search roots set here are used <i>in addition to</i> the
> current site root
>
>      * of the user performing the search.<p>
>
>      *
>
>      * By default, the search roots contain only one entry with an empty
> string.<p>
>
>      *
>
>      * *@param* searchRoots the search roots to set
>
>      */
>
>     *public* *void* setSearchRoots(String[] searchRoots) {
>
>
>
>         List<String> l = *new* ArrayList<String>(Arrays.*asList*(
> searchRoots));
>
>         m_parameters.setRoots(l);
>
>         resetLastResult();
>
>     }
>
>
>
>
>
> Best regards
>
> Kai
>
>
>
> *Von:* opencms-dev-bounces at opencms.org [mailto:
> opencms-dev-bounces at opencms.org] *Im Auftrag von *Deiverson Silveira
> *Gesendet:* Montag, 6. Oktober 2014 14:55
>
> *An:* The OpenCms mailing list
> *Betreff:* Re: [opencms-dev] How can search general in more
> perspective/multisite?
>
>
>
> Hi Kai,
>
> But this way, for a global search on all subsites I would have to
> instantiate each index and concatenate the results, right?
>
> Regards,
>
> Deiverson
>
>
>
> 2014-10-06 6:21 GMT-03:00 Schliemann, Kai <K.Schliemann at comundus.com>:
>
> Hi Deiverson,
>
> if you are using Lucene, you can create an index for each site.
>
> And then set the index in your search JSP.
>
> e.g. like
>
> org.opencms.search.CmsSearch.setIndex(indexName);
>
> AFAIK OpenCms provides a property “search.index”. You could use that to
> read the index you need. Or set it hard coded in your template, depending
> on the site you are in (not recommended).
>
>
>
> HTH
>
>
>
> Best regards
>
> Kai
>
>
>
> *Von:* opencms-dev-bounces at opencms.org [mailto:
> opencms-dev-bounces at opencms.org] *Im Auftrag von *Deiverson Silveira
> *Gesendet:* Freitag, 3. Oktober 2014 20:54
> *An:* The OpenCms mailing list
> *Betreff:* Re: [opencms-dev] How can search general in more
> perspective/multisite?
>
>
>
> Hi Fabian,
>
> Thank you for attention.
>
>
>
> I don't use Solr, you know how can make this using Lucene? I use
> traditional Lucene, I think this case is already a good opportunity to use
> Solr and leave the Lucene.
>
> I try set my object with project "/" but entry conflit in mysite because
> perspective:
>
>         CmsObject cmsObject = cms.getCmsObject();
>         CmsProject cmsproject = cmsObject.readProject("Offline");
>         cmsObject.getRequestContext().setCurrentProject(cmsproject);
>         cmsObject.getRequestContext().setSiteRoot("/");
>
> and:
>
> search.init(cmsproject);
>
>
>
> Regards,
>
> Deiverson
>
>
>
> 2014-10-01 8:57 GMT-03:00 fhsubscriptions at componio.net <
> fhsubscriptions at componio.net>:
>
> Hi Deiverson,
>
> you can set the "parent sites" in the Solr query to enable search across
> different sites.
>
> Regards,
>
> \Fabian
>
> Am 01.10.2014 13:24, schrieb Deiverson Silveira:
>
>     Hi List,
>
> I have problem.
>
> I have multisites, and I have search general, I need search
> /sites/siteA/news/ and /sites/siteB/news/.
>
> I stay perspective /sites/siteA/, dont see /sites/siteB/
>
>
>
> My search don´t work because perspective, how can solved this problem?
>
> I need help,
>
> Regards,
>
> Deiverson
>
>
>
>
> --
>
> *www.solutioncms.com <http://www.solutioncms.com>*
>
> *The Brazilian  *
>
> *Official Provider OpenCms*
>
>
>
> _______________________________________________
>
> This mail is sent to you from the opencms-dev mailing list
>
> To change your list options, or to unsubscribe from the list, please visit
>
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
>
> --
>
> *www.solutioncms.com <http://www.solutioncms.com>*
>
> *The Brazilian *
>
> *Official Provider OpenCms*
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
>
> --
>
> *www.solutioncms.com <http://www.solutioncms.com>*
>
> *The Brazilian *
>
> *Official Provider OpenCms*
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
>
>
> --
>
> *www.solutioncms.com <http://www.solutioncms.com>*
>
> *The Brazilian *
>
> *Official Provider OpenCms*
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
>
>
>
> --
>
> *www.solutioncms.com <http://www.solutioncms.com>*
>
> *The Brazilian *
>
> *Official Provider OpenCms*
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
>
>


-- 
*www.solutioncms.com <http://www.solutioncms.com>The Brazilian Official
Provider OpenCms*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20141013/af868834/attachment.htm>


More information about the opencms-dev mailing list