Author: ssmiweve
Date: 2009-03-12 15:26:24 +0100 (Thu, 12 Mar 2009)
New Revision: 7222
Modified:
branches/2.18/query-api/src/main/javacc/QueryParserImpl.jj
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/AbstractQueryBuilder.java
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/BaseFilterBuilder.java
Log:
- XorClauses weren't applying the field to all children.
- add correct handling of NotClause and AndNotClause.
Modified: branches/2.18/query-api/src/main/javacc/QueryParserImpl.jj
===================================================================
--- branches/2.18/query-api/src/main/javacc/QueryParserImpl.jj 2009-03-12
12:05:11 UTC (rev 7221)
+++ branches/2.18/query-api/src/main/javacc/QueryParserImpl.jj 2009-03-12
14:26:24 UTC (rev 7222)
@@ -1,4 +1,4 @@
-/** Copyright (2005-2008) Schibsted Søk AS
+/** Copyright (2005-2009) Schibsted Søk AS
* This file is part of SESAT.
*
* SESAT is free software: you can redistribute it and/or modify
@@ -169,7 +169,7 @@
Clause clause;
LOG.info("parsing: "+context.getQueryString());
}{
- (clause = rootPrecedence())
+ (clause = rootPrecedence())
{
LOG.info("parsing of " + context.getQueryString() + " resulted in: " +
clause);
return clause;
@@ -339,7 +339,8 @@
final PhoneNumberClause phClause =
context.createPhoneNumberClause(term, f);
// Create a XorClause
- final QueryParserImpl p = new
QueryParserImpl(createContext(token.image), PHONE_NUMBER_DISABLED);
+ final String fieldNterm = null == field ? token.image : f +
':' + token.image;
+ final QueryParserImpl p = new
QueryParserImpl(createContext(fieldNterm), PHONE_NUMBER_DISABLED);
final Clause altClause = p.parse();
return context.createXorClause(phClause, altClause,
XorClause.Hint.PHONE_NUMBER_ON_LEFT);
@@ -355,7 +356,8 @@
final NumberGroupClause orgClause =
context.createNumberGroupClause(term, f);
// Create a XorClause
- final QueryParserImpl p = new
QueryParserImpl(createContext(token.image), NUMBER_GROUP_DISABLED);
+ final String fieldNterm = null == field ? token.image : f +
':' + token.image;
+ final QueryParserImpl p = new
QueryParserImpl(createContext(fieldNterm), NUMBER_GROUP_DISABLED);
final Clause altClause = p.parse();
return context.createXorClause(orgClause, altClause,
XorClause.Hint.NUMBER_GROUP_ON_LEFT);
@@ -411,10 +413,12 @@
final PhraseClause phClause =
context.createPhraseClause(token.image, f );
// Create unphrased query. also strip all operator and skip
characters out. SKER4723.
+ final String spaceNfield = null == f ? "" : ' ' + f;
final String term = token.image
.replaceAll("\"","")
.replaceAll(SKIP_REGEX, " ")
.replaceAll(OPERATOR_REGEX, " ")
+ .replaceAll(" +", spaceNfield)
.trim();
try { // if we can parse the content again, then make an
xorclause
Modified:
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/AbstractQueryBuilder.java
===================================================================
---
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/AbstractQueryBuilder.java
2009-03-12 12:05:11 UTC (rev 7221)
+++
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/AbstractQueryBuilder.java
2009-03-12 14:26:24 UTC (rev 7222)
@@ -1,4 +1,4 @@
-/* Copyright (2008) Schibsted Søk AS
+/* Copyright (2008-2009) Schibsted Søk AS
* This file is part of SESAT.
*
* SESAT is free software: you can redistribute it and/or modify
@@ -155,6 +155,8 @@
boolean result = false;
+ // FIXME handle XorClause to call isEmptyLeaf on only the child that
getContext().visitXorClause(..) does.
+ // if(clause instanceof XorClause){}else{
if(clause instanceof BinaryClause){
final BinaryClause c = (BinaryClause)clause;
result = isEmptyLeaf(c.getFirstClause()) &&
isEmptyLeaf(c.getSecondClause());
Modified:
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/BaseFilterBuilder.java
===================================================================
---
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/BaseFilterBuilder.java
2009-03-12 12:05:11 UTC (rev 7221)
+++
branches/2.18/search-command-control-spi/src/main/java/no/sesat/search/mode/command/querybuilder/BaseFilterBuilder.java
2009-03-12 14:26:24 UTC (rev 7222)
@@ -1,5 +1,5 @@
/*
- * Copyright (2008) Schibsted Søk AS
+ * Copyright (2008-2009) Schibsted Søk AS
* This file is part of SESAT.
*
* SESAT is free software: you can redistribute it and/or modify
@@ -43,8 +43,6 @@
*
* The " +" is defined as the deliminator, and is provided by getDelim() if a
subclass wishes to alter just this.
*
- * @todo add correct handling of NotClause and AndNotClause.
- * This also needs to be added to the query builder visitor above.
*
* @todo design for polymorphism and push out fast specifics to appropriate
subclass.
*
@@ -56,12 +54,15 @@
private static final Logger LOG =
Logger.getLogger(BaseFilterBuilder.class);
- private static final String DELIM = " +";
+ private static final String DELIM_INCLUSIVE = " +";
+ private static final String DELIM_EXCLUSIVE = " -";
// Attributes ----------------------------------------------------
private final StringBuilder additionalFilters = new StringBuilder();
+ private boolean insideNot = false;
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -91,6 +92,7 @@
public String getFilterString() {
+ insideNot = false;
return getQueryString()
+ (additionalFilters.length() > 0 ? ' ' : "")
+ additionalFilters.toString();
@@ -158,9 +160,19 @@
}
protected void visitImpl(final NotClause clause) {
+
+ final boolean wasInsideNot = insideNot;
+ insideNot = true;
+ clause.getFirstClause().accept(this);
+ insideNot = wasInsideNot;
}
protected void visitImpl(final AndNotClause clause) {
+
+ final boolean wasInsideNot = insideNot;
+ insideNot = true;
+ clause.getFirstClause().accept(this);
+ insideNot = wasInsideNot;
}
protected void appendFilter(final LeafClause clause) {
@@ -188,7 +200,7 @@
}
protected String getDelim(){
- return DELIM;
+ return insideNot ? DELIM_EXCLUSIVE : DELIM_INCLUSIVE;
}
// Private -------------------------------------------------------
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits