Author: mickw
Date: 2006-04-27 10:59:54 +0200 (Thu, 27 Apr 2006)
New Revision: 2815

Modified:
   
trunk/src/java/no/schibstedsok/front/searchportal/command/AbstractSearchCommand.java
   
trunk/src/java/no/schibstedsok/front/searchportal/command/AbstractSimpleFastSearchCommand.java
   
trunk/src/java/no/schibstedsok/front/searchportal/command/NewsSearchCommand.java
   
trunk/src/java/no/schibstedsok/front/searchportal/command/WebSearchCommand.java
   
trunk/src/java/no/schibstedsok/front/searchportal/configuration/AbstractSearchConfiguration.java
   
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchConfiguration.java
   
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactory.java
   trunk/src/java/no/schibstedsok/front/searchportal/view/config/SearchTab.java
   
trunk/src/java/no/schibstedsok/front/searchportal/view/config/SearchTabFactory.java
   trunk/src/javacc/QueryParserImpl.jj
Log:
SEARCH-503


Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/command/AbstractSearchCommand.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/command/AbstractSearchCommand.java
        2006-04-27 08:59:29 UTC (rev 2814)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/command/AbstractSearchCommand.java
        2006-04-27 08:59:54 UTC (rev 2815)
@@ -19,6 +19,7 @@
 import no.schibstedsok.front.searchportal.query.NotClause;
 import no.schibstedsok.front.searchportal.query.OperationClause;
 import no.schibstedsok.front.searchportal.query.OrClause;
+import no.schibstedsok.front.searchportal.query.PhraseClause;
 import no.schibstedsok.front.searchportal.query.Query;
 import no.schibstedsok.front.searchportal.query.QueryStringContext;
 import no.schibstedsok.front.searchportal.query.Visitor;
@@ -74,6 +75,7 @@
 
     protected final Context context;
     private String filter = "";
+    private final String additionalFilter;
     private final Map<Clause,String> transformedTerms = new 
LinkedHashMap<Clause,String>();
     private String transformedQuery;
     private final Map parameters = new HashMap();
@@ -96,8 +98,15 @@
         this.parameters.putAll(parameters);
         transformedQuery = context.getQuery().getQueryString();
         final Clause root = context.getQuery().getRootClause();
+        
+        // initialise transformed terms
         final Visitor mapInitialisor = new MapInitialisor(transformedTerms);
         mapInitialisor.visit(root);
+        
+        // create additional filters
+        final FilterVisitor  additionalFilterVisitor = new FilterVisitor();
+        additionalFilterVisitor.visit(context.getQuery().getRootClause());
+        additionalFilter = additionalFilterVisitor.getFilter();
     }
 
    // Public --------------------------------------------------------
@@ -364,6 +373,20 @@
         return (String) transformedTerms.get(clause);
     }
 
+    /**
+     * Setter for property filter.
+     * @param filter New value of property filter.
+     */
+    protected void setFilter(final String filter) {
+        
+        LOG.debug("setFilter(\"" + filter + "\")");
+        this.filter = filter;
+    }
+    
+    protected String getAdditionalFilter() {
+        return additionalFilter;
+    }
+    
     // Private -------------------------------------------------------
 
     /**
@@ -379,7 +402,7 @@
             // initialise map with default values
 
 
-            final StringBuilder filterBuilder = new StringBuilder();
+            final StringBuilder filterBuilder = new StringBuilder(filter);
 
             for (final Iterator iterator = transformers.iterator(); 
iterator.hasNext();) {
 
@@ -504,4 +527,65 @@
             clause.getSecondClause().accept(this);
         }
     }
+
+
+    /**
+     *
+     * Visitor to create the FAST filter string. Handles the site: syntax.
+     *
+     * @todo add correct handling of NotClause and AndNotClause. This also 
needs
+     * to be added to the query builder visitor above.
+     *
+     */
+    private final class FilterVisitor extends AbstractReflectionVisitor {
+        
+        private final StringBuilder filterBuilder = new StringBuilder();
+        
+        String getFilter(){
+            return filterBuilder.toString().trim();
+        }
+
+        protected void visitImpl(final LeafClause clause) {
+            
+            final Map<String,String> fieldFilters = 
getSearchConfiguration().getFieldFilters();
+            if (fieldFilters.containsKey(clause.getField())) {
+                appendSiteFilter(clause);
+            }
+        }
+
+        protected void visitImpl(final PhraseClause clause) {
+            
+            final Map<String,String> fieldFilters = 
getSearchConfiguration().getFieldFilters();
+            if (fieldFilters.containsKey(clause.getField())) {
+                appendSiteFilter(clause);
+            }
+        }
+
+        protected void visitImpl(final DefaultOperatorClause clause) {
+            clause.getFirstClause().accept(this);
+            clause.getSecondClause().accept(this);
+        }
+
+        protected void visitImpl(final OrClause clause) {
+            clause.getFirstClause().accept(this);
+            clause.getSecondClause().accept(this);
+        }
+
+        protected void visitImpl(final AndClause clause) {
+            clause.getFirstClause().accept(this);
+            clause.getSecondClause().accept(this);
+        }
+
+        protected void visitImpl(final XorClause clause) {
+            clause.getFirstClause().accept(this);
+        }
+
+        private final void appendSiteFilter(final LeafClause clause) {
+            
+            final Map<String,String> fieldFilters = 
getSearchConfiguration().getFieldFilters();
+            filterBuilder.append(" +" + fieldFilters.get(clause.getField()) + 
":" + clause.getTerm());
+        }
+    }
+
+    
 }

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/command/AbstractSimpleFastSearchCommand.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/command/AbstractSimpleFastSearchCommand.java
      2006-04-27 08:59:29 UTC (rev 2814)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/command/AbstractSimpleFastSearchCommand.java
      2006-04-27 08:59:54 UTC (rev 2815)
@@ -498,10 +498,6 @@
         return (IFastSearchEngine) 
searchEngines.get(getFastConfiguration().getQueryServerURL());
     }
 
-    protected String getAdditionalFilter() {
-        return null;
-    }
-
     protected String getSortBy() {
 
         return getFastConfiguration().getSortBy();

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/command/NewsSearchCommand.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/command/NewsSearchCommand.java
    2006-04-27 08:59:29 UTC (rev 2814)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/command/NewsSearchCommand.java
    2006-04-27 08:59:54 UTC (rev 2815)
@@ -22,12 +22,10 @@
 /**
  *
  * @author magnuse
+ * @version $Id$
  */
 public class NewsSearchCommand extends FastSearchCommand {
 
-    private static final String FAST_SOURCE_FILTER_FIELD = "newssource";
-    private static final String SESAM_SOURCE_FIELD = "nyhetskilde";
-
     // Filter used to get all articles.
     private static final String FAST_SIZE_HACK = " +size:>0";
 
@@ -64,28 +62,15 @@
      *
      */
     protected void visitImpl(final LeafClause clause) {
-        if (! (hasSourceField(clause) || containsJustThePrefix())) {
+        if (!  containsJustThePrefix() ) {
             super.visitImpl(clause);
         }
     }
 
-    /**
-     * PhraseClause
-     *
-     * A phrase with a site field does not add anything to the query.
-     *
-     */
-    protected void visitImpl(final PhraseClause clause) {
-        if (!hasSourceField(clause)) {
-            super.visitImpl(clause);
-        }
-    }
-
     protected String getAdditionalFilter() {
         synchronized (this) {
             if (filterBuilder == null) {
-                filterBuilder = new StringBuilder();
-                new FilterVisitor().visit(context.getQuery().getRootClause());
+                filterBuilder = new StringBuilder(super.getAdditionalFilter());
             }
 
             // Add filter to retrieve all documents.
@@ -97,11 +82,6 @@
         }
     }
 
-    private boolean hasSourceField(final LeafClause clause) {
-        return clause.getField() != null
-                && clause.getField().equals(SESAM_SOURCE_FIELD);
-    }
-
     private boolean containsJustThePrefix() {
 
         final LeafClause firstLeaf = context.getQuery().getFirstLeafClause();
@@ -111,53 +91,4 @@
               || 
firstLeaf.getPossiblePredicates().contains(TokenPredicate.NEWS_MAGIC));
     }
 
-
-    /**
-     *
-     * Visitor to create the FAST filter string. Handles the nyhetskilde: 
syntax.
-     *
-     * @todo add correct handling of NotClause and AndNotClause. This also 
needs
-     * to be added to the query builder visitor above.
-     *
-     */
-    private final class FilterVisitor extends AbstractReflectionVisitor {
-
-        protected void visitImpl(final LeafClause clause) {
-            if (hasSourceField(clause)) {
-                appendSiteFilter(clause);
-            }
-        }
-
-        protected void visitImpl(final PhraseClause clause) {
-            if (hasSourceField(clause)) {
-                appendSiteFilter(clause);
-            }
-        }
-
-        protected void visitImpl(final DefaultOperatorClause clause) {
-            clause.getFirstClause().accept(this);
-            clause.getSecondClause().accept(this);
-        }
-
-        protected void visitImpl(final OrClause clause) {
-            clause.getFirstClause().accept(this);
-            clause.getSecondClause().accept(this);
-        }
-
-        protected void visitImpl(final AndClause clause) {
-            clause.getFirstClause().accept(this);
-            clause.getSecondClause().accept(this);
-        }
-
-        protected void visitImpl(final XorClause clause) {
-            clause.getFirstClause().accept(this);
-        }
-
-        private final void appendSiteFilter(final LeafClause clause) {
-            filterBuilder.append("+");
-            filterBuilder.append(FAST_SOURCE_FILTER_FIELD);
-            filterBuilder.append(':');
-            filterBuilder.append(clause.getTerm().replaceAll("\"", ""));
-        }
-    }
 }
\ No newline at end of file

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/command/WebSearchCommand.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/command/WebSearchCommand.java 
    2006-04-27 08:59:29 UTC (rev 2814)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/command/WebSearchCommand.java 
    2006-04-27 08:59:54 UTC (rev 2815)
@@ -24,9 +24,6 @@
  */
 public class WebSearchCommand extends FastSearchCommand {
 
-    private static final String FAST_SITE_FILTER_PREFIX = "site";
-    private static final String SESAM_SITE_PREFIX = "site";
-
     /** Creates a new instance of WebSearchCommand
      *
      * @param cxt Search command context.
@@ -36,7 +33,7 @@
         super(cxt, parameters);
     }
 
-    private StringBuffer filterBuilder = null;
+    
 
     /**
      *
@@ -52,91 +49,5 @@
         }
     }
 
-    /**
-     * LeafClause
-     *
-     * A leaf clause with a site field does not add anything to the query.
-     *
-     */
-    protected void visitImpl(final LeafClause clause) {
-        if (!hasSiteField(clause)) {
-            super.visitImpl(clause);
-        }
-    }
-
-    /**
-     * PhraseClause
-     *
-     * A phrase with a site field does not add anything to the query.
-     *
-     */
-    protected void visitImpl(final PhraseClause clause) {
-        if (!hasSiteField(clause)) {
-            super.visitImpl(clause);
-        }
-    }
-
-    protected String getAdditionalFilter() {
-        synchronized (this) {
-            if (filterBuilder == null) {
-                filterBuilder = new StringBuffer();
-                new FilterVisitor().visit(context.getQuery().getRootClause());
-            }
-            return filterBuilder.toString();
-        }
-    }
-
-    private final boolean hasSiteField(final LeafClause clause) {
-        return clause.getField() != null
-                && clause.getField().equals(SESAM_SITE_PREFIX);
-    }
-
-    /**
-     *
-     * Visitor to create the FAST filter string. Handles the site: syntax.
-     *
-     * @todo add correct handling of NotClause and AndNotClause. This also 
needs
-     * to be added to the query builder visitor above.
-     *
-     */
-    private final class FilterVisitor extends AbstractReflectionVisitor {
-
-        protected void visitImpl(final LeafClause clause) {
-            if (hasSiteField(clause)) {
-                appendSiteFilter(clause);
-            }
-        }
-
-        protected void visitImpl(final PhraseClause clause) {
-            if (hasSiteField(clause)) {
-                appendSiteFilter(clause);
-            }
-        }
-
-        protected void visitImpl(final DefaultOperatorClause clause) {
-            clause.getFirstClause().accept(this);
-            clause.getSecondClause().accept(this);
-        }
-
-        protected void visitImpl(final OrClause clause) {
-            clause.getFirstClause().accept(this);
-            clause.getSecondClause().accept(this);
-        }
-
-        protected void visitImpl(final AndClause clause) {
-            clause.getFirstClause().accept(this);
-            clause.getSecondClause().accept(this);
-        }
-
-        protected void visitImpl(final XorClause clause) {
-            clause.getFirstClause().accept(this);
-        }
-
-        private final void appendSiteFilter(final LeafClause clause) {
-            filterBuilder.append("+");
-            filterBuilder.append(FAST_SITE_FILTER_PREFIX);
-            filterBuilder.append(':');
-            filterBuilder.append(clause.getTerm().replaceAll("\"", ""));
-        }
-    }
+    
 }

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/AbstractSearchConfiguration.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/AbstractSearchConfiguration.java
    2006-04-27 08:59:29 UTC (rev 2814)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/AbstractSearchConfiguration.java
    2006-04-27 08:59:54 UTC (rev 2815)
@@ -2,6 +2,8 @@
 package no.schibstedsok.front.searchportal.configuration;
 
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 import no.schibstedsok.front.searchportal.query.transform.QueryTransformer;
 import no.schibstedsok.front.searchportal.result.handler.ResultHandler;
 import no.schibstedsok.front.searchportal.util.SearchConstants;
@@ -46,6 +48,7 @@
             resultHandlers.addAll(asc.resultHandlers);
             pageSize = asc.pageSize;
             resultFields.addAll(asc.resultFields);
+            fieldFilters.putAll(asc.fieldFilters);
             resultsToReturn = asc.resultsToReturn;
             isPagingEnabled = asc.isPagingEnabled;
             child = asc.child;
@@ -169,4 +172,21 @@
     public String toString(){
         return getClass().getSimpleName() + " [" + name + "]";
     }
+
+    /**
+     * Holds value of property fieldFilters.
+     */
+    private final Map<String,String> fieldFilters = new 
HashMap<String,String>();
+    
+    void addFieldFilter(final String field, final String filter){
+        fieldFilters.put(field, field);
+    }
+
+    /**
+     * Getter for property fieldFilters.
+     * @return Value of property fieldFilters.
+     */
+    public Map<String,String> getFieldFilters() {
+        return Collections.unmodifiableMap(fieldFilters);
+    }
 }

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchConfiguration.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchConfiguration.java
    2006-04-27 08:59:29 UTC (rev 2814)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchConfiguration.java
    2006-04-27 08:59:54 UTC (rev 2815)
