Author: mickw
Date: 2006-04-27 14:37:48 +0200 (Thu, 27 Apr 2006)
New Revision: 2816

Modified:
   trunk/src/
   
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/SearchMode.java
   
trunk/src/java/no/schibstedsok/front/searchportal/query/parser/AbstractQueryParser.java
   
trunk/src/java/no/schibstedsok/front/searchportal/query/run/RunningQueryImpl.java
   
trunk/src/java/no/schibstedsok/front/searchportal/velocity/VelocityEngineFactory.java
   trunk/src/javacc/QueryParserImpl.jj
   
trunk/src/test/java/no/schibstedsok/front/searchportal/command/WebSearchCommandTest.java
   trunk/src/webapp/WEB-INF/jsp/decorators/mainDecorator.jsp
Log:
Merging branches/2.0 back into trunk, after a little confusion with thomas and 
thamba ;-)
svn merge -r2783:HEAD 
https://dev.schibstedsok.no/svn/search-front-html/branches/2.0/



Property changes on: trunk/src
___________________________________________________________________
Name: svn:externals
   - conf               
https://dev.schibstedsok.no/svn/search-front-config/trunk/src/main/conf/
checkstyle      
https://dev.schibstedsok.no/svn/schibstedsok-commons/trunk/src/checkstyle/conf/

   + conf               
https://dev.schibstedsok.no/svn/search-front-config/branches/2.0/src/main/conf/
checkstyle      
https://dev.schibstedsok.no/svn/schibstedsok-commons/trunk/src/checkstyle/conf/


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:54 UTC (rev 2815)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/command/AbstractSimpleFastSearchCommand.java
      2006-04-27 12:37:48 UTC (rev 2816)
@@ -413,9 +413,9 @@
             final String transformedTerm = (String) getTransformedTerm(clause);
             if (transformedTerm != null && transformedTerm.length() > 0) {
                 if (insideNot) {
-                    appendToQueryRepresentation(" -");
+                    appendToQueryRepresentation("-");
                 }  else if (writeAnd != null && writeAnd.booleanValue()) {
-                    appendToQueryRepresentation(" +");
+                    appendToQueryRepresentation("+");
                 }
                 appendToQueryRepresentation(transformedTerm);
             }

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:54 UTC (rev 2815)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/command/NewsSearchCommand.java
    2006-04-27 12:37:48 UTC (rev 2816)
@@ -11,8 +11,10 @@
 import java.util.Map;
 import no.schibstedsok.front.searchportal.command.SearchCommand.Context;
 import no.schibstedsok.front.searchportal.query.AndClause;
+import no.schibstedsok.front.searchportal.query.AndNotClause;
 import no.schibstedsok.front.searchportal.query.DefaultOperatorClause;
 import no.schibstedsok.front.searchportal.query.LeafClause;
+import no.schibstedsok.front.searchportal.query.NotClause;
 import no.schibstedsok.front.searchportal.query.OrClause;
 import no.schibstedsok.front.searchportal.query.PhraseClause;
 import no.schibstedsok.front.searchportal.query.XorClause;
@@ -91,4 +93,62 @@
               || 
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 NotClause clause) {
+            clause.getFirstClause().accept(this);
+        }
+
+        protected void visitImpl(final AndNotClause clause) {
+            clause.getFirstClause().accept(this);
+        }
+
+        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:54 UTC (rev 2815)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/command/WebSearchCommand.java 
    2006-04-27 12:37:48 UTC (rev 2816)
@@ -10,8 +10,10 @@
 
 import java.util.Map;
 import no.schibstedsok.front.searchportal.query.AndClause;
+import no.schibstedsok.front.searchportal.query.AndNotClause;
 import no.schibstedsok.front.searchportal.query.DefaultOperatorClause;
 import no.schibstedsok.front.searchportal.query.LeafClause;
+import no.schibstedsok.front.searchportal.query.NotClause;
 import no.schibstedsok.front.searchportal.query.OrClause;
 import no.schibstedsok.front.searchportal.query.PhraseClause;
 import no.schibstedsok.front.searchportal.query.XorClause;
@@ -49,5 +51,101 @@
         }
     }
 
-    
+
+    /**
+     * 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 NotClause clause) {
+            clause.getFirstClause().accept(this);
+        }
+
+        protected void visitImpl(final AndNotClause clause) {
+            clause.getFirstClause().accept(this);
+        }
+
+        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/SearchMode.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchMode.java 
    2006-04-27 08:59:54 UTC (rev 2815)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/configuration/SearchMode.java 
    2006-04-27 12:37:48 UTC (rev 2816)
@@ -53,6 +53,16 @@
     public Collection<SearchConfiguration> getSearchConfigurations() {
         return searchConfigurations;
     }
+    
+    public SearchConfiguration getSearchConfiguration(final String name) {
+       
+        for( SearchConfiguration sc : searchConfigurations){
+            if( sc.getName().equals(name) ){
+                return sc;
+            }
+        }
+        return null;
+    }
 
     public void setSearchConfigurations(Collection<SearchConfiguration> 
searchConfigurations) {
         this.searchConfigurations = searchConfigurations;

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/query/parser/AbstractQueryParser.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/query/parser/AbstractQueryParser.java
     2006-04-27 08:59:54 UTC (rev 2815)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/query/parser/AbstractQueryParser.java
     2006-04-27 12:37:48 UTC (rev 2816)
@@ -46,7 +46,7 @@
      ***/
     protected static final String ERR_EMPTY_CONTEXT
         = "The \"QueryParser(QueryParser.Context)\" constructor must be used!";
-    private static final String ERR_PARSING = "Unable to create RunningQuery's 
query due to ParseException";
+    private static final String ERR_PARSING = "Unable to create RunningQuery's 
query due to ParseException of ";
 
     /** the context this query parser implementation must work against.
      ***/
@@ -87,9 +87,9 @@
                 };
                 
             }catch(ParseException pe){
-                LOG.warn(ERR_PARSING, pe);
+                LOG.warn(ERR_PARSING + queryStr, pe);
             } catch (TokenMgrError tme)  {
-                LOG.error(ERR_PARSING, tme);
+                LOG.error(ERR_PARSING + queryStr, tme);
             }
             
             if( query == null ){

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/query/run/RunningQueryImpl.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/query/run/RunningQueryImpl.java
   2006-04-27 08:59:54 UTC (rev 2815)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/query/run/RunningQueryImpl.java
   2006-04-27 12:37:48 UTC (rev 2816)
@@ -435,6 +435,8 @@
             return "c=p";
         } else if (source.startsWith("Person")) {
             return "c=w";
+        } else if (source.startsWith("Norske blogger")) {
+            return "c=b";
         } else if (source.startsWith("Bedrift")) {
             return "c=y";
         } else if (source.equals("Internasjonale nettsider")) {

Modified: 
trunk/src/java/no/schibstedsok/front/searchportal/velocity/VelocityEngineFactory.java
===================================================================
--- 
trunk/src/java/no/schibstedsok/front/searchportal/velocity/VelocityEngineFactory.java
       2006-04-27 08:59:54 UTC (rev 2815)
+++ 
trunk/src/java/no/schibstedsok/front/searchportal/velocity/VelocityEngineFactory.java
       2006-04-27 12:37:48 UTC (rev 2816)
@@ -82,7 +82,7 @@
             engine.setProperty(Velocity.RESOURCE_LOADER, "url");
             engine.setProperty("url.resource.loader.class", 
"no.schibstedsok.front.searchportal.velocity.URLVelocityTemplateLoader");
             engine.setProperty("url.resource.loader.cache", "true");
-            
engine.setProperty("url.resource.loader.modificationCheckInterval", "60"); // 1 
minute update cycle.
+            
engine.setProperty("url.resource.loader.modificationCheckInterval", "300"); // 
5 minute update cycle.
             engine.setProperty("velocimacro.library", site.getTemplateDir() + 
"/VM_global_library.vm");
             engine.setProperty(Site.NAME_KEY, site);
             engine.setProperty("site.fallback", Site.DEFAULT);

Modified: trunk/src/javacc/QueryParserImpl.jj
===================================================================
--- trunk/src/javacc/QueryParserImpl.jj 2006-04-27 08:59:54 UTC (rev 2815)
+++ trunk/src/javacc/QueryParserImpl.jj 2006-04-27 12:37:48 UTC (rev 2816)
@@ -74,7 +74,8 @@
 <*>SKIP : {
       " " | "!" 
     | < [ "\u0023"-"\u0027" ] >
-    | < [ "\u002a"-"\u002f" ] >
+    | < [ "\u002a"-"\u002c" ] >
+    | < [ "\u002e"-"\u002f" ] >
     | < [ "\u003b"-"\u0040" ] >
     | < [ "\u005b"-"\u0060" ] >
     | < [ "\u007b"-"\u00bf" ] >

Modified: 
trunk/src/test/java/no/schibstedsok/front/searchportal/command/WebSearchCommandTest.java
===================================================================
--- 
trunk/src/test/java/no/schibstedsok/front/searchportal/command/WebSearchCommandTest.java
    2006-04-27 08:59:54 UTC (rev 2815)
+++ 
trunk/src/test/java/no/schibstedsok/front/searchportal/command/WebSearchCommandTest.java
    2006-04-27 12:37:48 UTC (rev 2816)
@@ -16,6 +16,7 @@
 import no.schibstedsok.front.searchportal.configuration.FastConfiguration;
 import no.schibstedsok.front.searchportal.configuration.SearchConfiguration;
 import no.schibstedsok.front.searchportal.configuration.SearchMode;
+import no.schibstedsok.front.searchportal.configuration.SearchModeFactory;
 import no.schibstedsok.front.searchportal.configuration.loader.DocumentLoader;
 import 
no.schibstedsok.front.searchportal.configuration.loader.FileResourceLoader;
 import 
no.schibstedsok.front.searchportal.configuration.loader.PropertiesLoader;
@@ -75,12 +76,28 @@
                 "bil",
                 "");
     }
+
+    public void testExclusion() {
+        executeTestOfQuery("magnus -eklund",
+                "magnus -eklund",
+                "");
+        executeTestOfQuery("-whatever",
+                "-whatever",
+                "");
+    }
+
     
+    public void testTwoTerms() {
+        executeTestOfQuery("magnus eklund",
+                "magnus eklund",
+                "");
+    }
+    
     /**
      *
      *
      */
