Author: ssmiweve
Date: 2008-09-27 14:47:14 +0200 (Sat, 27 Sep 2008)
New Revision: 6851
Added:
trunk/generic.sesam/result-handler-config/src/main/java/no/sesat/search/result/handler/ClusteringHitCountResultHandlerConfig.java
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/ClusteringHitCountResultHandler.java
Log:
SKER4781 Promote ClusteringHitCountResultHandler (from Schibsted S?\195?\184k
AS)
Added:
trunk/generic.sesam/result-handler-config/src/main/java/no/sesat/search/result/handler/ClusteringHitCountResultHandlerConfig.java
===================================================================
---
trunk/generic.sesam/result-handler-config/src/main/java/no/sesat/search/result/handler/ClusteringHitCountResultHandlerConfig.java
(rev 0)
+++
trunk/generic.sesam/result-handler-config/src/main/java/no/sesat/search/result/handler/ClusteringHitCountResultHandlerConfig.java
2008-09-27 12:47:14 UTC (rev 6851)
@@ -0,0 +1,86 @@
+/* Copyright (2008) Schibsted Søk AS
+ * This file is part of SESAT.
+ *
+ * SESAT is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SESAT is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with SESAT. If not, see <http://www.gnu.org/licenses/>.
+ */
+package no.sesat.search.result.handler;
+
+import org.apache.log4j.Logger;
+import org.w3c.dom.Element;
+
+import no.sesat.search.result.handler.AbstractResultHandlerConfig.Controller;
+
+/**
+ * Result handler to fix the hit count on clustering search results where Fast
gives us a wrong hit count (too low).
+ * Uses the navigator counts instead since these are correct.
+ *
+ * @version $Id$
+ */
[EMAIL PROTECTED]("ClusteringHitCountResultHandler")
+public class ClusteringHitCountResultHandlerConfig extends
AbstractResultHandlerConfig {
+
+ // Constants -----------------------------------------------------
+
+ private static final Logger LOG =
Logger.getLogger(ClusteringHitCountResultHandlerConfig.class);
+
+ private static final long serialVersionUID = 7021379415579338168L;
+
+ private static final String DEFAULT_NAV_ID = "year";
+
+ // Attributes ----------------------------------------------------
+
+ private String navId;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ @Override
+ public AbstractResultHandlerConfig readResultHandler(final Element
element) {
+ super.readResultHandler(element);
+
+ LOG.debug("nav-id: '" + element.getAttribute("nav-id") + "'");
+ setNavId(element.getAttribute("nav-id") != null &&
element.getAttribute("nav-id") != ""
+ ? element.getAttribute("nav-id") : DEFAULT_NAV_ID);
+
+ return this;
+ }
+
+ // Getters / Setters ---------------------------------------------
+
+ /** The Nav Id to search in to find the correct hit count.
+ * @return the navId
+ */
+ public String getNavId() {
+ return navId;
+ }
+
+ /** @see #getNavId()
+ * @param navId the navId to set
+ */
+ public void setNavId(final String navId) {
+ this.navId = navId;
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
Property changes on:
trunk/generic.sesam/result-handler-config/src/main/java/no/sesat/search/result/handler/ClusteringHitCountResultHandlerConfig.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added:
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/ClusteringHitCountResultHandler.java
===================================================================
---
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/ClusteringHitCountResultHandler.java
(rev 0)
+++
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/ClusteringHitCountResultHandler.java
2008-09-27 12:47:14 UTC (rev 6851)
@@ -0,0 +1,106 @@
+/* Copyright (2008) Schibsted Søk AS
+ * This file is part of SESAT.
+ *
+ * SESAT is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SESAT is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with SESAT. If not, see <http://www.gnu.org/licenses/>.
+ */
+package no.sesat.search.result.handler;
+
+import java.util.List;
+
+import no.sesat.search.datamodel.DataModel;
+import no.sesat.search.result.FastSearchResult;
+import no.sesat.search.result.Modifier;
+import no.sesat.search.result.ResultItem;
+import no.sesat.search.result.ResultList;
+
+import org.apache.log4j.Logger;
+
+/**
+ * @see ClusteringHitCountResultHandlerConfig
+ *
+ * @version $Id$
+ */
+public class ClusteringHitCountResultHandler implements ResultHandler {
+
+ // Constants -----------------------------------------------------
+
+ private static final Logger LOG =
Logger.getLogger(ClusteringHitCountResultHandler.class);
+
+ // Attributes ----------------------------------------------------
+
+ private final ClusteringHitCountResultHandlerConfig config;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ public ClusteringHitCountResultHandler(final ResultHandlerConfig config) {
+ this.config = (ClusteringHitCountResultHandlerConfig) config;
+ }
+
+ // Public --------------------------------------------------------
+
+ public void handleResult(final Context cxt, final DataModel datamodel) {
+ final String cmdId = cxt.getSearchConfiguration().getName();
+ final String navId = config.getNavId();
+
+ LOG.debug("cmdId: " + cmdId + ", navId: " + navId);
+
+ final ResultList<? extends ResultItem> searchResult =
cxt.getSearchResult();
+
+ LOG.debug("Original hitCount: " + searchResult.getHitCount() + " (" +
cmdId + ")");
+
+ if (searchResult.getHitCount() <= 0) {
+ LOG.warn("No result, does nothing (" + cmdId + ")");
+ return;
+ }
+
+ if (!(searchResult instanceof FastSearchResult)) {
+ LOG.warn("Result is not a FastSearchResult, does nothing (" +
cmdId + ")");
+ return;
+ }
+
+ final FastSearchResult fres = (FastSearchResult) searchResult;
+ final List<Modifier> modifiers = fres.getModifiers(config.getNavId());
+
+ if (modifiers != null && modifiers.size() > 0) {
+ // Iterate over all values and sum the counts.
+ int newHitCount = 0;
+
+ for (final Modifier modifier : modifiers) {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace(modifier.getName() + " -> " +
modifier.getCount() + " (" + cmdId + ")");
+ }
+
+ newHitCount += modifier.getCount();
+ }
+
+ LOG.debug("New hitCount: " + newHitCount + " (" + cmdId + ")");
+ searchResult.setHitCount(newHitCount);
+ } else {
+ LOG.warn("Navigator '" + config.getNavId() + "' not found, does
nothing (" + cmdId + ")");
+ }
+ }
+
+ // Getters / Setters ---------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
Property changes on:
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/ClusteringHitCountResultHandler.java
___________________________________________________________________
Name: svn:keywords
+ Id
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits