Author: ssmiweve
Date: 2008-01-21 12:00:01 +0100 (Mon, 21 Jan 2008)
New Revision: 5995
Added:
trunk/generic.sesam/result-handler-config/src/main/java/no/sesat/search/result/handler/RegexpResultHandlerConfig.java
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/RegexpResultHandler.java
Removed:
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/SearchConfiguration.java
Log:
SEARCH-3991 - Access scheme mixtures not yet supported
Added:
trunk/generic.sesam/result-handler-config/src/main/java/no/sesat/search/result/handler/RegexpResultHandlerConfig.java
===================================================================
---
trunk/generic.sesam/result-handler-config/src/main/java/no/sesat/search/result/handler/RegexpResultHandlerConfig.java
(rev 0)
+++
trunk/generic.sesam/result-handler-config/src/main/java/no/sesat/search/result/handler/RegexpResultHandlerConfig.java
2008-01-21 11:00:01 UTC (rev 5995)
@@ -0,0 +1,88 @@
+/* Copyright (2006-2007) Schibsted Søk AS
+ * This file is part of SESAT.
+ * You can use, redistribute, and/or modify it, under the terms of the SESAT
License.
+ * You should have received a copy of the SESAT License along with this
program.
+ * If not, see https://dev.sesat.no/confluence/display/SESAT/SESAT+License
+
+ */
+package no.sesat.search.result.handler;
+
+import no.sesat.search.result.handler.AbstractResultHandlerConfig.Controller;
+import no.sesat.search.site.config.AbstractDocumentFactory;
+import no.sesat.search.site.config.AbstractDocumentFactory.ParseType;
+import org.w3c.dom.Element;
+
+
+/**
+ * Applies a regular expression to a specified field in every result item
+ * adding a target field matching the first capturing group in the regular
expression.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a>
+ * @version $Id$
+ */
[EMAIL PROTECTED]("RegexpResultHandler")
+public final class RegexpResultHandlerConfig extends
AbstractResultHandlerConfig {
+
+ private String field;
+ private String target;
+ private String regexp;
+
+ /**
+ *
+ * @param field
+ */
+ public void setField(final String field){
+ this.field = field;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public String getField(){
+ return field;
+ }
+
+ /**
+ *
+ * @param target
+ */
+ public void setTarget(final String target){
+ this.target = target;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public String getTarget(){
+ return target;
+ }
+
+ /**
+ *
+ * @param regexp
+ */
+ public void setRegexp(final String regexp){
+ this.regexp = regexp;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public String getRegexp(){
+ return regexp;
+ }
+
+ @Override
+ public RegexpResultHandlerConfig readResultHandler(final Element element) {
+
+ super.readResultHandler(element);
+ AbstractDocumentFactory.fillBeanProperty(this, null, "field",
ParseType.String, element, null);
+ AbstractDocumentFactory.fillBeanProperty(this, null, "target",
ParseType.String, element, null);
+ AbstractDocumentFactory.fillBeanProperty(this, null, "regexp",
ParseType.String, element, null);
+ return this;
+ }
+
+}
Property changes on:
trunk/generic.sesam/result-handler-config/src/main/java/no/sesat/search/result/handler/RegexpResultHandlerConfig.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added:
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/RegexpResultHandler.java
===================================================================
---
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/RegexpResultHandler.java
(rev 0)
+++
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/RegexpResultHandler.java
2008-01-21 11:00:01 UTC (rev 5995)
@@ -0,0 +1,60 @@
+/* Copyright (2006-2007) Schibsted Søk AS
+ * This file is part of SESAT.
+ * You can use, redistribute, and/or modify it, under the terms of the SESAT
License.
+ * You should have received a copy of the SESAT License along with this
program.
+ * If not, see https://dev.sesat.no/confluence/display/SESAT/SESAT+License
+ */
+package no.sesat.search.result.handler;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.activation.MimetypesFileTypeMap;
+import no.sesat.search.datamodel.DataModel;
+import no.sesat.search.result.ResultItem;
+
+
+/**
+ * Applies a regular expression to a specified field in every result item
+ * adding a target field matching the first capturing group in the regular
expression.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Michael Semb Wever</a>
+ * @version $Id$
+ */
+public final class RegexpResultHandler implements ResultHandler {
+
+ private final RegexpResultHandlerConfig config;
+
+ private Pattern regExPattern;
+
+ /**
+ *
+ * @param config
+ */
+ public RegexpResultHandler(final ResultHandlerConfig config){
+ this.config = (RegexpResultHandlerConfig) config;
+ }
+
+ /** [EMAIL PROTECTED] **/
+ public void handleResult(final Context cxt, final DataModel datamodel) {
+
+
+ for (final ResultItem item : cxt.getSearchResult().getResults()) {
+
+ final String field = item.getField(config.getField());
+
+ if(null != field){
+ if(null == regExPattern){
+ regExPattern = Pattern.compile(config.getRegexp());
+ }
+
+ final Matcher m = regExPattern.matcher(field);
+ if(m.find()){
+
+ cxt.getSearchResult().replaceResult(item,
item.addField(config.getTarget(), m.group(1)));
+ }
+ }
+ }
+ }
+}
+
+
\ No newline at end of file
Property changes on:
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/RegexpResultHandler.java
___________________________________________________________________
Name: svn:keywords
+ Id
Deleted:
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/SearchConfiguration.java
===================================================================
---
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/SearchConfiguration.java
2008-01-21 10:18:40 UTC (rev 5994)
+++
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/SearchConfiguration.java
2008-01-21 11:00:01 UTC (rev 5995)
@@ -1,61 +0,0 @@
-/* Copyright (2007) 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/>.
- */
-/*
- * SearchConfiguration.java
- *
- * Created on 5/08/2007, 19:44:00
- *
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package no.sesat.search.result.handler;
-
-/**
- *
- * @author mick
- * @version $Id$
- */
-class SearchConfiguration {
-
- // Constants -----------------------------------------------------
-
- //private static final Logger LOG =
Logger.getLogger(SearchConfiguration.class);
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public SearchConfiguration() {
- }
-
- // Public --------------------------------------------------------
-
- // Z implementation ----------------------------------------------
-
- // Y overrides ---------------------------------------------------
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits