From 26a23cd3bf67bc4fd837aec7276ccf72649555fd Mon Sep 17 00:00:00 2001 From: Brian Chan Date: Mon, 16 May 2011 19:50:10 +0000 Subject: [PATCH] LPS-6473 Source formatting git-svn-id: svn://svn.liferay.com/repos/public/portal/trunk@80652 05bdf26c-840f-0410-9ced-eb539d925f36 --- .classpath | 4 +- lib/versions.xml | 6 +- nbproject/project.xml | 2 +- .../portal/search/BoboFacetCollector.java | 15 +- .../portal/search/BoboTermCollector.java | 4 +- .../portal/search/IndexSearcherProxyBean.java | 9 +- .../lucene/LuceneIndexSearcherImpl.java | 359 +++++++++--------- .../bookmarks/util/BookmarksIndexer.java | 47 +-- .../documentlibrary/util/DLIndexer.java | 53 ++- .../portlet/imagegallery/util/IGIndexer.java | 44 +-- .../portlet/messageboards/util/MBIndexer.java | 53 ++- .../portlet/wiki/util/WikiIndexer.java | 119 +++--- .../service/BookmarksFolderServiceTest.java | 5 +- .../service/DLAppServiceTest.java | 2 +- .../portal/kernel/search/BaseIndexer.java | 129 +++++-- .../portal/kernel/search/FacetedSearcher.java | 14 +- .../portal/kernel/search/IndexSearcher.java | 6 +- .../liferay/portal/kernel/search/Indexer.java | 4 +- .../portal/kernel/search/IndexerWrapper.java | 11 +- .../portal/kernel/search/SearchContext.java | 4 +- .../kernel/search/SearchEngineUtil.java | 152 ++++---- .../search/facet/AssetEntriesFacet.java | 36 +- .../portal/kernel/search/facet/BaseFacet.java | 25 +- .../kernel/search/facet/MultiValueFacet.java | 17 +- .../kernel/search/facet/RangeFacet.java | 28 +- .../kernel/search/facet/ScopeFacet.java | 11 +- .../kernel/search/facet/SimpleFacet.java | 8 +- .../facet/config/FacetConfiguration.java | 12 +- .../facet/config/FacetConfigurationUtil.java | 74 ++-- 29 files changed, 666 insertions(+), 587 deletions(-) diff --git a/.classpath b/.classpath index 9e65eb6a4d4b8c..b954faf11c5420 100644 --- a/.classpath +++ b/.classpath @@ -104,6 +104,7 @@ + @@ -147,6 +148,7 @@ + @@ -282,7 +284,5 @@ - - diff --git a/lib/versions.xml b/lib/versions.xml index c52340eae8945c..227651818f3420 100644 --- a/lib/versions.xml +++ b/lib/versions.xml @@ -1099,9 +1099,9 @@ portal/bobo-browse.jar - 2.5.0-rc1 + 2.5.0 RC1 Bob Browse - http://code.google.com/p/bobo-browse/ + http://code.google.com/p/bobo-browse LGPL 3 @@ -1605,7 +1605,7 @@ portal/fastutil.jar 5.0.5 Fastutil - http://fastutil.dsi.unimi.it/ + http://fastutil.dsi.unimi.it Apache License 2.0 diff --git a/nbproject/project.xml b/nbproject/project.xml index 3e61cb8e2f8fc8..2a63255c60bcbd 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -173,7 +173,7 @@ util-java/src util-taglib/src - lib/development/activation.jar:lib/development/annotations.jar:lib/development/ant-apache-bsf.jar:lib/development/ant-contrib.jar:lib/development/ant-ext.jar:lib/development/ant-installer.jar:lib/development/antelope.jar:lib/development/catalina.jar:lib/development/ckpackager.jar:lib/development/deployment.jar:lib/development/derby.jar:lib/development/derbytools.jar:lib/development/dtddoc.jar:lib/development/dtdparser.jar:lib/development/ecj.jar:lib/development/firebird.jar:lib/development/hamcrest-core.jar:lib/development/hamcrest-library.jar:lib/development/hsql.jar:lib/development/icefaces-comps.jar:lib/development/icefaces-facelets.jar:lib/development/icefaces.jar:lib/development/interbase.jar:lib/development/j2h.jar:lib/development/jaas.jar:lib/development/jakarta-regexp.jar:lib/development/jalopy.jar:lib/development/jargs.jar:lib/development/jaxb-api.jar:lib/development/jbi_rt.jar:lib/development/jetty.jar:lib/development/jetty-util.jar:lib/development/jhighlight.jar:lib/development/jmock.jar:lib/development/jmock-junit4.jar:lib/development/jms.jar:lib/development/jndi.jar:lib/development/jnet.jar:lib/development/jsf-api.jar:lib/development/jsf-facelets.jar:lib/development/jsf-impl.jar:lib/development/jsf-portlet.jar:lib/development/jsp-api.jar:lib/development/jta.jar:lib/development/jtds.jar:lib/development/junit.jar:lib/development/just-ice.jar:lib/development/jutf7.jar:lib/development/jymsg.jar:lib/development/mail.jar:lib/development/myfaces-api.jar:lib/development/myfaces-impl.jar:lib/development/mysql.jar:lib/development/objenesis.jar:lib/development/orangevolt-ant-tasks.jar:lib/development/p6spy.jar:lib/development/persistence.jar:lib/development/postgresql.jar:lib/development/qdox.jar:lib/development/resin.jar:lib/development/sap.jar:lib/development/saxpath.jar:lib/development/script-10.jar:lib/development/sdk-addon-api-0.2.jar:lib/development/selenium-java-client-driver.jar:lib/development/selenium-server.jar:lib/development/servlet-api.jar:lib/development/smtp.jar:lib/development/spring-instrument.jar:lib/development/spring-instrument-tomcat.jar:lib/development/spring-test.jar:lib/development/tomcat-coyote.jar:lib/development/xmltask.jar:lib/global/portlet.jar:lib/portal/abdera.jar:lib/portal/alloy-taglib.jar:lib/portal/ant.jar:lib/portal/antlr.jar:lib/portal/aopalliance.jar:lib/portal/asm-analysis.jar:lib/portal/asm-commons.jar:lib/portal/asm-tree.jar:lib/portal/asm-util.jar:lib/portal/asm-xml.jar:lib/portal/asm.jar:lib/portal/aspectj-rt.jar:lib/portal/aspectj-weaver.jar:lib/portal/axiom-api.jar:lib/portal/axiom-impl.jar:lib/portal/axis-ant.jar:lib/portal/axis.jar:lib/portal/backport-concurrent.jar:lib/portal/bcmail.jar:lib/portal/bcprov.jar:lib/portal/bsh.jar:lib/portal/bsf.jar:lib/portal/c3p0.jar:lib/portal/cas-client-core.jar:lib/portal/ccpp-ri.jar:lib/portal/ccpp.jar:lib/portal/cglib.jar:lib/portal/chardet.jar:lib/portal/chemistry-opencmis-client-api.jar:lib/portal/chemistry-opencmis-client-bindings.jar:lib/portal/chemistry-opencmis-client-impl.jar:lib/portal/chemistry-opencmis-commons-api.jar:lib/portal/chemistry-opencmis-commons-impl.jar:lib/portal/commons-beanutils.jar:lib/portal/commons-codec.jar:lib/portal/commons-collections.jar:lib/portal/commons-compress.jar:lib/portal/commons-configuration.jar:lib/portal/commons-dbcp.jar:lib/portal/commons-digester.jar:lib/portal/commons-discovery.jar:lib/portal/commons-email.jar:lib/portal/commons-fileupload.jar:lib/portal/commons-httpclient.jar:lib/portal/commons-io.jar:lib/portal/commons-lang.jar:lib/portal/commons-logging.jar:lib/portal/commons-math.jar:lib/portal/commons-pool.jar:lib/portal/commons-validator.jar:lib/portal/compass.jar:lib/portal/concurrent.jar:lib/portal/crypt.jar:lib/portal/daim.jar:lib/portal/daisydiff.jar:lib/portal/displaytag.jar:lib/portal/dom4j.jar:lib/portal/easyconf.jar:lib/portal/eclipselink.jar:lib/portal/eclipse-core-runtime.jar:lib/portal/ecs.jar:lib/portal/ehcache-jgroupsreplication.jar:lib/portal/ehcache.jar:lib/portal/flexjson.jar:lib/portal/fontbox.jar:lib/portal/freemarker.jar:lib/portal/freshcookies-security.jar:lib/portal/gif89.jar:alib/portal/groovy.jar:lib/portal/gt-coverage.jar:lib/portal/gt-metadata.jar:lib/portal/hessian.jar:lib/portal/hibernate3.jar:lib/portal/h™lparser.jar:lib/portal/ical4j.jar:lib/portal/icq.jar:lib/portal/jabsorb.jar:lib/portal/jackrabbit-api.jar:lib/portal/jackrabbit-core.jar:lib/portal/jackrabbit-jcr-commons.jar:lib/portal/jackrabbit-spi-commons.jar:lib/portal/jackrabbit-spi.jar:lib/portal/jai_codec.jar:lib/portal/jai_core.jar:lib/portal/jamwiki-core.jar:lib/portal/javassist.jar:lib/portal/java-diff.jar:lib/portal/jaxb-impl.jar:lib/portal/jaxen.jar:lib/portal/jaxrpc.jar:lib/portal/jaxws-rt.jar:lib/portal/jazzy.jar:lib/portal/jcifs.jar:lib/portal/jcommon.jar:lib/portal/jcr.jar:lib/portal/jdom.jar:lib/portal/jempbox.jar:lib/portal/jena.jar:lib/portal/jericho-html.jar:lib/portal/jets3t.jar:lib/portal/jfreechart.jar:lib/portal/jgroups.jar:lib/portal/jhlabs-filters.jar:lib/portal/jodconverter.jar:lib/portal/jodd-wot.jar:lib/portal/jodd.jar:lib/portal/jrcs-diff.jar:lib/portal/jruby.jar:lib/portal/jsonrpc.jar:lib/portal/jspwiki.jar:lib/portal/jsr107cache.jar:lib/portal/jstl-api.jar:lib/portal/jstl-impl.jar:lib/portal/juh.jar:lib/portal/jurt.jar:lib/portal/jython.jar:lib/portal/liferay-icu4j.jar:lib/portal/liferay-rhino.jar:lib/portal/liferay-yuicompressor.jar:lib/portal/log4j.jar:lib/portal/lucene-analyzers.jar:lib/portal/lucene-core.jar:lib/portal/lucene-highlighter.jar:lib/portal/lucene-memory.jar:lib/portal/memcached.jar:lib/portal/metadata-extractor.jar:lib/portal/mimepull.jar:lib/portal/msnm.jar:lib/portal/nekoh™l.jar:lib/portal/odmg.jar:lib/portal/openid4java.jar:lib/portal/oro.jar:lib/portal/oscache.jar:lib/portal/pdfbox.jar:lib/portal/poi-ooxml-schemas.jar:lib/portal/poi-ooxml.jar:lib/portal/poi-scratchpad.jar:lib/portal/poi.jar:lib/portal/portal-client.jar:lib/portal/portals-bridges.jar:lib/portal/portletbridge-core.jar:lib/portal/portletbridge-portlet.jar:lib/portal/primrose.jar:lib/portal/quartz.jar:lib/portal/rdffilter.jar:lib/portal/ridl.jar:lib/portal/rome.jar:lib/portal/ruby-gems.jar:lib/portal/saaj-api.jar:lib/portal/saaj-impl.jar:lib/portal/scribe.jar:lib/portal/serializer.jar:lib/portal/simplecaptcha.jar:lib/portal/slf4j-api.jar:lib/portal/slf4j-log4j12.jar:lib/portal/soap.jar:lib/portal/spring-aop.jar:lib/portal/spring-asm.jar:lib/portal/spring-aspects.jar:lib/portal/spring-beans.jar:lib/portal/spring-context.jar:lib/portal/spring-context-support.jar:lib/portal/spring-core.jar:lib/portal/spring-expression.jar:lib/portal/spring-jdbc.jar:lib/portal/spring-jms.jar:lib/portal/spring-orm.jar:lib/portal/spring-oxm.jar:lib/portal/spring-transaction.jar:lib/portal/spring-web.jar:lib/portal/spring-web-portlet.jar:lib/portal/spring-web-servlet.jar:lib/portal/spring-web-struts.jar:lib/portal/stax-ex.jar:lib/portal/stax.jar:lib/portal/streambuffer.jar:lib/portal/struts-el.jar:lib/portal/struts.jar:lib/portal/tagsoup.jar:lib/portal/tika-core.jar:lib/portal/tika-parsers.jar:lib/portal/truezip.jar:lib/portal/unoil.jar:lib/portal/urlrewrite.jar:lib/portal/vaadin.jar:lib/portal/velocity-tools.jar:lib/portal/velocity.jar:lib/portal/wsdl4j.jar:lib/portal/wstx.jar:lib/portal/xalan.jar:lib/portal/xbean.jar:lib/portal/xbean-spring.jar:lib/portal/xercesImpl.jar:lib/portal/xml-apis.jar:lib/portal/xmlsec.jar:lib/portal/xpp3.jar:lib/portal/xstream.jar + lib/development/activation.jar:lib/development/annotations.jar:lib/development/ant-apache-bsf.jar:lib/development/ant-contrib.jar:lib/development/ant-ext.jar:lib/development/ant-installer.jar:lib/development/antelope.jar:lib/development/catalina.jar:lib/development/ckpackager.jar:lib/development/deployment.jar:lib/development/derby.jar:lib/development/derbytools.jar:lib/development/dtddoc.jar:lib/development/dtdparser.jar:lib/development/ecj.jar:lib/development/firebird.jar:lib/development/hamcrest-core.jar:lib/development/hamcrest-library.jar:lib/development/hsql.jar:lib/development/icefaces-comps.jar:lib/development/icefaces-facelets.jar:lib/development/icefaces.jar:lib/development/interbase.jar:lib/development/j2h.jar:lib/development/jaas.jar:lib/development/jakarta-regexp.jar:lib/development/jalopy.jar:lib/development/jargs.jar:lib/development/jaxb-api.jar:lib/development/jbi_rt.jar:lib/development/jetty.jar:lib/development/jetty-util.jar:lib/development/jhighlight.jar:lib/development/jmock.jar:lib/development/jmock-junit4.jar:lib/development/jms.jar:lib/development/jndi.jar:lib/development/jnet.jar:lib/development/jsf-api.jar:lib/development/jsf-facelets.jar:lib/development/jsf-impl.jar:lib/development/jsf-portlet.jar:lib/development/jsp-api.jar:lib/development/jta.jar:lib/development/jtds.jar:lib/development/junit.jar:lib/development/just-ice.jar:lib/development/jutf7.jar:lib/development/jymsg.jar:lib/development/mail.jar:lib/development/myfaces-api.jar:lib/development/myfaces-impl.jar:lib/development/mysql.jar:lib/development/objenesis.jar:lib/development/orangevolt-ant-tasks.jar:lib/development/p6spy.jar:lib/development/persistence.jar:lib/development/postgresql.jar:lib/development/qdox.jar:lib/development/resin.jar:lib/development/sap.jar:lib/development/saxpath.jar:lib/development/script-10.jar:lib/development/sdk-addon-api-0.2.jar:lib/development/selenium-java-client-driver.jar:lib/development/selenium-server.jar:lib/development/servlet-api.jar:lib/development/smtp.jar:lib/development/spring-instrument.jar:lib/development/spring-instrument-tomcat.jar:lib/development/spring-test.jar:lib/development/tomcat-coyote.jar:lib/development/xmltask.jar:lib/global/portlet.jar:lib/portal/abdera.jar:lib/portal/alloy-taglib.jar:lib/portal/ant.jar:lib/portal/antlr.jar:lib/portal/aopalliance.jar:lib/portal/asm-analysis.jar:lib/portal/asm-commons.jar:lib/portal/asm-tree.jar:lib/portal/asm-util.jar:lib/portal/asm-xml.jar:lib/portal/asm.jar:lib/portal/aspectj-rt.jar:lib/portal/aspectj-weaver.jar:lib/portal/axiom-api.jar:lib/portal/axiom-impl.jar:lib/portal/axis-ant.jar:lib/portal/axis.jar:lib/portal/backport-concurrent.jar:lib/portal/bcmail.jar:lib/portal/bcprov.jar:lib/portal/bobo-browse.jar:lib/portal/bsh.jar:lib/portal/bsf.jar:lib/portal/c3p0.jar:lib/portal/cas-client-core.jar:lib/portal/ccpp-ri.jar:lib/portal/ccpp.jar:lib/portal/cglib.jar:lib/portal/chardet.jar:lib/portal/chemistry-opencmis-client-api.jar:lib/portal/chemistry-opencmis-client-bindings.jar:lib/portal/chemistry-opencmis-client-impl.jar:lib/portal/chemistry-opencmis-commons-api.jar:lib/portal/chemistry-opencmis-commons-impl.jar:lib/portal/commons-beanutils.jar:lib/portal/commons-codec.jar:lib/portal/commons-collections.jar:lib/portal/commons-compress.jar:lib/portal/commons-configuration.jar:lib/portal/commons-dbcp.jar:lib/portal/commons-digester.jar:lib/portal/commons-discovery.jar:lib/portal/commons-email.jar:lib/portal/commons-fileupload.jar:lib/portal/commons-httpclient.jar:lib/portal/commons-io.jar:lib/portal/commons-lang.jar:lib/portal/commons-logging.jar:lib/portal/commons-math.jar:lib/portal/commons-pool.jar:lib/portal/commons-validator.jar:lib/portal/compass.jar:lib/portal/concurrent.jar:lib/portal/crypt.jar:lib/portal/daim.jar:lib/portal/daisydiff.jar:lib/portal/displaytag.jar:lib/portal/dom4j.jar:lib/portal/easyconf.jar:lib/portal/eclipselink.jar:lib/portal/eclipse-core-runtime.jar:lib/portal/ecs.jar:lib/portal/ehcache-jgroupsreplication.jar:lib/portal/ehcache.jar:lib/portal/fastutil.jar:lib/portal/flexjson.jar:lib/portal/fontbox.jar:lib/portal/freemarker.jar:lib/portal/freshcookies-security.jar:lib/portal/gif89.jar:alib/portal/groovy.jar:lib/portal/gt-coverage.jar:lib/portal/gt-metadata.jar:lib/portal/hessian.jar:lib/portal/hibernate3.jar:lib/portal/h™lparser.jar:lib/portal/ical4j.jar:lib/portal/icq.jar:lib/portal/jabsorb.jar:lib/portal/jackrabbit-api.jar:lib/portal/jackrabbit-core.jar:lib/portal/jackrabbit-jcr-commons.jar:lib/portal/jackrabbit-spi-commons.jar:lib/portal/jackrabbit-spi.jar:lib/portal/jai_codec.jar:lib/portal/jai_core.jar:lib/portal/jamwiki-core.jar:lib/portal/javassist.jar:lib/portal/java-diff.jar:lib/portal/jaxb-impl.jar:lib/portal/jaxen.jar:lib/portal/jaxrpc.jar:lib/portal/jaxws-rt.jar:lib/portal/jazzy.jar:lib/portal/jcifs.jar:lib/portal/jcommon.jar:lib/portal/jcr.jar:lib/portal/jdom.jar:lib/portal/jempbox.jar:lib/portal/jena.jar:lib/portal/jericho-html.jar:lib/portal/jets3t.jar:lib/portal/jfreechart.jar:lib/portal/jgroups.jar:lib/portal/jhlabs-filters.jar:lib/portal/jodconverter.jar:lib/portal/jodd-wot.jar:lib/portal/jodd.jar:lib/portal/jrcs-diff.jar:lib/portal/jruby.jar:lib/portal/jsonrpc.jar:lib/portal/jspwiki.jar:lib/portal/jsr107cache.jar:lib/portal/jstl-api.jar:lib/portal/jstl-impl.jar:lib/portal/juh.jar:lib/portal/jurt.jar:lib/portal/jython.jar:lib/portal/liferay-icu4j.jar:lib/portal/liferay-rhino.jar:lib/portal/liferay-yuicompressor.jar:lib/portal/log4j.jar:lib/portal/lucene-analyzers.jar:lib/portal/lucene-core.jar:lib/portal/lucene-highlighter.jar:lib/portal/lucene-memory.jar:lib/portal/memcached.jar:lib/portal/metadata-extractor.jar:lib/portal/mimepull.jar:lib/portal/msnm.jar:lib/portal/nekoh™l.jar:lib/portal/odmg.jar:lib/portal/openid4java.jar:lib/portal/oro.jar:lib/portal/oscache.jar:lib/portal/pdfbox.jar:lib/portal/poi-ooxml-schemas.jar:lib/portal/poi-ooxml.jar:lib/portal/poi-scratchpad.jar:lib/portal/poi.jar:lib/portal/portal-client.jar:lib/portal/portals-bridges.jar:lib/portal/portletbridge-core.jar:lib/portal/portletbridge-portlet.jar:lib/portal/primrose.jar:lib/portal/quartz.jar:lib/portal/rdffilter.jar:lib/portal/ridl.jar:lib/portal/rome.jar:lib/portal/ruby-gems.jar:lib/portal/saaj-api.jar:lib/portal/saaj-impl.jar:lib/portal/scribe.jar:lib/portal/serializer.jar:lib/portal/simplecaptcha.jar:lib/portal/slf4j-api.jar:lib/portal/slf4j-log4j12.jar:lib/portal/soap.jar:lib/portal/spring-aop.jar:lib/portal/spring-asm.jar:lib/portal/spring-aspects.jar:lib/portal/spring-beans.jar:lib/portal/spring-context.jar:lib/portal/spring-context-support.jar:lib/portal/spring-core.jar:lib/portal/spring-expression.jar:lib/portal/spring-jdbc.jar:lib/portal/spring-jms.jar:lib/portal/spring-orm.jar:lib/portal/spring-oxm.jar:lib/portal/spring-transaction.jar:lib/portal/spring-web.jar:lib/portal/spring-web-portlet.jar:lib/portal/spring-web-servlet.jar:lib/portal/spring-web-struts.jar:lib/portal/stax-ex.jar:lib/portal/stax.jar:lib/portal/streambuffer.jar:lib/portal/struts-el.jar:lib/portal/struts.jar:lib/portal/tagsoup.jar:lib/portal/tika-core.jar:lib/portal/tika-parsers.jar:lib/portal/truezip.jar:lib/portal/unoil.jar:lib/portal/urlrewrite.jar:lib/portal/vaadin.jar:lib/portal/velocity-tools.jar:lib/portal/velocity.jar:lib/portal/wsdl4j.jar:lib/portal/wstx.jar:lib/portal/xalan.jar:lib/portal/xbean.jar:lib/portal/xbean-spring.jar:lib/portal/xercesImpl.jar:lib/portal/xml-apis.jar:lib/portal/xmlsec.jar:lib/portal/xpp3.jar:lib/portal/xstream.jar 1.5 diff --git a/portal-impl/src/com/liferay/portal/search/BoboFacetCollector.java b/portal-impl/src/com/liferay/portal/search/BoboFacetCollector.java index e9cec27e4a84f4..3dde4d3b748ade 100644 --- a/portal-impl/src/com/liferay/portal/search/BoboFacetCollector.java +++ b/portal-impl/src/com/liferay/portal/search/BoboFacetCollector.java @@ -14,12 +14,12 @@ package com.liferay.portal.search; -import com.liferay.portal.kernel.search.facet.collector.FacetCollector; -import com.liferay.portal.kernel.search.facet.collector.TermCollector; - import com.browseengine.bobo.api.BrowseFacet; import com.browseengine.bobo.api.FacetAccessible; +import com.liferay.portal.kernel.search.facet.collector.FacetCollector; +import com.liferay.portal.kernel.search.facet.collector.TermCollector; + import java.util.ArrayList; import java.util.List; @@ -28,12 +28,12 @@ */ public class BoboFacetCollector implements FacetCollector { - public BoboFacetCollector(String fieldName, FacetAccessible facetAccessible) { + public BoboFacetCollector( + String fieldName, FacetAccessible facetAccessible) { + _fieldName = fieldName; _facetAccessible = facetAccessible; - _termCollectors = new ArrayList(); - for (BrowseFacet browseFacet : _facetAccessible.getFacets()) { _termCollectors.add(new BoboTermCollector(browseFacet)); } @@ -52,7 +52,8 @@ public List getTermCollectors() { } private FacetAccessible _facetAccessible; - private List _termCollectors; private String _fieldName; + private List _termCollectors = + new ArrayList(); } \ No newline at end of file diff --git a/portal-impl/src/com/liferay/portal/search/BoboTermCollector.java b/portal-impl/src/com/liferay/portal/search/BoboTermCollector.java index cb4e0d79a2e873..de9af3b9813196 100644 --- a/portal-impl/src/com/liferay/portal/search/BoboTermCollector.java +++ b/portal-impl/src/com/liferay/portal/search/BoboTermCollector.java @@ -14,10 +14,10 @@ package com.liferay.portal.search; -import com.liferay.portal.kernel.search.facet.collector.TermCollector; - import com.browseengine.bobo.api.BrowseFacet; +import com.liferay.portal.kernel.search.facet.collector.TermCollector; + /** * @author Raymond Augé */ diff --git a/portal-impl/src/com/liferay/portal/search/IndexSearcherProxyBean.java b/portal-impl/src/com/liferay/portal/search/IndexSearcherProxyBean.java index 95b453bc382fd8..81470e21e4ab62 100644 --- a/portal-impl/src/com/liferay/portal/search/IndexSearcherProxyBean.java +++ b/portal-impl/src/com/liferay/portal/search/IndexSearcherProxyBean.java @@ -19,7 +19,6 @@ import com.liferay.portal.kernel.search.IndexSearcher; import com.liferay.portal.kernel.search.Query; import com.liferay.portal.kernel.search.SearchContext; -import com.liferay.portal.kernel.search.SearchException; import com.liferay.portal.kernel.search.Sort; /** @@ -30,15 +29,13 @@ public class IndexSearcherProxyBean extends BaseProxyBean implements IndexSearcher { - public Hits search(SearchContext searchContext, Query query) - throws SearchException { + public Hits search( + long companyId, Query query, Sort[] sorts, int start, int end) { throw new UnsupportedOperationException(); } - public Hits search( - long companyId, Query query, Sort[] sorts, int start, int end) { - + public Hits search(SearchContext searchContext, Query query) { throw new UnsupportedOperationException(); } diff --git a/portal-impl/src/com/liferay/portal/search/lucene/LuceneIndexSearcherImpl.java b/portal-impl/src/com/liferay/portal/search/lucene/LuceneIndexSearcherImpl.java index e8994f88026ba1..fa2d3be59865e3 100644 --- a/portal-impl/src/com/liferay/portal/search/lucene/LuceneIndexSearcherImpl.java +++ b/portal-impl/src/com/liferay/portal/search/lucene/LuceneIndexSearcherImpl.java @@ -14,6 +14,21 @@ package com.liferay.portal.search.lucene; +import com.browseengine.bobo.api.BoboBrowser; +import com.browseengine.bobo.api.BoboIndexReader; +import com.browseengine.bobo.api.Browsable; +import com.browseengine.bobo.api.BrowseHit; +import com.browseengine.bobo.api.BrowseRequest; +import com.browseengine.bobo.api.BrowseResult; +import com.browseengine.bobo.api.FacetAccessible; +import com.browseengine.bobo.api.FacetSpec.FacetSortSpec; +import com.browseengine.bobo.api.FacetSpec; +import com.browseengine.bobo.facets.FacetHandler.TermCountSize; +import com.browseengine.bobo.facets.FacetHandler; +import com.browseengine.bobo.facets.impl.MultiValueFacetHandler; +import com.browseengine.bobo.facets.impl.RangeFacetHandler; +import com.browseengine.bobo.facets.impl.SimpleFacetHandler; + import com.liferay.portal.kernel.dao.orm.QueryUtil; import com.liferay.portal.kernel.json.JSONArray; import com.liferay.portal.kernel.json.JSONObject; @@ -36,6 +51,7 @@ import com.liferay.portal.kernel.search.facet.MultiValueFacet; import com.liferay.portal.kernel.search.facet.RangeFacet; import com.liferay.portal.kernel.search.facet.SimpleFacet; +import com.liferay.portal.kernel.search.facet.collector.FacetCollector; import com.liferay.portal.kernel.search.facet.config.FacetConfiguration; import com.liferay.portal.kernel.util.ArrayUtil; import com.liferay.portal.kernel.util.StringPool; @@ -45,21 +61,6 @@ import com.liferay.portal.search.BoboFacetCollector; import com.liferay.portal.util.PropsValues; -import com.browseengine.bobo.api.BoboBrowser; -import com.browseengine.bobo.api.BoboIndexReader; -import com.browseengine.bobo.api.Browsable; -import com.browseengine.bobo.api.BrowseHit; -import com.browseengine.bobo.api.BrowseRequest; -import com.browseengine.bobo.api.BrowseResult; -import com.browseengine.bobo.api.FacetAccessible; -import com.browseengine.bobo.api.FacetSpec; -import com.browseengine.bobo.api.FacetSpec.FacetSortSpec; -import com.browseengine.bobo.facets.FacetHandler; -import com.browseengine.bobo.facets.FacetHandler.TermCountSize; -import com.browseengine.bobo.facets.impl.MultiValueFacetHandler; -import com.browseengine.bobo.facets.impl.RangeFacetHandler; -import com.browseengine.bobo.facets.impl.SimpleFacetHandler; - import java.io.IOException; import java.util.ArrayList; @@ -70,6 +71,7 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.Explanation; +import org.apache.lucene.search.ScoreDoc; import org.apache.lucene.search.SortField; import org.apache.lucene.search.TopFieldDocs; @@ -78,30 +80,128 @@ */ public class LuceneIndexSearcherImpl implements IndexSearcher { - public Hits search(SearchContext searchContext, Query query) + public Hits search( + long companyId, Query query, Sort[] sorts, int start, int end) throws SearchException { if (_log.isDebugEnabled()) { _log.debug("Query " + query); } - long companyId = searchContext.getCompanyId(); - Sort[] sorts = searchContext.getSorts(); - int start = searchContext.getStart(); - int end = searchContext.getEnd(); + Hits hits = null; + + org.apache.lucene.search.IndexSearcher indexSearcher = null; + org.apache.lucene.search.Sort luceneSort = null; + + try { + indexSearcher = LuceneHelperUtil.getSearcher(companyId, true); + + if (sorts != null) { + SortField[] sortFields = new SortField[sorts.length]; + + for (int i = 0; i < sorts.length; i++) { + Sort sort = sorts[i]; + + sortFields[i] = new SortField( + sort.getFieldName(), sort.getType(), sort.isReverse()); + } + + luceneSort = new org.apache.lucene.search.Sort(sortFields); + } + else { + luceneSort = new org.apache.lucene.search.Sort(); + } + + long startTime = System.currentTimeMillis(); + + TopFieldDocs topFieldDocs = indexSearcher.search( + (org.apache.lucene.search.Query)QueryTranslatorUtil.translate( + query), + null, PropsValues.INDEX_SEARCH_LIMIT, luceneSort); + + long endTime = System.currentTimeMillis(); + + float searchTime = (float)(endTime - startTime) / Time.SECOND; + + hits = toHits( + indexSearcher, new HitDocs(topFieldDocs), query, startTime, + searchTime, start, end); + } + catch (BooleanQuery.TooManyClauses tmc) { + int maxClauseCount = BooleanQuery.getMaxClauseCount(); + + BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE); + + try { + long startTime = System.currentTimeMillis(); + + TopFieldDocs topFieldDocs = indexSearcher.search( + (org.apache.lucene.search.Query) + QueryTranslatorUtil.translate(query), + null, PropsValues.INDEX_SEARCH_LIMIT, luceneSort); + + long endTime = System.currentTimeMillis(); + + float searchTime = (float)(endTime - startTime) / Time.SECOND; + + hits = toHits( + indexSearcher, new HitDocs(topFieldDocs), query, startTime, + searchTime, start, end); + } + catch (Exception e) { + throw new SearchException(e); + } + finally { + BooleanQuery.setMaxClauseCount(maxClauseCount); + } + } + catch (ParseException pe) { + _log.error("Query " + query, pe); + + return new HitsImpl(); + } + catch (Exception e) { + throw new SearchException(e); + } + finally { + if (indexSearcher != null) { + try { + indexSearcher.close(); + } + catch (IOException ioe) { + _log.error(ioe, ioe); + } + } + } + + if (_log.isDebugEnabled()) { + _log.debug( + "Search found " + hits.getLength() + " results in " + + hits.getSearchTime() + "ms"); + } + + return hits; + } + + public Hits search(SearchContext searchContext, Query query) + throws SearchException { + + if (_log.isDebugEnabled()) { + _log.debug("Query " + query); + } Hits hits = null; org.apache.lucene.search.IndexSearcher indexSearcher = null; - BoboIndexReader boboReader = null; - Browsable browser = null; - BrowseRequest browseRequest = null; Map facets = null; + BrowseRequest browseRequest = null; + Browsable browsable = null; try { - indexSearcher = LuceneHelperUtil.getSearcher(companyId, true); + indexSearcher = LuceneHelperUtil.getSearcher( + searchContext.getCompanyId(), true); - List> handlerList = + List> facetHandlers = new ArrayList>(); facets = searchContext.getFacets(); @@ -114,26 +214,28 @@ public Hits search(SearchContext searchContext, Query query) FacetConfiguration facetConfiguration = facet.getFacetConfiguration(); - JSONObject dataJSONObject = facetConfiguration.getData(); - if (facet instanceof MultiValueFacet) { MultiValueFacetHandler multiValueFacetHandler = new MultiValueFacetHandler( facetConfiguration.getFieldName(), facetConfiguration.getFieldName()); + JSONObject dataJSONObject = facetConfiguration.getData(); + if (dataJSONObject.has("maxTerms")) { multiValueFacetHandler.setMaxItems( dataJSONObject.getInt("maxTerms")); } - handlerList.add(multiValueFacetHandler); + facetHandlers.add(multiValueFacetHandler); } else if (facet instanceof RangeFacet) { List ranges = new ArrayList(); - JSONArray rangesJSONArray = - facetConfiguration.getData().getJSONArray("ranges"); + JSONObject dataJSONObject = facetConfiguration.getData(); + + JSONArray rangesJSONArray = dataJSONObject.getJSONArray( + "ranges"); if (rangesJSONArray != null) { for (int i = 0; i < rangesJSONArray.length(); i++) { @@ -151,7 +253,7 @@ else if (facet instanceof RangeFacet) { rangeFacetHandler.setTermCountSize(TermCountSize.large); - handlerList.add(rangeFacetHandler); + facetHandlers.add(rangeFacetHandler); } else if (facet instanceof SimpleFacet) { SimpleFacetHandler simpleFacetHandler = @@ -159,15 +261,17 @@ else if (facet instanceof SimpleFacet) { facetConfiguration.getFieldName(), facetConfiguration.getFieldName()); - handlerList.add(simpleFacetHandler); + facetHandlers.add(simpleFacetHandler); } } - boboReader = BoboIndexReader.getInstance( - indexSearcher.getIndexReader(), handlerList); + BoboIndexReader boboIndexReader = BoboIndexReader.getInstance( + indexSearcher.getIndexReader(), facetHandlers); SortField[] sortFields = new SortField[0]; + Sort[] sorts = searchContext.getSorts(); + if (sorts != null) { sortFields = new SortField[sorts.length]; @@ -189,27 +293,28 @@ else if (facet instanceof SimpleFacet) { FacetConfiguration facetConfiguration = facet.getFacetConfiguration(); - FacetSpec spec = new FacetSpec(); - spec.setOrderBy( + FacetSpec facetSpec = new FacetSpec(); + + facetSpec.setOrderBy( FacetSortSpec.valueOf(facetConfiguration.getOrder())); - browseRequest.setFacetSpec(facet.getFieldName(), spec); + browseRequest.setFacetSpec(facet.getFieldName(), facetSpec); } browseRequest.setCount(PropsValues.INDEX_SEARCH_LIMIT); browseRequest.setOffset(0); - browseRequest.setSort(sortFields); browseRequest.setQuery( (org.apache.lucene.search.Query)QueryTranslatorUtil.translate( query)); + browseRequest.setSort(sortFields); - browser = new BoboBrowser(boboReader); + browsable = new BoboBrowser(boboIndexReader); long startTime = System.currentTimeMillis(); - BrowseResult result = browser.browse(browseRequest); + BrowseResult browseResult = browsable.browse(browseRequest); - BrowseHit[] browseHits = result.getHits(); + BrowseHit[] browseHits = browseResult.getHits(); long endTime = System.currentTimeMillis(); @@ -217,20 +322,21 @@ else if (facet instanceof SimpleFacet) { hits = toHits( indexSearcher, new HitDocs(browseHits), query, startTime, - searchTime, start, end); + searchTime, searchContext.getStart(), searchContext.getEnd()); - Map facetMap = result.getFacetMap(); + Map facetMap = browseResult.getFacetMap(); - for (Map.Entry facetEntry : + for (Map.Entry entry : facetMap.entrySet()) { - Facet facet = facets.get(facetEntry.getKey()); + Facet facet = facets.get(entry.getKey()); - FacetAccessible facetAccessible = facetEntry.getValue(); + FacetAccessible facetAccessible = entry.getValue(); - facet.setFacetCollector( - new BoboFacetCollector( - facetEntry.getKey(), facetAccessible)); + FacetCollector facetCollector = new BoboFacetCollector( + entry.getKey(), facetAccessible); + + facet.setFacetCollector(facetCollector); } } catch (BooleanQuery.TooManyClauses tmc) { @@ -241,7 +347,7 @@ indexSearcher, new HitDocs(browseHits), query, startTime, try { long startTime = System.currentTimeMillis(); - BrowseResult result = browser.browse(browseRequest); + BrowseResult result = browsable.browse(browseRequest); BrowseHit[] browseHits = result.getHits(); @@ -251,123 +357,23 @@ indexSearcher, new HitDocs(browseHits), query, startTime, hits = toHits( indexSearcher, new HitDocs(browseHits), query, startTime, - searchTime, start, end); + searchTime, searchContext.getStart(), + searchContext.getEnd()); - Map facetMap = result.getFacetMap(); + Map facetMap = result.getFacetMap(); - for (Map.Entry facetEntry : + for (Map.Entry entry : facetMap.entrySet()) { - Facet facet = facets.get(facetEntry.getKey()); - - FacetAccessible facetAccessible = facetEntry.getValue(); - - facet.setFacetCollector( - new BoboFacetCollector(facetEntry.getKey(), facetAccessible)); - } - } - catch (Exception e) { - throw new SearchException(e); - } - finally { - BooleanQuery.setMaxClauseCount(maxClauseCount); - } - } - catch (ParseException pe) { - _log.error("Query: " + query, pe); - - return new HitsImpl(); - } - catch (Exception e) { - throw new SearchException(e); - } - finally { - if (browser != null) { - try { - browser.close(); - } - catch (IOException ioe) { - _log.error(ioe, ioe); - } - } - } - - if (_log.isDebugEnabled()) { - _log.debug( - "Search found " + hits.getLength() + " results in " + - hits.getSearchTime() + "ms"); - } - - return hits; - } - - public Hits search( - long companyId, Query query, Sort[] sorts, int start, int end) - throws SearchException { - - if (_log.isDebugEnabled()) { - _log.debug("Query " + query); - } - - Hits hits = null; - - org.apache.lucene.search.IndexSearcher indexSearcher = null; - org.apache.lucene.search.Sort luceneSort = null; - - try { - indexSearcher = LuceneHelperUtil.getSearcher(companyId, true); + Facet facet = facets.get(entry.getKey()); - if (sorts != null) { - SortField[] sortFields = new SortField[sorts.length]; + FacetAccessible facetAccessible = entry.getValue(); - for (int i = 0; i < sorts.length; i++) { - Sort sort = sorts[i]; + FacetCollector facetCollector = new BoboFacetCollector( + entry.getKey(), facetAccessible); - sortFields[i] = new SortField( - sort.getFieldName(), sort.getType(), sort.isReverse()); + facet.setFacetCollector(facetCollector); } - - luceneSort = new org.apache.lucene.search.Sort(sortFields); - } - else { - luceneSort = new org.apache.lucene.search.Sort(); - } - - long startTime = System.currentTimeMillis(); - - TopFieldDocs topFieldDocs = indexSearcher.search( - (org.apache.lucene.search.Query)QueryTranslatorUtil.translate( - query), - null, PropsValues.INDEX_SEARCH_LIMIT, luceneSort); - - long endTime = System.currentTimeMillis(); - - float searchTime = (float)(endTime - startTime) / Time.SECOND; - - hits = toHits( - indexSearcher, new HitDocs(topFieldDocs), query, startTime, - searchTime, start, end); - } - catch (BooleanQuery.TooManyClauses tmc) { - int maxClauseCount = BooleanQuery.getMaxClauseCount(); - - BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE); - - try { - long startTime = System.currentTimeMillis(); - - TopFieldDocs topFieldDocs = indexSearcher.search( - (org.apache.lucene.search.Query) - QueryTranslatorUtil.translate(query), - null, PropsValues.INDEX_SEARCH_LIMIT, luceneSort); - - long endTime = System.currentTimeMillis(); - - float searchTime = (float)(endTime - startTime) / Time.SECOND; - - hits = toHits( - indexSearcher, new HitDocs(topFieldDocs), query, startTime, - searchTime, start, end); } catch (Exception e) { throw new SearchException(e); @@ -377,7 +383,7 @@ indexSearcher, new HitDocs(topFieldDocs), query, startTime, } } catch (ParseException pe) { - _log.error("Query: " + query, pe); + _log.error("Query " + query, pe); return new HitsImpl(); } @@ -385,9 +391,9 @@ indexSearcher, new HitDocs(topFieldDocs), query, startTime, throw new SearchException(e); } finally { - if (indexSearcher != null) { + if (browsable != null) { try { - indexSearcher.close(); + browsable.close(); } catch (IOException ioe) { _log.error(ioe, ioe); @@ -445,7 +451,7 @@ protected String[] getQueryTerms(Query query) { query)); } catch (ParseException pe) { - _log.error("Query: " + query, pe); + _log.error("Query " + query, pe); } return queryTerms; @@ -472,7 +478,7 @@ protected String getSnippet( field, s); } catch (ParseException pe) { - _log.error("Query: " + query, pe); + _log.error("Query " + query, pe); } return snippet; @@ -535,8 +541,10 @@ protected Hits toHits( break; } + int docId = hitDocs.getDocId(i); + org.apache.lucene.document.Document document = - indexSearcher.doc(hitDocs.getDocId(i)); + indexSearcher.doc(docId); Document subsetDocument = getDocument(document); @@ -552,15 +560,14 @@ protected Hits toHits( subsetSnippets.add(StringPool.BLANK); } - Float subsetScore = - hitDocs.getScore(i) / scoredFieldNamesCount; + Float subsetScore = hitDocs.getScore(i) / scoredFieldNamesCount; subsetScores.add(subsetScore); if (_log.isDebugEnabled()) { try { Explanation explanation = indexSearcher.explain( - luceneQuery, hitDocs.getDocId(i)); + luceneQuery, docId); _log.debug(explanation.toString()); } @@ -584,7 +591,10 @@ protected Hits toHits( return hits; } - public class HitDocs { + private static Log _log = LogFactoryUtil.getLog( + LuceneIndexSearcherImpl.class); + + private class HitDocs { public HitDocs(BrowseHit[] browseHits) { _browseHits = browseHits; @@ -596,7 +606,9 @@ public HitDocs(TopFieldDocs topFieldDocs) { public int getDocId(int i) { if (_topFieldDocs != null) { - return _topFieldDocs.scoreDocs[i].doc; + ScoreDoc scoreDoc = _topFieldDocs.scoreDocs[i]; + + return scoreDoc.doc; } else if (_browseHits != null) { return _browseHits[i].getDocid(); @@ -607,7 +619,9 @@ else if (_browseHits != null) { public float getScore(int i) { if (_topFieldDocs != null) { - return _topFieldDocs.scoreDocs[i].score; + ScoreDoc scoreDoc = _topFieldDocs.scoreDocs[i]; + + return scoreDoc.score; } else if (_browseHits != null) { return _browseHits[i].getScore(); @@ -632,7 +646,4 @@ else if (_browseHits != null) { } - private static Log _log = LogFactoryUtil.getLog( - LuceneIndexSearcherImpl.class); - } \ No newline at end of file diff --git a/portal-impl/src/com/liferay/portlet/bookmarks/util/BookmarksIndexer.java b/portal-impl/src/com/liferay/portlet/bookmarks/util/BookmarksIndexer.java index da1c8909828554..0a4b80d3817a79 100644 --- a/portal-impl/src/com/liferay/portlet/bookmarks/util/BookmarksIndexer.java +++ b/portal-impl/src/com/liferay/portlet/bookmarks/util/BookmarksIndexer.java @@ -15,7 +15,6 @@ package com.liferay.portlet.bookmarks.util; import com.liferay.portal.kernel.search.BaseIndexer; -import com.liferay.portal.kernel.search.BooleanQuery; import com.liferay.portal.kernel.search.Document; import com.liferay.portal.kernel.search.DocumentImpl; import com.liferay.portal.kernel.search.Field; @@ -23,7 +22,6 @@ import com.liferay.portal.kernel.search.SearchContext; import com.liferay.portal.kernel.search.SearchEngineUtil; import com.liferay.portal.kernel.search.Summary; -import com.liferay.portal.kernel.search.facet.MultiValueFacet; import com.liferay.portal.kernel.search.facet.util.FacetValueValidator; import com.liferay.portal.kernel.util.GetterUtil; import com.liferay.portal.model.Group; @@ -63,32 +61,6 @@ public String[] getClassNames() { return CLASS_NAMES; } - protected void addSearchFolderIds( - BooleanQuery contextQuery, SearchContext searchContext) - throws Exception { - - MultiValueFacet folderIdsFacet = new MultiValueFacet(searchContext); - - folderIdsFacet.setFacetValueValidator(new FacetValueValidator() { - public boolean check(SearchContext searchContext, String primKey) { - try { - BookmarksFolderServiceUtil.getFolder( - GetterUtil.getLong(primKey)); - } - catch (Exception e) { - return false; - } - - return true; - } - }); - - folderIdsFacet.setFieldName(Field.FOLDER_ID); - folderIdsFacet.setStatic(true); - - searchContext.addFacet(folderIdsFacet); - } - protected void checkSearchFolderId( long folderId, SearchContext searchContext) throws Exception { @@ -201,6 +173,25 @@ protected void doReindex(String[] ids) throws Exception { reindexRoot(companyId); } + protected FacetValueValidator getAddSearchFolderIdsFacetValueValidator() { + return new FacetValueValidator() { + + public boolean check(SearchContext searchContext, String primKey) { + + try { + BookmarksFolderServiceUtil.getFolder( + GetterUtil.getLong(primKey)); + } + catch (Exception e) { + return false; + } + + return true; + } + + }; + } + protected String getPortletId(SearchContext searchContext) { return PORTLET_ID; } diff --git a/portal-impl/src/com/liferay/portlet/documentlibrary/util/DLIndexer.java b/portal-impl/src/com/liferay/portlet/documentlibrary/util/DLIndexer.java index faff92c714320c..bfbebf1836a71e 100644 --- a/portal-impl/src/com/liferay/portlet/documentlibrary/util/DLIndexer.java +++ b/portal-impl/src/com/liferay/portlet/documentlibrary/util/DLIndexer.java @@ -26,7 +26,6 @@ import com.liferay.portal.kernel.search.SearchContext; import com.liferay.portal.kernel.search.SearchEngineUtil; import com.liferay.portal.kernel.search.Summary; -import com.liferay.portal.kernel.search.facet.MultiValueFacet; import com.liferay.portal.kernel.search.facet.util.FacetValueValidator; import com.liferay.portal.kernel.util.GetterUtil; import com.liferay.portal.kernel.util.StringUtil; @@ -82,6 +81,10 @@ public boolean hasPermission( permissionChecker, entryClassPK, ActionKeys.VIEW); } + public boolean isFilterSearch() { + return _FILTER_SEARCH; + } + public void postProcessSearchQuery( BooleanQuery searchQuery, SearchContext searchContext) throws Exception { @@ -104,31 +107,6 @@ public void postProcessSearchQuery( } } - protected void addSearchFolderIds( - BooleanQuery contextQuery, SearchContext searchContext) - throws Exception { - - MultiValueFacet folderIdsFacet = new MultiValueFacet(searchContext); - - folderIdsFacet.setFacetValueValidator(new FacetValueValidator() { - public boolean check(SearchContext searchContext, String primKey) { - try { - DLFolderServiceUtil.getFolder(GetterUtil.getLong(primKey)); - } - catch (Exception e) { - return false; - } - - return true; - } - }); - - folderIdsFacet.setFieldName(Field.FOLDER_ID); - folderIdsFacet.setStatic(true); - - searchContext.addFacet(folderIdsFacet); - } - protected void doDelete(Object obj) throws Exception { DLFileEntry fileEntry = (DLFileEntry)obj; @@ -240,12 +218,27 @@ protected void doReindex(String[] ids) throws Exception { reindexRoot(companyId); } - protected String getPortletId(SearchContext searchContext) { - return PORTLET_ID; + protected FacetValueValidator getAddSearchFolderIdsFacetValueValidator() { + return new FacetValueValidator() { + + public boolean check( + SearchContext searchContext, String primKey) { + + try { + DLFolderServiceUtil.getFolder(GetterUtil.getLong(primKey)); + } + catch (Exception e) { + return false; + } + + return true; + } + + }; } - public boolean isFilterSearch() { - return _FILTER_SEARCH; + protected String getPortletId(SearchContext searchContext) { + return PORTLET_ID; } protected void reindexFolders(long companyId) throws Exception { diff --git a/portal-impl/src/com/liferay/portlet/imagegallery/util/IGIndexer.java b/portal-impl/src/com/liferay/portlet/imagegallery/util/IGIndexer.java index c111dff5155dba..9a166e959723f5 100644 --- a/portal-impl/src/com/liferay/portlet/imagegallery/util/IGIndexer.java +++ b/portal-impl/src/com/liferay/portlet/imagegallery/util/IGIndexer.java @@ -15,7 +15,6 @@ package com.liferay.portlet.imagegallery.util; import com.liferay.portal.kernel.search.BaseIndexer; -import com.liferay.portal.kernel.search.BooleanQuery; import com.liferay.portal.kernel.search.Document; import com.liferay.portal.kernel.search.DocumentImpl; import com.liferay.portal.kernel.search.Field; @@ -23,7 +22,6 @@ import com.liferay.portal.kernel.search.SearchContext; import com.liferay.portal.kernel.search.SearchEngineUtil; import com.liferay.portal.kernel.search.Summary; -import com.liferay.portal.kernel.search.facet.MultiValueFacet; import com.liferay.portal.kernel.search.facet.util.FacetValueValidator; import com.liferay.portal.kernel.util.GetterUtil; import com.liferay.portal.kernel.util.StringUtil; @@ -65,31 +63,6 @@ public String[] getClassNames() { return CLASS_NAMES; } - protected void addSearchFolderIds( - BooleanQuery contextQuery, SearchContext searchContext) - throws Exception { - - MultiValueFacet folderIdsFacet = new MultiValueFacet(searchContext); - - folderIdsFacet.setFacetValueValidator(new FacetValueValidator() { - public boolean check(SearchContext searchContext, String primKey) { - try { - IGFolderServiceUtil.getFolder(GetterUtil.getLong(primKey)); - } - catch (Exception e) { - return false; - } - - return true; - } - }); - - folderIdsFacet.setFieldName(Field.FOLDER_ID); - folderIdsFacet.setStatic(true); - - searchContext.addFacet(folderIdsFacet); - } - protected void checkSearchFolderId( long folderId, SearchContext searchContext) throws Exception { @@ -203,6 +176,23 @@ protected void doReindex(String[] ids) throws Exception { reindexRoot(companyId); } + protected FacetValueValidator getAddSearchFolderIdsFacetValueValidator() { + return new FacetValueValidator() { + + public boolean check(SearchContext searchContext, String primKey) { + try { + IGFolderServiceUtil.getFolder(GetterUtil.getLong(primKey)); + } + catch (Exception e) { + return false; + } + + return true; + } + + }; + } + protected String getPortletId(SearchContext searchContext) { return PORTLET_ID; } diff --git a/portal-impl/src/com/liferay/portlet/messageboards/util/MBIndexer.java b/portal-impl/src/com/liferay/portlet/messageboards/util/MBIndexer.java index 3219038eeb9f72..f8307740d5477f 100644 --- a/portal-impl/src/com/liferay/portlet/messageboards/util/MBIndexer.java +++ b/portal-impl/src/com/liferay/portlet/messageboards/util/MBIndexer.java @@ -28,7 +28,6 @@ import com.liferay.portal.kernel.search.SearchContext; import com.liferay.portal.kernel.search.SearchEngineUtil; import com.liferay.portal.kernel.search.Summary; -import com.liferay.portal.kernel.search.facet.MultiValueFacet; import com.liferay.portal.kernel.search.facet.util.FacetValueValidator; import com.liferay.portal.kernel.util.GetterUtil; import com.liferay.portal.kernel.util.HtmlUtil; @@ -86,6 +85,10 @@ public boolean hasPermission( permissionChecker, entryClassPK, ActionKeys.VIEW); } + public boolean isFilterSearch() { + return _FILTER_SEARCH; + } + public void postProcessContextQuery( BooleanQuery contextQuery, SearchContext searchContext) throws Exception { @@ -98,32 +101,6 @@ public void postProcessContextQuery( } } - protected void addSearchCategoryIds( - BooleanQuery contextQuery, SearchContext searchContext) - throws Exception { - - MultiValueFacet categoryIdsFacet = new MultiValueFacet(searchContext); - - categoryIdsFacet.setFacetValueValidator(new FacetValueValidator() { - public boolean check(SearchContext searchContext, String primKey) { - try { - MBCategoryServiceUtil.getCategory( - GetterUtil.getLong(primKey)); - } - catch (Exception e) { - return false; - } - - return true; - } - }); - - categoryIdsFacet.setFieldName(Field.CATEGORY_ID); - categoryIdsFacet.setStatic(true); - - searchContext.addFacet(categoryIdsFacet); - } - protected void doDelete(Object obj) throws Exception { if (obj instanceof MBCategory) { MBCategory category = (MBCategory)obj; @@ -296,12 +273,26 @@ protected void doReindex(String[] ids) throws Exception { reindexRoot(companyId); } - protected String getPortletId(SearchContext searchContext) { - return PORTLET_ID; + protected FacetValueValidator getAddSearchCategoryIdsFacetValueValidator() { + return new FacetValueValidator() { + + public boolean check(SearchContext searchContext, String primKey) { + try { + MBCategoryServiceUtil.getCategory( + GetterUtil.getLong(primKey)); + } + catch (Exception e) { + return false; + } + + return true; + } + + }; } - public boolean isFilterSearch() { - return _FILTER_SEARCH; + protected String getPortletId(SearchContext searchContext) { + return PORTLET_ID; } protected String processContent(long messageId, String content) { diff --git a/portal-impl/src/com/liferay/portlet/wiki/util/WikiIndexer.java b/portal-impl/src/com/liferay/portlet/wiki/util/WikiIndexer.java index a7bc95716505aa..b3e286448e0858 100644 --- a/portal-impl/src/com/liferay/portlet/wiki/util/WikiIndexer.java +++ b/portal-impl/src/com/liferay/portlet/wiki/util/WikiIndexer.java @@ -26,7 +26,6 @@ import com.liferay.portal.kernel.search.SearchContext; import com.liferay.portal.kernel.search.SearchEngineUtil; import com.liferay.portal.kernel.search.Summary; -import com.liferay.portal.kernel.search.facet.MultiValueFacet; import com.liferay.portal.kernel.search.facet.util.FacetValueValidator; import com.liferay.portal.kernel.util.GetterUtil; import com.liferay.portal.kernel.util.HtmlUtil; @@ -67,17 +66,9 @@ public String[] getClassNames() { return CLASS_NAMES; } - protected String getPortletId(SearchContext searchContext) { - return PORTLET_ID; - } + protected FacetValueValidator getAddSearchNodeIdsFacetValueValidator() { + return new FacetValueValidator() { - protected void addSearchNodeIds( - BooleanQuery contextQuery, SearchContext searchContext) - throws Exception { - - MultiValueFacet nodeIdsFacet = new MultiValueFacet(searchContext); - - nodeIdsFacet.setFacetValueValidator(new FacetValueValidator() { public boolean check(SearchContext searchContext, String primKey) { try { WikiNodeServiceUtil.getNode(GetterUtil.getLong(primKey)); @@ -88,12 +79,15 @@ public boolean check(SearchContext searchContext, String primKey) { return true; } - }); - nodeIdsFacet.setFieldName(Field.NODE_ID); - nodeIdsFacet.setStatic(true); + }; + } + + protected void checkSearchNodeId( + long nodeId, SearchContext searchContext) + throws Exception { - searchContext.addFacet(nodeIdsFacet); + WikiNodeServiceUtil.getNode(nodeId); } protected void doDelete(Object obj) throws Exception { @@ -143,51 +137,6 @@ else if (obj instanceof WikiPage) { } } - protected Summary doGetSummary( - Document document, Locale locale, String snippet, - PortletURL portletURL) { - - String title = document.get(Field.TITLE); - - String content = snippet; - - if (Validator.isNull(snippet)) { - content = StringUtil.shorten(document.get(Field.CONTENT), 200); - } - - String nodeId = document.get("nodeId"); - - portletURL.setParameter("struts_action", "/wiki/view"); - portletURL.setParameter("nodeId", nodeId); - portletURL.setParameter("title", title); - - return new Summary(title, content, portletURL); - } - - protected void doReindex(Object obj) throws Exception { - WikiPage page = (WikiPage)obj; - - if (Validator.isNotNull(page.getRedirectTitle())) { - return; - } - - Document document = getDocument(page); - - SearchEngineUtil.updateDocument(page.getCompanyId(), document); - } - - protected void doReindex(String className, long classPK) throws Exception { - WikiPage page = WikiPageLocalServiceUtil.getPage(classPK); - - doReindex(page); - } - - protected void doReindex(String[] ids) throws Exception { - long companyId = GetterUtil.getLong(ids[0]); - - reindexNodes(companyId); - } - protected Document doGetDocument(Object obj) throws Exception { WikiPage page = (WikiPage)obj; @@ -238,11 +187,53 @@ protected Document doGetDocument(Object obj) throws Exception { return document; } - protected void checkSearchNodeId( - long nodeId, SearchContext searchContext) - throws Exception { + protected Summary doGetSummary( + Document document, Locale locale, String snippet, + PortletURL portletURL) { - WikiNodeServiceUtil.getNode(nodeId); + String title = document.get(Field.TITLE); + + String content = snippet; + + if (Validator.isNull(snippet)) { + content = StringUtil.shorten(document.get(Field.CONTENT), 200); + } + + String nodeId = document.get("nodeId"); + + portletURL.setParameter("struts_action", "/wiki/view"); + portletURL.setParameter("nodeId", nodeId); + portletURL.setParameter("title", title); + + return new Summary(title, content, portletURL); + } + + protected void doReindex(Object obj) throws Exception { + WikiPage page = (WikiPage)obj; + + if (Validator.isNotNull(page.getRedirectTitle())) { + return; + } + + Document document = getDocument(page); + + SearchEngineUtil.updateDocument(page.getCompanyId(), document); + } + + protected void doReindex(String className, long classPK) throws Exception { + WikiPage page = WikiPageLocalServiceUtil.getPage(classPK); + + doReindex(page); + } + + protected void doReindex(String[] ids) throws Exception { + long companyId = GetterUtil.getLong(ids[0]); + + reindexNodes(companyId); + } + + protected String getPortletId(SearchContext searchContext) { + return PORTLET_ID; } protected void reindexNodes(long companyId) throws Exception { diff --git a/portal-impl/test/com/liferay/portlet/bookmarks/service/BookmarksFolderServiceTest.java b/portal-impl/test/com/liferay/portlet/bookmarks/service/BookmarksFolderServiceTest.java index 39791b2c00ca95..2504acfaebae7d 100644 --- a/portal-impl/test/com/liferay/portlet/bookmarks/service/BookmarksFolderServiceTest.java +++ b/portal-impl/test/com/liferay/portlet/bookmarks/service/BookmarksFolderServiceTest.java @@ -19,6 +19,7 @@ import com.liferay.portal.kernel.search.Hits; import com.liferay.portal.kernel.search.Indexer; import com.liferay.portal.kernel.search.IndexerRegistryUtil; +import com.liferay.portal.kernel.search.Query; import com.liferay.portal.kernel.search.QueryConfig; import com.liferay.portal.kernel.search.SearchContext; import com.liferay.portal.kernel.util.GetterUtil; @@ -110,7 +111,9 @@ public void testSearch() throws Exception { hits = indexer.search(searchContext); - assertEquals(hits.getQuery().toString(), 0, hits.getLength()); + Query query = hits.getQuery(); + + assertEquals(query.toString(), 0, hits.getLength()); addEntry(); addEntry(); diff --git a/portal-impl/test/com/liferay/portlet/documentlibrary/service/DLAppServiceTest.java b/portal-impl/test/com/liferay/portlet/documentlibrary/service/DLAppServiceTest.java index ca75f2c03925cf..ae2cdcbbc8103b 100644 --- a/portal-impl/test/com/liferay/portlet/documentlibrary/service/DLAppServiceTest.java +++ b/portal-impl/test/com/liferay/portlet/documentlibrary/service/DLAppServiceTest.java @@ -305,7 +305,7 @@ protected void search(boolean rootFolder, String keywords) message += "file entry by " + keywords; } - message += " using query " + hits.getQuery().toString(); + message += " using query " + hits.getQuery(); assertTrue(message, found); } diff --git a/portal-service/src/com/liferay/portal/kernel/search/BaseIndexer.java b/portal-service/src/com/liferay/portal/kernel/search/BaseIndexer.java index 7a48330bbbb2e5..7c02a0802fe698 100644 --- a/portal-service/src/com/liferay/portal/kernel/search/BaseIndexer.java +++ b/portal-service/src/com/liferay/portal/kernel/search/BaseIndexer.java @@ -22,6 +22,7 @@ import com.liferay.portal.kernel.search.facet.Facet; import com.liferay.portal.kernel.search.facet.MultiValueFacet; import com.liferay.portal.kernel.search.facet.ScopeFacet; +import com.liferay.portal.kernel.search.facet.util.FacetValueValidator; import com.liferay.portal.kernel.util.GetterUtil; import com.liferay.portal.kernel.util.ListUtil; import com.liferay.portal.kernel.util.PropsKeys; @@ -56,6 +57,11 @@ */ public abstract class BaseIndexer implements Indexer { + public static final int INDEX_FILTER_SEARCH_LIMIT = GetterUtil.getInteger( + PropsUtil.get(PropsKeys.INDEX_FILTER_SEARCH_LIMIT)); + + private static final boolean _FILTER_SEARCH = false; + public void delete(Object obj) throws SearchException { try { doDelete(obj); @@ -68,10 +74,6 @@ public void delete(Object obj) throws SearchException { } } - public String getSortField(String orderByCol) { - return doGetSortField(orderByCol); - } - public Document getDocument(Object obj) throws SearchException { try { Document document = doGetDocument(obj); @@ -106,18 +108,14 @@ public Document getDocument(Object obj) throws SearchException { } } - public String getSearchEngineId() { - return SearchEngineUtil.SYSTEM_ENGINE_ID; - } - public BooleanQuery getFacetQuery( String className, SearchContext searchContext) throws Exception { BooleanQuery facetQuery = BooleanQueryFactoryUtil.create(); - facetQuery.addExactTerm(Field.PORTLET_ID, getPortletId(searchContext)); facetQuery.addExactTerm(Field.ENTRY_CLASS_NAME, className); + facetQuery.addExactTerm(Field.PORTLET_ID, getPortletId(searchContext)); if (searchContext.getUserId() > 0) { SearchPermissionChecker searchPermissionChecker = @@ -140,6 +138,14 @@ public IndexerPostProcessor[] getIndexerPostProcessors() { return _indexerPostProcessors; } + public String getSearchEngineId() { + return SearchEngineUtil.SYSTEM_ENGINE_ID; + } + + public String getSortField(String orderByCol) { + return doGetSortField(orderByCol); + } + public Summary getSummary( Document document, Locale locale, String snippet, PortletURL portletURL) @@ -264,13 +270,15 @@ public Hits search(SearchContext searchContext) throws SearchException { searchContext.setEntryClassNames( new String[] {getClassName(searchContext)}); - AssetEntriesFacet assetEntryFacet = new AssetEntriesFacet( + AssetEntriesFacet assetEntriesFacet = new AssetEntriesFacet( searchContext); - assetEntryFacet.setStatic(true); - searchContext.addFacet(assetEntryFacet); + assetEntriesFacet.setStatic(true); + + searchContext.addFacet(assetEntriesFacet); ScopeFacet scopeFacet = new ScopeFacet(searchContext); + scopeFacet.setStatic(true); searchContext.addFacet(scopeFacet); @@ -344,30 +352,44 @@ protected void addSearchAssetCategoryIds( BooleanQuery contextQuery, SearchContext searchContext) throws Exception { - MultiValueFacet assetCategoryIdsFacet = new MultiValueFacet( - searchContext); + MultiValueFacet multiValueFacet = new MultiValueFacet(searchContext); - assetCategoryIdsFacet.setFieldName(Field.ASSET_CATEGORY_IDS); - assetCategoryIdsFacet.setStatic(true); + multiValueFacet.setFieldName(Field.ASSET_CATEGORY_IDS); + multiValueFacet.setStatic(true); - searchContext.addFacet(assetCategoryIdsFacet); + searchContext.addFacet(multiValueFacet); } protected void addSearchAssetTagNames( BooleanQuery contextQuery, SearchContext searchContext) throws Exception { - MultiValueFacet assetTagNamesFacet = new MultiValueFacet(searchContext); + MultiValueFacet multiValueFacet = new MultiValueFacet(searchContext); - assetTagNamesFacet.setFieldName(Field.ASSET_TAG_NAMES); - assetTagNamesFacet.setStatic(true); + multiValueFacet.setFieldName(Field.ASSET_TAG_NAMES); + multiValueFacet.setStatic(true); - searchContext.addFacet(assetTagNamesFacet); + searchContext.addFacet(multiValueFacet); } protected void addSearchCategoryIds( BooleanQuery contextQuery, SearchContext searchContext) throws Exception { + + FacetValueValidator facetValueValidator = + getAddSearchCategoryIdsFacetValueValidator(); + + if (facetValueValidator == null) { + return; + } + + MultiValueFacet multiValueFacet = new MultiValueFacet(searchContext); + + multiValueFacet.setFacetValueValidator(facetValueValidator); + multiValueFacet.setFieldName(Field.CATEGORY_ID); + multiValueFacet.setStatic(true); + + searchContext.addFacet(multiValueFacet); } protected void addSearchExpando( @@ -408,6 +430,21 @@ protected void addSearchExpando( protected void addSearchFolderIds( BooleanQuery contextQuery, SearchContext searchContext) throws Exception { + + FacetValueValidator facetValueValidator = + getAddSearchFolderIdsFacetValueValidator(); + + if (facetValueValidator == null) { + return; + } + + MultiValueFacet multiValueFacet = new MultiValueFacet(searchContext); + + multiValueFacet.setFacetValueValidator(facetValueValidator); + multiValueFacet.setFieldName(Field.FOLDER_ID); + multiValueFacet.setStatic(true); + + searchContext.addFacet(multiValueFacet); } protected void addSearchGroupId( @@ -429,10 +466,9 @@ protected void addSearchKeywords( return; } - searchQuery.addTerms(Field.KEYWORDS, keywords, true); - searchQuery.addExactTerm(Field.ASSET_CATEGORY_NAMES, keywords); searchQuery.addExactTerm(Field.ASSET_TAG_NAMES, keywords); + searchQuery.addTerms(Field.KEYWORDS, keywords, true); addSearchExpando(searchQuery, searchContext, keywords); } @@ -440,6 +476,21 @@ protected void addSearchKeywords( protected void addSearchNodeIds( BooleanQuery contextQuery, SearchContext searchContext) throws Exception { + + FacetValueValidator facetValueValidator = + getAddSearchNodeIdsFacetValueValidator(); + + if (facetValueValidator == null) { + return; + } + + MultiValueFacet multiValueFacet = new MultiValueFacet(searchContext); + + multiValueFacet.setFacetValueValidator(facetValueValidator); + multiValueFacet.setFieldName(Field.NODE_ID); + multiValueFacet.setStatic(true); + + searchContext.addFacet(multiValueFacet); } protected void addSearchTerm( @@ -517,7 +568,7 @@ protected BooleanQuery createFullQuery( searchQuery, searchContext); } - Map facets = searchContext.getFacets(); + Map facets = searchContext.getFacets(); for (Facet facet : facets.values()) { BooleanClause facetClause = facet.getFacetClause(); @@ -596,15 +647,16 @@ protected Hits filterSearch( Document[] documents = hits.getDocs(); for (int i = 0; i < documents.length; i++) { - Document document = documents[i]; + try { + Document document = documents[i]; - String entryClassName = document.get(Field.ENTRY_CLASS_NAME); - long entryClassPK = GetterUtil.getLong( - document.get(Field.ENTRY_CLASS_PK)); + String entryClassName = document.get(Field.ENTRY_CLASS_NAME); + long entryClassPK = GetterUtil.getLong( + document.get(Field.ENTRY_CLASS_PK)); - Indexer indexer = IndexerRegistryUtil.getIndexer(entryClassName); + Indexer indexer = IndexerRegistryUtil.getIndexer( + entryClassName); - try { if (indexer.hasPermission( permissionChecker, entryClassPK, ActionKeys.VIEW)) { @@ -648,6 +700,18 @@ protected Hits filterSearch( return hits; } + protected FacetValueValidator getAddSearchCategoryIdsFacetValueValidator() { + return null; + } + + protected FacetValueValidator getAddSearchFolderIdsFacetValueValidator() { + return null; + } + + protected FacetValueValidator getAddSearchNodeIdsFacetValueValidator() { + return null; + } + protected String getClassName(SearchContext searchContext) { String[] classNames = getClassNames(); @@ -687,11 +751,6 @@ protected void setStagingAware(boolean stagingAware) { _stagingAware = stagingAware; } - private static final boolean _FILTER_SEARCH = false; - - public static final int INDEX_FILTER_SEARCH_LIMIT = GetterUtil.getInteger( - PropsUtil.get(PropsKeys.INDEX_FILTER_SEARCH_LIMIT)); - private static Log _log = LogFactoryUtil.getLog(BaseIndexer.class); private IndexerPostProcessor[] _indexerPostProcessors = diff --git a/portal-service/src/com/liferay/portal/kernel/search/FacetedSearcher.java b/portal-service/src/com/liferay/portal/kernel/search/FacetedSearcher.java index 091d5d27f33d70..d3374a1e8983e5 100644 --- a/portal-service/src/com/liferay/portal/kernel/search/FacetedSearcher.java +++ b/portal-service/src/com/liferay/portal/kernel/search/FacetedSearcher.java @@ -14,8 +14,6 @@ package com.liferay.portal.kernel.search; -import com.liferay.portal.kernel.log.Log; -import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.search.facet.Facet; import com.liferay.portal.kernel.util.GetterUtil; import com.liferay.portal.kernel.util.SetUtil; @@ -112,9 +110,8 @@ protected void addSearchExpandoKeywords( String keywords, String className) throws Exception { - ExpandoBridge expandoBridge = - ExpandoBridgeFactoryUtil.getExpandoBridge( - searchContext.getCompanyId(), className); + ExpandoBridge expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge( + searchContext.getCompanyId(), className); Set attributeNames = SetUtil.fromEnumeration( expandoBridge.getAttributeNames()); @@ -182,10 +179,9 @@ protected BooleanQuery createFullQuery( String keywords = searchContext.getKeywords(); if (Validator.isNotNull(keywords)) { - searchQuery.addTerms(Field.KEYWORDS, keywords, true); - searchQuery.addExactTerm(Field.ASSET_CATEGORY_NAMES, keywords); searchQuery.addExactTerm(Field.ASSET_TAG_NAMES, keywords); + searchQuery.addTerms(Field.KEYWORDS, keywords, true); } for (String entryClassName : searchContext.getEntryClassNames()) { @@ -210,7 +206,7 @@ protected BooleanQuery createFullQuery( } } - Map facets = searchContext.getFacets(); + Map facets = searchContext.getFacets(); for (Facet facet : facets.values()) { BooleanClause facetClause = facet.getFacetClause(); @@ -315,6 +311,4 @@ protected void postProcessFullQuery( throws Exception { } - private static Log _log = LogFactoryUtil.getLog(BaseIndexer.class); - } \ No newline at end of file diff --git a/portal-service/src/com/liferay/portal/kernel/search/IndexSearcher.java b/portal-service/src/com/liferay/portal/kernel/search/IndexSearcher.java index bc147fb97a3aaf..c580f2d3db6fda 100644 --- a/portal-service/src/com/liferay/portal/kernel/search/IndexSearcher.java +++ b/portal-service/src/com/liferay/portal/kernel/search/IndexSearcher.java @@ -24,11 +24,11 @@ @MessagingProxy(mode = ProxyMode.SYNC) public interface IndexSearcher { - public Hits search(SearchContext searchContext, Query query) - throws SearchException; - public Hits search( long companyId, Query query, Sort[] sort, int start, int end) throws SearchException; + public Hits search(SearchContext searchContext, Query query) + throws SearchException; + } \ No newline at end of file diff --git a/portal-service/src/com/liferay/portal/kernel/search/Indexer.java b/portal-service/src/com/liferay/portal/kernel/search/Indexer.java index e5b4058c160b38..2e0384bb7165b8 100644 --- a/portal-service/src/com/liferay/portal/kernel/search/Indexer.java +++ b/portal-service/src/com/liferay/portal/kernel/search/Indexer.java @@ -35,14 +35,14 @@ public interface Indexer { public Document getDocument(Object obj) throws SearchException; - public String getSearchEngineId(); - public BooleanQuery getFacetQuery( String className, SearchContext searchContext) throws Exception; public IndexerPostProcessor[] getIndexerPostProcessors(); + public String getSearchEngineId(); + public String getSortField(String orderByCol); public Summary getSummary( diff --git a/portal-service/src/com/liferay/portal/kernel/search/IndexerWrapper.java b/portal-service/src/com/liferay/portal/kernel/search/IndexerWrapper.java index 7fee5e40f4b8e0..67973e066b2ca6 100644 --- a/portal-service/src/com/liferay/portal/kernel/search/IndexerWrapper.java +++ b/portal-service/src/com/liferay/portal/kernel/search/IndexerWrapper.java @@ -41,11 +41,8 @@ public Document getDocument(Object obj) throws SearchException { return _indexer.getDocument(obj); } - public String getSearchEngineId() { - return _indexer.getSearchEngineId(); - } - - public BooleanQuery getFacetQuery(String className, SearchContext searchContext) + public BooleanQuery getFacetQuery( + String className, SearchContext searchContext) throws Exception { return _indexer.getFacetQuery(className, searchContext); @@ -55,6 +52,10 @@ public IndexerPostProcessor[] getIndexerPostProcessors() { return _indexer.getIndexerPostProcessors(); } + public String getSearchEngineId() { + return _indexer.getSearchEngineId(); + } + public String getSortField(String orderByCol) { return _indexer.getSortField(orderByCol); } diff --git a/portal-service/src/com/liferay/portal/kernel/search/SearchContext.java b/portal-service/src/com/liferay/portal/kernel/search/SearchContext.java index a8215ef7c0b5b4..596e6051a843a4 100644 --- a/portal-service/src/com/liferay/portal/kernel/search/SearchContext.java +++ b/portal-service/src/com/liferay/portal/kernel/search/SearchContext.java @@ -93,7 +93,7 @@ public Facet getFacet(String fieldName) { return _facets.get(fieldName); } - public Map getFacets() { + public Map getFacets() { return _facets; } @@ -296,7 +296,7 @@ public void setUserId(long userId) { private long _companyId; private int _end = QueryUtil.ALL_POS; private String[] _entryClassNames; - private Map _facets = new ConcurrentHashMap(); + private Map _facets = new ConcurrentHashMap(); private long[] _folderIds; private long[] _groupIds; private boolean _includeLiveGroups = true; diff --git a/portal-service/src/com/liferay/portal/kernel/search/SearchEngineUtil.java b/portal-service/src/com/liferay/portal/kernel/search/SearchEngineUtil.java index a4e085935f3597..d6887b775eb811 100644 --- a/portal-service/src/com/liferay/portal/kernel/search/SearchEngineUtil.java +++ b/portal-service/src/com/liferay/portal/kernel/search/SearchEngineUtil.java @@ -57,7 +57,9 @@ public static void addDocument( SearchEngine searchEngine = _searchEngines.get(searchEngineId); - searchEngine.getWriter().addDocument(companyId, document); + IndexWriter indexWriter = searchEngine.getWriter(); + + indexWriter.addDocument(companyId, document); } public static void addDocuments( @@ -68,7 +70,8 @@ public static void addDocuments( } public static void addDocuments( - String searchEngineId, long companyId, Collection documents) + String searchEngineId, long companyId, + Collection documents) throws SearchException { if (isIndexReadOnly() || (documents == null) || documents.isEmpty()) { @@ -85,7 +88,9 @@ public static void addDocuments( SearchEngine searchEngine = _searchEngines.get(searchEngineId); - searchEngine.getWriter().addDocuments(companyId, documents); + IndexWriter indexWriter = searchEngine.getWriter(); + + indexWriter.addDocuments(companyId, documents); } public static void deleteDocument(long companyId, String uid) @@ -104,7 +109,9 @@ public static void deleteDocument( SearchEngine searchEngine = _searchEngines.get(searchEngineId); - searchEngine.getWriter().deleteDocument(companyId, uid); + IndexWriter indexWriter = searchEngine.getWriter(); + + indexWriter.deleteDocument(companyId, uid); } public static void deleteDocuments(long companyId, Collection uids) @@ -123,12 +130,16 @@ public static void deleteDocuments( SearchEngine searchEngine = _searchEngines.get(searchEngineId); - searchEngine.getWriter().deleteDocuments(companyId, uids); + IndexWriter indexWriter = searchEngine.getWriter(); + + indexWriter.deleteDocuments(companyId, uids); } - public static void deletePortletDocuments(long companyId, String portletId) + public static void deletePortletDocuments( + long companyId, String portletId) throws SearchException { + deletePortletDocuments(SYSTEM_ENGINE_ID, companyId, portletId); } public static void deletePortletDocuments( @@ -141,7 +152,9 @@ public static void deletePortletDocuments( SearchEngine searchEngine = _searchEngines.get(searchEngineId); - searchEngine.getWriter().deletePortletDocuments(companyId, portletId); + IndexWriter indexWriter = searchEngine.getWriter(); + + indexWriter.deletePortletDocuments(companyId, portletId); } public static PortalSearchEngine getPortalSearchEngine() { @@ -164,60 +177,57 @@ public static boolean isIndexReadOnly() { return _portalSearchEngine.isIndexReadOnly(); } - public static Hits search(SearchContext searchContext, Query query) + public static Hits search( + long companyId, long[] groupIds, long userId, String className, + Query query, int start, int end) throws SearchException { - if (_log.isDebugEnabled()) { - _log.debug("Search query " + query.toString()); + if (userId > 0) { + query = _searchPermissionChecker.getPermissionQuery( + companyId, groupIds, userId, className, query); } - SearchEngine searchEngine = _searchEngines.get( - searchContext.getSearchEngineId()); - - return searchEngine.getSearcher().search(searchContext, query); + return search( + companyId, query, SortFactoryUtil.getDefaultSorts(), start, end); } - public static Hits search(long companyId, Query query, int start, int end) + public static Hits search( + long companyId, long[] groupIds, long userId, String className, + Query query, Sort sort, int start, int end) throws SearchException { - return search(SYSTEM_ENGINE_ID, companyId, query, start, end); + if (userId > 0) { + query = _searchPermissionChecker.getPermissionQuery( + companyId, groupIds, userId, className, query); + } + + return search(companyId, query, sort, start, end); } public static Hits search( - String searchEngineId, long companyId, Query query, int start, - int end) + long companyId, long[] groupIds, long userId, String className, + Query query, Sort[] sorts, int start, int end) throws SearchException { - if (_log.isDebugEnabled()) { - _log.debug("Search query " + query.toString()); + if (userId > 0) { + query = _searchPermissionChecker.getPermissionQuery( + companyId, groupIds, userId, className, query); } - SearchEngine searchEngine = _searchEngines.get(searchEngineId); - - return searchEngine.getSearcher().search( - companyId, query, SortFactoryUtil.getDefaultSorts(), start, end); + return search(companyId, query, sorts, start, end); } - public static Hits search( - long companyId, Query query, Sort sort, int start, int end) + public static Hits search(long companyId, Query query, int start, int end) throws SearchException { - return search(SYSTEM_ENGINE_ID, companyId, query, sort, start, end); + return search(SYSTEM_ENGINE_ID, companyId, query, start, end); } public static Hits search( - String searchEngineId, long companyId, Query query, Sort sort, - int start, int end) + long companyId, Query query, Sort sort, int start, int end) throws SearchException { - if (_log.isDebugEnabled()) { - _log.debug("Search query " + query.toString()); - } - - SearchEngine searchEngine = _searchEngines.get(searchEngineId); - - return searchEngine.getSearcher().search( - companyId, query, new Sort[] {sort}, start, end); + return search(SYSTEM_ENGINE_ID, companyId, query, sort, start, end); } public static Hits search( @@ -227,59 +237,69 @@ public static Hits search( return search(SYSTEM_ENGINE_ID, companyId, query, sorts, start, end); } - public static Hits search( - String searchEngineId, long companyId, Query query, Sort[] sorts, - int start, int end) + public static Hits search(SearchContext searchContext, Query query) throws SearchException { if (_log.isDebugEnabled()) { _log.debug("Search query " + query.toString()); } - SearchEngine searchEngine = _searchEngines.get(searchEngineId); + SearchEngine searchEngine = _searchEngines.get( + searchContext.getSearchEngineId()); + + IndexSearcher indexSearcher = searchEngine.getSearcher(); - return searchEngine.getSearcher().search( - companyId, query, sorts, start, end); + return indexSearcher.search(searchContext, query); } public static Hits search( - long companyId, long[] groupIds, long userId, String className, - Query query, int start, int end) + String searchEngineId, long companyId, Query query, int start, + int end) throws SearchException { - if (userId > 0) { - query = _searchPermissionChecker.getPermissionQuery( - companyId, groupIds, userId, className, query); + if (_log.isDebugEnabled()) { + _log.debug("Search query " + query.toString()); } - return search( + SearchEngine searchEngine = _searchEngines.get(searchEngineId); + + IndexSearcher indexSearcher = searchEngine.getSearcher(); + + return indexSearcher.search( companyId, query, SortFactoryUtil.getDefaultSorts(), start, end); } public static Hits search( - long companyId, long[] groupIds, long userId, String className, - Query query, Sort sort, int start, int end) + String searchEngineId, long companyId, Query query, Sort sort, + int start, int end) throws SearchException { - if (userId > 0) { - query = _searchPermissionChecker.getPermissionQuery( - companyId, groupIds, userId, className, query); + if (_log.isDebugEnabled()) { + _log.debug("Search query " + query.toString()); } - return search(companyId, query, sort, start, end); + SearchEngine searchEngine = _searchEngines.get(searchEngineId); + + IndexSearcher indexSearcher = searchEngine.getSearcher(); + + return indexSearcher.search( + companyId, query, new Sort[] {sort}, start, end); } public static Hits search( - long companyId, long[] groupIds, long userId, String className, - Query query, Sort[] sorts, int start, int end) + String searchEngineId, long companyId, Query query, Sort[] sorts, + int start, int end) throws SearchException { - if (userId > 0) { - query = _searchPermissionChecker.getPermissionQuery( - companyId, groupIds, userId, className, query); + if (_log.isDebugEnabled()) { + _log.debug("Search query " + query.toString()); } - return search(companyId, query, sorts, start, end); + SearchEngine searchEngine = _searchEngines.get(searchEngineId); + + IndexSearcher indexSearcher = searchEngine.getSearcher(); + + return indexSearcher.search(companyId, query, sorts, start, end); } public static void setIndexReadOnly(boolean indexReadOnly) { @@ -308,7 +328,9 @@ public static void updateDocument( SearchEngine searchEngine = _searchEngines.get(searchEngineId); - searchEngine.getWriter().updateDocument(companyId, document); + IndexWriter indexWriter = searchEngine.getWriter(); + + indexWriter.updateDocument(companyId, document); } public static void updateDocuments( @@ -337,7 +359,9 @@ public static void updateDocuments( SearchEngine searchEngine = _searchEngines.get(searchEngineId); - searchEngine.getWriter().updateDocuments(companyId, documents); + IndexWriter indexWriter = searchEngine.getWriter(); + + indexWriter.updateDocuments(companyId, documents); } public static void updatePermissionFields(long resourceId) { @@ -377,7 +401,7 @@ public void setSearchPermissionChecker( private static Log _log = LogFactoryUtil.getLog(SearchEngineUtil.class); private static PortalSearchEngine _portalSearchEngine; - private static Map _searchEngines = + private static Map _searchEngines = new ConcurrentHashMap(); private static SearchPermissionChecker _searchPermissionChecker; diff --git a/portal-service/src/com/liferay/portal/kernel/search/facet/AssetEntriesFacet.java b/portal-service/src/com/liferay/portal/kernel/search/facet/AssetEntriesFacet.java index dc73129333ed4f..b7fd60a61fbba9 100644 --- a/portal-service/src/com/liferay/portal/kernel/search/facet/AssetEntriesFacet.java +++ b/portal-service/src/com/liferay/portal/kernel/search/facet/AssetEntriesFacet.java @@ -48,6 +48,7 @@ public AssetEntriesFacet(SearchContext searchContext) { super(searchContext); setFieldName(Field.ENTRY_CLASS_NAME); + initFacetClause(); } @@ -72,25 +73,27 @@ protected BooleanClause doGetFacetClause() { } try { - BooleanQuery indexerQuery = indexer.getFacetQuery( + BooleanQuery indexerBooleanQuery = indexer.getFacetQuery( entryClassName, searchContext); - if ((indexerQuery == null ) || - (indexerQuery.clauses().isEmpty())) { + if ((indexerBooleanQuery == null ) || + (indexerBooleanQuery.clauses().isEmpty())) { continue; } - indexer.postProcessContextQuery(indexerQuery, searchContext); + indexer.postProcessContextQuery( + indexerBooleanQuery, searchContext); for (IndexerPostProcessor indexerPostProcessor : indexer.getIndexerPostProcessors()) { indexerPostProcessor.postProcessContextQuery( - indexerQuery, searchContext); + indexerBooleanQuery, searchContext); } - facetQuery.add(indexerQuery, BooleanClauseOccur.SHOULD); + facetQuery.add( + indexerBooleanQuery, BooleanClauseOccur.SHOULD); if (!indexer.isStagingAware()) { continue; @@ -99,12 +102,14 @@ protected BooleanClause doGetFacetClause() { if (!searchContext.isIncludeLiveGroups() && searchContext.isIncludeStagingGroups()) { - facetQuery.addRequiredTerm(Field.STAGING_GROUP, true); + facetQuery.addRequiredTerm( + Field.STAGING_GROUP, true); } else if (searchContext.isIncludeLiveGroups() && !searchContext.isIncludeStagingGroups()) { - facetQuery.addRequiredTerm(Field.STAGING_GROUP, false); + facetQuery.addRequiredTerm( + Field.STAGING_GROUP, false); } } catch (Exception e) { @@ -122,13 +127,15 @@ else if (searchContext.isIncludeLiveGroups() && protected void initFacetClause() { SearchContext searchContext = getSearchContext(); + FacetConfiguration facetConfiguration = getFacetConfiguration(); - JSONObject data = facetConfiguration.getData(); + + JSONObject dataJSONObject = facetConfiguration.getData(); String[] entryClassNames = null; - if (data.has("values")) { - JSONArray valuesJSONArray = data.getJSONArray("values"); + if (dataJSONObject.has("values")) { + JSONArray valuesJSONArray = dataJSONObject.getJSONArray("values"); entryClassNames = new String[valuesJSONArray.length()]; @@ -171,15 +178,14 @@ protected void initFacetClause() { entryClassNames = entryClassNamesList.toArray( new String[entryClassNamesList.size()]); - if (!facetConfiguration.getData().has("values")) { + if (!dataJSONObject.has("values")) { JSONArray entriesJSONArray = JSONFactoryUtil.createJSONArray(); for (String entryClassName : entryClassNames) { entriesJSONArray.put(entryClassName); } - facetConfiguration.getData().put( - "values", entriesJSONArray); + dataJSONObject.put("values", entriesJSONArray); } } @@ -188,6 +194,4 @@ protected void initFacetClause() { private static Log _log = LogFactoryUtil.getLog(AssetEntriesFacet.class); - private BooleanClause _facetClause; - } \ No newline at end of file diff --git a/portal-service/src/com/liferay/portal/kernel/search/facet/BaseFacet.java b/portal-service/src/com/liferay/portal/kernel/search/facet/BaseFacet.java index ba0456bcc4e6df..16ad163ca3e291 100644 --- a/portal-service/src/com/liferay/portal/kernel/search/facet/BaseFacet.java +++ b/portal-service/src/com/liferay/portal/kernel/search/facet/BaseFacet.java @@ -50,6 +50,18 @@ public FacetValueValidator getFacetValueValidator() { return _facetValueValidator; } + public String getFieldName() { + return _facetConfiguration.getFieldName(); + } + + public SearchContext getSearchContext() { + return _searchContext; + } + + public boolean isStatic() { + return _facetConfiguration.isStatic(); + } + public void setFacetCollector(FacetCollector facetCollector) { _facetCollector = facetCollector; } @@ -64,18 +76,6 @@ public void setFacetValueValidator( _facetValueValidator = facetValueValidator; } - public String getFieldName() { - return _facetConfiguration.getFieldName(); - } - - public SearchContext getSearchContext() { - return _searchContext; - } - - public boolean isStatic() { - return _facetConfiguration.isStatic(); - } - public void setFieldName(String fieldName) { _facetConfiguration.setFieldName(fieldName); } @@ -86,7 +86,6 @@ public void setStatic(boolean isStatic) { protected abstract BooleanClause doGetFacetClause(); - protected BooleanClause _facetClause; private FacetCollector _facetCollector; private FacetConfiguration _facetConfiguration = new FacetConfiguration(); private FacetValueValidator _facetValueValidator; diff --git a/portal-service/src/com/liferay/portal/kernel/search/facet/MultiValueFacet.java b/portal-service/src/com/liferay/portal/kernel/search/facet/MultiValueFacet.java index e96f78bd4b7bf1..78833c3f6c59da 100644 --- a/portal-service/src/com/liferay/portal/kernel/search/facet/MultiValueFacet.java +++ b/portal-service/src/com/liferay/portal/kernel/search/facet/MultiValueFacet.java @@ -28,6 +28,7 @@ import com.liferay.portal.kernel.search.TermQuery; import com.liferay.portal.kernel.search.TermQueryFactoryUtil; import com.liferay.portal.kernel.search.facet.config.FacetConfiguration; +import com.liferay.portal.kernel.search.facet.util.FacetValueValidator; import com.liferay.portal.kernel.util.GetterUtil; import com.liferay.portal.kernel.util.StringUtil; @@ -42,13 +43,15 @@ public MultiValueFacet(SearchContext searchContext) { protected BooleanClause doGetFacetClause() { SearchContext searchContext = getSearchContext(); + FacetConfiguration facetConfiguration = getFacetConfiguration(); - JSONObject data = facetConfiguration.getData(); + + JSONObject dataJSONObject = facetConfiguration.getData(); String[] values = null; - if (isStatic() && data.has("values")) { - JSONArray valuesJSONArray = data.getJSONArray("values"); + if (isStatic() && dataJSONObject.has("values")) { + JSONArray valuesJSONArray = dataJSONObject.getJSONArray("values"); values = new String[valuesJSONArray.length()]; @@ -61,9 +64,7 @@ protected BooleanClause doGetFacetClause() { GetterUtil.getString( searchContext.getAttribute(getFieldName()))); - if ((!isStatic()) && (valuesParam != null) && - (valuesParam.length > 0)) { - + if (!isStatic() && (valuesParam != null) && (valuesParam.length > 0)) { values = valuesParam; } @@ -74,8 +75,10 @@ protected BooleanClause doGetFacetClause() { BooleanQuery facetQuery = BooleanQueryFactoryUtil.create(); for (String value : values) { + FacetValueValidator facetValueValidator = getFacetValueValidator(); + if ((searchContext.getUserId() > 0) && - (!getFacetValueValidator().check(searchContext, value))) { + (!facetValueValidator.check(searchContext, value))) { continue; } diff --git a/portal-service/src/com/liferay/portal/kernel/search/facet/RangeFacet.java b/portal-service/src/com/liferay/portal/kernel/search/facet/RangeFacet.java index 3a5bb134cca47b..5638a9178347e0 100644 --- a/portal-service/src/com/liferay/portal/kernel/search/facet/RangeFacet.java +++ b/portal-service/src/com/liferay/portal/kernel/search/facet/RangeFacet.java @@ -14,6 +14,7 @@ package com.liferay.portal.kernel.search.facet; +import com.liferay.portal.kernel.json.JSONArray; import com.liferay.portal.kernel.json.JSONObject; import com.liferay.portal.kernel.search.BooleanClause; import com.liferay.portal.kernel.search.BooleanClauseFactoryUtil; @@ -38,15 +39,18 @@ public RangeFacet(SearchContext searchContext) { protected BooleanClause doGetFacetClause() { SearchContext searchContext = getSearchContext(); + FacetConfiguration facetConfiguration = getFacetConfiguration(); - JSONObject data = facetConfiguration.getData(); - String fieldName = getFieldName(); + + JSONObject dataJSONObject = facetConfiguration.getData(); String start = StringPool.BLANK; String end = StringPool.BLANK; - if (isStatic() && data.has("ranges")) { - String rangeString = data.getJSONArray("ranges").getString(0); + if (isStatic() && dataJSONObject.has("ranges")) { + JSONArray rangesJSONArray = dataJSONObject.getJSONArray("ranges"); + + String rangeString = rangesJSONArray.getString(0); String[] range = RangeParserUtil.parserRange(rangeString); @@ -54,6 +58,8 @@ protected BooleanClause doGetFacetClause() { end = range[1]; } + String fieldName = getFieldName(); + String rangeParam = GetterUtil.getString( searchContext.getAttribute(fieldName)); @@ -68,30 +74,30 @@ protected BooleanClause doGetFacetClause() { return null; } - if (Validator.isNotNull(start) && - Validator.isNotNull(end) && - start.compareTo(end) >= 0) { + if (Validator.isNotNull(start) && Validator.isNotNull(end) && + (start.compareTo(end) >= 0)) { throw new IllegalArgumentException( - "End value must be greater than Start value."); + "End value must be greater than start value"); } - String endString = StringPool.STAR; String startString = StringPool.STAR; if (Validator.isNotNull(start)) { startString = start; } + String endString = StringPool.STAR; + if (Validator.isNotNull(end)) { endString = end; } - TermRangeQuery facetQuery = TermRangeQueryFactoryUtil.create( + TermRangeQuery facetTermRangeQuery = TermRangeQueryFactoryUtil.create( fieldName, startString, endString, true, true); return BooleanClauseFactoryUtil.create( - facetQuery, BooleanClauseOccur.MUST.getName()); + facetTermRangeQuery, BooleanClauseOccur.MUST.getName()); } } \ No newline at end of file diff --git a/portal-service/src/com/liferay/portal/kernel/search/facet/ScopeFacet.java b/portal-service/src/com/liferay/portal/kernel/search/facet/ScopeFacet.java index 070ddf53d725bb..8d60e62a180d19 100644 --- a/portal-service/src/com/liferay/portal/kernel/search/facet/ScopeFacet.java +++ b/portal-service/src/com/liferay/portal/kernel/search/facet/ScopeFacet.java @@ -45,13 +45,15 @@ public ScopeFacet(SearchContext searchContext) { protected BooleanClause doGetFacetClause() { SearchContext searchContext = getSearchContext(); + FacetConfiguration facetConfiguration = getFacetConfiguration(); - JSONObject data = facetConfiguration.getData(); + + JSONObject dataJSONObject = facetConfiguration.getData(); long[] groupIds = null; - if (data.has("values")) { - JSONArray valuesJSONArray = data.getJSONArray("values"); + if (dataJSONObject.has("values")) { + JSONArray valuesJSONArray = dataJSONObject.getJSONArray("values"); groupIds = new long[valuesJSONArray.length()]; @@ -113,8 +115,7 @@ protected BooleanClause doGetFacetClause() { groupIds[i] = parentGroupId; if (group.isLayout() || searchContext.isScopeStrict()) { - scopeGroupIdsQuery.addTerm( - Field.SCOPE_GROUP_ID, groupId); + scopeGroupIdsQuery.addTerm(Field.SCOPE_GROUP_ID, groupId); } } catch (Exception e) { diff --git a/portal-service/src/com/liferay/portal/kernel/search/facet/SimpleFacet.java b/portal-service/src/com/liferay/portal/kernel/search/facet/SimpleFacet.java index be229fe8d5b7ff..53e8d24a0a502e 100644 --- a/portal-service/src/com/liferay/portal/kernel/search/facet/SimpleFacet.java +++ b/portal-service/src/com/liferay/portal/kernel/search/facet/SimpleFacet.java @@ -35,13 +35,15 @@ public SimpleFacet(SearchContext searchContext) { protected BooleanClause doGetFacetClause() { SearchContext searchContext = getSearchContext(); + FacetConfiguration facetConfiguration = getFacetConfiguration(); - JSONObject data = facetConfiguration.getData(); + + JSONObject dataJSONObject = facetConfiguration.getData(); String value = StringPool.BLANK; - if (isStatic() && data.has("value")) { - value = data.getString("value"); + if (isStatic() && dataJSONObject.has("value")) { + value = dataJSONObject.getString("value"); } String valueParam = GetterUtil.getString( diff --git a/portal-service/src/com/liferay/portal/kernel/search/facet/config/FacetConfiguration.java b/portal-service/src/com/liferay/portal/kernel/search/facet/config/FacetConfiguration.java index efaede575036ca..5d50d7d9f5391d 100644 --- a/portal-service/src/com/liferay/portal/kernel/search/facet/config/FacetConfiguration.java +++ b/portal-service/src/com/liferay/portal/kernel/search/facet/config/FacetConfiguration.java @@ -27,11 +27,11 @@ public String getClassName() { } public JSONObject getData() { - if (_data == null) { - _data = JSONFactoryUtil.createJSONObject(); + if (_dataJSONObject == null) { + _dataJSONObject = JSONFactoryUtil.createJSONObject(); } - return _data; + return _dataJSONObject; } public String getDisplayStyle() { @@ -66,8 +66,8 @@ public void setClassName(String className) { _className = className; } - public void setData(JSONObject data) { - _data = data; + public void setDataJSONObject(JSONObject dataJSONObject) { + _dataJSONObject = dataJSONObject; } public void setDisplayStyle(String displayStyle) { @@ -95,7 +95,7 @@ public void setWeight(double weight) { } private String _className; - private JSONObject _data; + private JSONObject _dataJSONObject; private String _displayStyle; private String _fieldName; private String _label; diff --git a/portal-service/src/com/liferay/portal/kernel/search/facet/config/FacetConfigurationUtil.java b/portal-service/src/com/liferay/portal/kernel/search/facet/config/FacetConfigurationUtil.java index 527fc2ce4573c2..cdf55c8391ff24 100644 --- a/portal-service/src/com/liferay/portal/kernel/search/facet/config/FacetConfigurationUtil.java +++ b/portal-service/src/com/liferay/portal/kernel/search/facet/config/FacetConfigurationUtil.java @@ -17,6 +17,8 @@ import com.liferay.portal.kernel.json.JSONArray; import com.liferay.portal.kernel.json.JSONFactoryUtil; import com.liferay.portal.kernel.json.JSONObject; +import com.liferay.portal.kernel.log.Log; +import com.liferay.portal.kernel.log.LogFactoryUtil; import com.liferay.portal.kernel.util.Validator; import java.util.ArrayList; @@ -27,49 +29,65 @@ */ public class FacetConfigurationUtil { - public static List load(String configuration) throws Exception { - List configurationList = + public static List load(String configuration) { + List facetConfigurations = new ArrayList(); - if (Validator.isNull(configuration)) { - return configurationList; - } - try { - JSONObject configurationJSONObject = JSONFactoryUtil.createJSONObject( - configuration); + if (Validator.isNull(configuration)) { + return facetConfigurations; + } + + JSONObject configurationJSONObject = + JSONFactoryUtil.createJSONObject(configuration); JSONArray facetsJSONArray = configurationJSONObject.getJSONArray( "facets"); - if (facetsJSONArray != null) { - for (int i = 0; i < facetsJSONArray.length(); i++) { - JSONObject facetJSONObject = facetsJSONArray.getJSONObject(i); - - FacetConfiguration config = new FacetConfiguration(); - - config.setClassName(facetJSONObject.getString("className")); + if (facetsJSONArray == null) { + return facetConfigurations; + } - if (facetJSONObject.has("data")) { - config.setData(facetJSONObject.getJSONObject("data")); - } + for (int i = 0; i < facetsJSONArray.length(); i++) { + JSONObject facetJSONObject = facetsJSONArray.getJSONObject(i); - config.setDisplayStyle( - facetJSONObject.getString("displayStyle")); - config.setFieldName(facetJSONObject.getString("fieldName")); - config.setLabel(facetJSONObject.getString("label")); - config.setOrder(facetJSONObject.getString("order")); - config.setStatic(facetJSONObject.getBoolean("static")); - config.setWeight(facetJSONObject.getDouble("weight")); + FacetConfiguration facetConfiguration = + _toFacetConfiguration(facetJSONObject); - configurationList.add(config); - } + facetConfigurations.add(facetConfiguration); } } catch (Exception e) { + _log.error(e, e); + } + + return facetConfigurations; + } + + private static FacetConfiguration _toFacetConfiguration( + JSONObject facetJSONObject) { + + FacetConfiguration facetConfiguration = new FacetConfiguration(); + + facetConfiguration.setClassName(facetJSONObject.getString("className")); + + if (facetJSONObject.has("data")) { + facetConfiguration.setDataJSONObject( + facetJSONObject.getJSONObject("data")); } - return configurationList; + facetConfiguration.setDisplayStyle( + facetJSONObject.getString("displayStyle")); + facetConfiguration.setFieldName(facetJSONObject.getString("fieldName")); + facetConfiguration.setLabel(facetJSONObject.getString("label")); + facetConfiguration.setOrder(facetJSONObject.getString("order")); + facetConfiguration.setStatic(facetJSONObject.getBoolean("static")); + facetConfiguration.setWeight(facetJSONObject.getDouble("weight")); + + return facetConfiguration; } + private static Log _log = LogFactoryUtil.getLog( + FacetConfigurationUtil.class); + } \ No newline at end of file