@@ -97,4 +97,11 @@
 
     boolean isAlwaysRunEnabled();
     String getStatisticsName();
+
+    /**
+     * Getter for property fieldFilters.
+     * 
+     * @return Value of property fieldFilters.
+     */
+    Map<String, String> getFieldFilters();
 }

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactory.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactory.java
      2006-04-27 08:59:29 UTC (rev 2814)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchModeFactory.java
      2006-04-27 08:59:54 UTC (rev 2815)
@@ -298,18 +298,35 @@
                     final AbstractSearchConfiguration ascInherit = inherit 
instanceof AbstractSearchConfiguration 
                             ? (AbstractSearchConfiguration)inherit
                             : null;
+                    
                     asc.setName(id);
+                    
                     asc.setAlwaysRunEnabled( 
parseBoolean(commandE.getAttribute("always-run"), 
                             ascInherit != null ? 
ascInherit.isAlwaysRunEnabled() : false) );
+                    
+                    if( commandE.getAttribute("field-filters").length() >0 ){
+                        final String[] fieldFilters = 
commandE.getAttribute("field-filters").split(",");
+                        for( String fieldFilter : fieldFilters ){
+                            if( fieldFilter.contains(" AS ")){
+                                final String[] ff = fieldFilter.split(" AS ");
+                                asc.addFieldFilter(ff[0], ff[1]);
+                            }else{
+                                asc.addFieldFilter(fieldFilter, fieldFilter);
+                            }
+                        }
+                    }
                     asc.setPagingEnabled( 
parseBoolean(commandE.getAttribute("paging"),
                             ascInherit != null ? ascInherit.isPagingEnabled() 
: false) );
+                    
                     asc.setUseParameterAsQuery( 
commandE.getAttribute("query-parameter") );
+                    
                     if( commandE.getAttribute("result-fields").length() >0 ){
-                    final String[] resultFields = 
commandE.getAttribute("result-fields").split(",");
+                        final String[] resultFields = 
commandE.getAttribute("result-fields").split(",");
                         for( String resultField : resultFields ){
                             asc.addResultField(resultField);
                         }
                     }