-    public void testExclusion() {
+    public void testSiteExclusion() {
 //        executeTestOfQuery(
 //                "-site:zmag.org bil",
 //                "bil",
@@ -107,6 +124,7 @@
     }
     
     private void executeTestOfQuery(final String query, final String 
wantedQuery, final String wantedFilter) {
+        
         final SearchCommand.Context cxt = createCommandContext(query);
         
         final WebSearchCommand cmd = new WebSearchCommand(cxt, 
Collections.EMPTY_MAP);
@@ -118,12 +136,16 @@
     }
     
     private SearchCommand.Context createCommandContext(final String query) {
+        
         final FastConfiguration config = new FastConfiguration();
+        
         final RunningQuery.Context rqCxt = new RunningQuery.Context() {
             private final SearchMode mode = new SearchMode();
             
             public SearchMode getSearchMode() {
-                return mode;
+                return SearchModeFactory.getModeFactory(
+                        ContextWrapper.wrap(SearchModeFactory.Context.class, 
this))
+                        .getMode("magic");
             }
             public SearchTab getSearchTab(){
                 return SearchTabFactory.getTabFactory(
@@ -148,7 +170,7 @@
         
         final SearchCommand.Context searchCmdCxt = new SearchCommand.Context() 
{
             public SearchConfiguration getSearchConfiguration() {
-                return config;
+                return 
rqCxt.getSearchMode().getSearchConfiguration("defaultSearch");
             }
             
             public RunningQuery getRunningQuery() {

Modified: trunk/src/webapp/WEB-INF/jsp/decorators/mainDecorator.jsp
===================================================================
--- trunk/src/webapp/WEB-INF/jsp/decorators/mainDecorator.jsp   2006-04-27 
08:59:54 UTC (rev 2815)
+++ trunk/src/webapp/WEB-INF/jsp/decorators/mainDecorator.jsp   2006-04-27 
12:37:48 UTC (rev 2816)
@@ -79,7 +79,6 @@
 
 
 <body onload="<%if (currentC.equals("y") || currentC.equals("yipticker") || 
currentC.equals("w") ) {%>init();<%} else if (currentC.equals("yip") || 
currentC.equals("wip")) {%>init(); checkTab();<% } %>">
-     
 
     <% // sitesearch
     final VelocityEngine engine = VelocityResultHandler.getEngine(site);
@@ -420,7 +419,7 @@
                            <% int i = 0; %>
                     <% for (Iterator iterator = sources.iterator(); 
iterator.hasNext();) {
                         Modifier e = (Modifier) iterator.next();
-                        if ( (currentC.equals("d") && 
!e.getName().equals("Nettsøk")) || (currentC.equals("d") && searchType != null 
&& searchType.equals("g")) || currentC.equals("p")) {
+                        if ( (currentC.equals("d") && 
!e.getName().equals("Nettsøk")) || (currentC.equals("d") && searchType != null 
&& searchType.equals("g")) || currentC.equals("p") || currentC.equals("b")) {
                             ++i;
                     %>
 
@@ -596,7 +595,10 @@
                 <decorator:getProperty property="page.tv-results"/>
                 <%}%>
 
-            </td>
+                <%if (currentC.equals("b")) {%>
+                <decorator:getProperty property="page.blog-search"/>
+                <%}%> 
+               </td>
 
            <%if (q.trim().equals("")) {%>
 
@@ -642,6 +644,7 @@
 <% } else if (currentC.equals("w")) { %> tmsec[1]="tmsec=personsok";
 <% } else if (currentC.equals("wip")) { %> tmsec[1]="tmsec=personsok_info";
 <% } else if (currentC.equals("p")) { %> tmsec[1]="tmsec=bildesok";
+<% } else if (currentC.equals("b")) { %> tmsec[1]="tmsec=bloggsok";
 <% } %>
 getTMqs('','', 'sesam_no', 'no', 'iso-8859-15', tmsec);
 //-->
@@ -658,6 +661,7 @@
 <% } else if (currentC.equals("w")) { %> <noscript><img 
src="http://statistik-gallup.net/v11***sesam_no/no/iso-8859-15/tmsec=sesam&amp;tmsec=personsok";
 alt="" /></noscript>
 <% } else if (currentC.equals("wip")) { %> <noscript><img 
src="http://statistik-gallup.net/v11***sesam_no/no/iso-8859-15/tmsec=sesam&amp;tmsec=personsok_info";
 alt="" /></noscript>
 <% } else if (currentC.equals("p")) { %> <noscript><img 
src="http://statistik-gallup.net/v11***sesam_no/no/iso-8859-15/tmsec=sesam&amp;tmsec=bildesok";
 alt="" /></noscript>
+<% } else if (currentC.equals("b")) { %> <noscript><img 
src="http://statistik-gallup.net/v11***sesam_no/no/iso-8859-15/tmsec=sesam&amp;tmsec=bloggesok";
 alt="" /></noscript>
 <% } %>
 
 <!-- end gallup -->

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

Reply via email to