+                    
                     
asc.setStatisticsName(parseString(commandE.getAttribute("statistical-name"),
                             ascInherit != null ? 
ascInherit.getStatisticsName() : ""));
                 }

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/view/config/SearchTab.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/view/config/SearchTab.java    
    2006-04-27 08:59:29 UTC (rev 2814)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/view/config/SearchTab.java    
    2006-04-27 08:59:54 UTC (rev 2815)
@@ -36,7 +36,7 @@
     // Constructors --------------------------------------------------
 
     /** Creates a new instance of SearchTab */
-    public SearchTab(
+    SearchTab(
                 final SearchTab inherit, 
                 final String id, 
                 final String mode, 
@@ -46,6 +46,7 @@
                 final Collection<NavigatorHint> navigations,
                 final int enrichmentLimit, 
                 final int enrichmentOnTop,
+                final int enrichmentOnTopScore,
                 final Collection<EnrichmentHint> enrichments,
                 final String adCommand,
                 final int adLimit,
@@ -64,6 +65,9 @@
         this.navigators.addAll(navigators);
         this.enrichmentLimit = enrichmentLimit >=0 || inherit == null ? 
enrichmentLimit : inherit.enrichmentLimit;
         this.enrichmentOnTop = enrichmentOnTop >=0 || inherit == null ? 
enrichmentOnTop : inherit.enrichmentOnTop;
+        this.enrichmentOnTopScore = enrichmentOnTopScore >=0 || inherit == 
null 
+                ? enrichmentOnTopScore 
+                : inherit.enrichmentOnTopScore;
         this.enrichments.addAll(enrichments);
         this.adCommand = adCommand != null && adCommand.trim().length() >0 
                 ? adCommand 
@@ -416,4 +420,17 @@
     public String toString(){
         return id + (inherit != null ? " --> " + inherit.toString() : "");
     }
+
+    /**
+     * Holds value of property enrichmentOnTopScore.
+     */
+    private int enrichmentOnTopScore;
+
+    /**
+     * Getter for property enrichmentScoreOnTop.
+     * @return Value of property enrichmentScoreOnTop.
+     */
+    public int getEnrichmentOnTopScore() {
+        return this.enrichmentOnTopScore;
+    }
 }

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/view/config/SearchTabFactory.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/view/config/SearchTabFactory.java
 2006-04-27 08:59:29 UTC (rev 2814)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/view/config/SearchTabFactory.java
 2006-04-27 08:59:54 UTC (rev 2815)
@@ -215,6 +215,9 @@
                     navigations,
                     parseInt(tabE.getAttribute("enrichment-limit"), inherit != 
null ? inherit.getEnrichmentLimit() : -1), 
                     parseInt(tabE.getAttribute("enrichment-on-top"), inherit 
!= null ? inherit.getEnrichmentOnTop() : -1),
+                    parseInt(tabE.getAttribute("enrichment-on-top-score"), 
inherit != null 
+                        ? inherit.getEnrichmentOnTopScore() 
+                        : -1),
                     enrichments,
                     adCommand,
                     parseInt(tabE.getAttribute("ad-limit"), inherit != null ? 
inherit.getAdLimit() : -1),

Modified: trunk/src/javacc/QueryParserImpl.jj
===================================================================
--- trunk/src/javacc/QueryParserImpl.jj 2006-04-27 08:59:29 UTC (rev 2814)
+++ trunk/src/javacc/QueryParserImpl.jj 2006-04-27 08:59:54 UTC (rev 2815)
@@ -105,7 +105,7 @@
     | <ANDNOT: ("ANDNOT")>
     | <INTEGER: ((<DIGIT>)+)>
     | <WORD: 
(<LETTER>|<DIGIT>|<WORD_SYMBOL_PREFIX>)(<LETTER>|<DIGIT>|<WORD_SYMBOL_MIDDLE>)*("*")?>
-    | <#WORD_SYMBOL_PREFIX: (".")>
+    | <#WORD_SYMBOL_PREFIX: (".")|("<")|("=")|(">")>
     | <#WORD_SYMBOL_MIDDLE: (".")|("-")|("_")>
     | <#WORD_SEPARATOR: [ // just a copy of the SKIP declaration.
             " ", "!", 

_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits

Reply via email to