Added generic support for lucene scalar functions and used the to implement CMIS Upper/Lower string functions (MOB-221)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14578 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrew Hind
2009-06-08 10:42:01 +00:00
parent 2c122bca4e
commit 1a261b54fd
33 changed files with 1385 additions and 242 deletions

View File

@@ -0,0 +1,51 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.search.impl.lucene;
/**
* Functions that can be applied to lucene fields
*
* Currently upper and lower that perform a case insensitive match for untokenised fields.
* (If the field is tokenised the match should already be case insensitive.)
*
* @author andyh
*
*/
public enum LuceneFunction
{
/**
* Match as if the field was converted to upper case.
*/
UPPER,
/**
* Match as if the field was converted to lower case.
*/
LOWER,
/**
* A normal lucene field match.
*/
FIELD;
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.search.impl.lucene.query;
import java.io.IOException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.FilteredTermEnum;
import org.apache.lucene.search.MultiTermQuery;
/**
* Perform a case insensitive match against a field
*
* @author andyh
*
*/
public class CaseInsensitiveFieldQuery extends MultiTermQuery
{
/**
*
*/
private static final long serialVersionUID = -2570803495329346982L;
/**
* @param term - the term for the match
*/
public CaseInsensitiveFieldQuery(Term term)
{
super(term);
}
@Override
protected FilteredTermEnum getEnum(IndexReader reader) throws IOException
{
Term term = new Term(getTerm().field(), getTerm().text());
return new CaseInsensitiveTermEnum(reader, term);
}
}

View File

@@ -0,0 +1,84 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.search.impl.lucene.query;
import java.io.IOException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.FilteredTermEnum;
import org.apache.lucene.search.MultiTermQuery;
/**
* Find terms that match a range ignoring case
*
* @author andyh
*/
public class CaseInsensitiveFieldRangeQuery extends MultiTermQuery
{
/**
*
*/
private static final long serialVersionUID = -5859977841901861122L;
String expandedFieldName;
String lowerTermText;
String upperTermText;
boolean includeLower;
boolean includeUpper;
/**
* @param expandedFieldName -
* field
* @param lowerTermText -
* upper range value
* @param upperTermText -
* lower range value
* @param includeLower -
* include the lower value
* @param includeUpper -
* include the upper value
*/
public CaseInsensitiveFieldRangeQuery(String expandedFieldName, String lowerTermText, String upperTermText, boolean includeLower, boolean includeUpper)
{
super(new Term(expandedFieldName, ""));
this.expandedFieldName = expandedFieldName;
this.lowerTermText = lowerTermText;
this.upperTermText = upperTermText;
this.includeLower = includeLower;
this.includeUpper = includeUpper;
}
@Override
protected FilteredTermEnum getEnum(IndexReader reader) throws IOException
{
return new CaseInsensitiveTermRangeEnum(reader, expandedFieldName, lowerTermText, upperTermText, includeLower, includeUpper);
}
}

View File

@@ -0,0 +1,86 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.search.impl.lucene.query;
import java.io.IOException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.FilteredTermEnum;
/**
* A term enum to find case insensitive matches - used for Upper and Lower
*
* @author andyh
*/
public class CaseInsensitiveTermEnum extends FilteredTermEnum
{
private String field = "";
private boolean endEnum = false;
private String text;
/**
* @param reader =
* the index reader
* @param term -
* the term to match
* @throws IOException
*/
public CaseInsensitiveTermEnum(IndexReader reader, Term term) throws IOException
{
super();
field = term.field();
text = term.text();
// position at the start - we could do slightly better
setEnum(reader.terms(new Term(term.field(), "")));
}
@Override
public float difference()
{
return 1.0f;
}
@Override
protected boolean endEnum()
{
return endEnum;
}
@Override
protected boolean termCompare(Term term)
{
if (field.equals(term.field()))
{
String searchText = term.text();
return searchText.equalsIgnoreCase(text);
}
endEnum = true;
return false;
}
}

View File

@@ -0,0 +1,129 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.search.impl.lucene.query;
import java.io.IOException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.FilteredTermEnum;
/**
* A term enum that finds terms that lie with in some range ignoring case
*
* @author andyh
*/
public class CaseInsensitiveTermRangeEnum extends FilteredTermEnum
{
private boolean endEnum = false;
String expandedFieldName;
String lowerTermText;
String upperTermText;
boolean includeLower;
boolean includeUpper;
/**
* @param reader
* the index reader
* @param expandedFieldName -
* field
* @param lowerTermText -
* upper range value
* @param upperTermText -
* lower range value
* @param includeLower -
* include the lower value
* @param includeUpper -
* include the upper value
* @throws IOException
*/
public CaseInsensitiveTermRangeEnum(IndexReader reader, String expandedFieldName, String lowerTermText, String upperTermText, boolean includeLower, boolean includeUpper)
throws IOException
{
super();
this.expandedFieldName = expandedFieldName;
this.lowerTermText = lowerTermText.toLowerCase();
this.upperTermText = upperTermText.toLowerCase();
this.includeLower = includeLower;
this.includeUpper = includeUpper;
setEnum(reader.terms(new Term(expandedFieldName, "")));
}
@Override
public float difference()
{
return 1.0f;
}
@Override
protected boolean endEnum()
{
return endEnum;
}
@Override
protected boolean termCompare(Term term)
{
if (expandedFieldName.equals(term.field()))
{
String searchText = term.text().toLowerCase();
return checkLower(searchText) && checkUpper(searchText);
}
endEnum = true;
return false;
}
private boolean checkLower(String searchText)
{
if (includeLower)
{
return (lowerTermText.compareTo(searchText) <= 0);
}
else
{
return (lowerTermText.compareTo(searchText) < 0);
}
}
private boolean checkUpper(String searchText)
{
if (includeUpper)
{
return (upperTermText.compareTo(searchText) >= 0);
}
else
{
return (upperTermText.compareTo(searchText) > 0);
}
}
}

View File

@@ -29,7 +29,9 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import org.alfresco.repo.search.impl.lucene.LuceneFunction;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.search.impl.querymodel.FunctionArgument;
import org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext;
import org.alfresco.repo.search.impl.querymodel.PredicateMode;
import org.alfresco.service.cmr.dictionary.DictionaryService;
@@ -40,14 +42,19 @@ import org.alfresco.service.namespace.QName;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.search.Query;
/**
* Alfrecso function evaluation context for evaluating FTS expressions against lucene.
* @author andyh
*
*/
public class AlfrescoFunctionEvaluationContext implements FunctionEvaluationContext
{
private static HashSet<String> EXPOSED_FIELDS = new HashSet<String>();
private NamespacePrefixResolver namespacePrefixResolver;
private DictionaryService dictionaryService;
private String defaultNamespace;
static
@@ -71,7 +78,12 @@ public class AlfrescoFunctionEvaluationContext implements FunctionEvaluationCont
EXPOSED_FIELDS.add("ISNULL");
EXPOSED_FIELDS.add("ISNOTNULL");
}
/**
* @param namespacePrefixResolver
* @param dictionaryService
* @param defaultNamespace
*/
public AlfrescoFunctionEvaluationContext(NamespacePrefixResolver namespacePrefixResolver, DictionaryService dictionaryService, String defaultNamespace)
{
this.namespacePrefixResolver = namespacePrefixResolver;
@@ -79,7 +91,7 @@ public class AlfrescoFunctionEvaluationContext implements FunctionEvaluationCont
this.defaultNamespace = defaultNamespace;
}
public Query buildLuceneEquality(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException
public Query buildLuceneEquality(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
throw new UnsupportedOperationException();
}
@@ -89,12 +101,12 @@ public class AlfrescoFunctionEvaluationContext implements FunctionEvaluationCont
throw new UnsupportedOperationException();
}
public Query buildLuceneGreaterThan(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException
public Query buildLuceneGreaterThan(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
throw new UnsupportedOperationException();
}
public Query buildLuceneGreaterThanOrEquals(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException
public Query buildLuceneGreaterThanOrEquals(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
throw new UnsupportedOperationException();
}
@@ -104,17 +116,17 @@ public class AlfrescoFunctionEvaluationContext implements FunctionEvaluationCont
throw new UnsupportedOperationException();
}
public Query buildLuceneInequality(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException
public Query buildLuceneInequality(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
throw new UnsupportedOperationException();
}
public Query buildLuceneLessThan(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException
public Query buildLuceneLessThan(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
throw new UnsupportedOperationException();
}
public Query buildLuceneLessThanOrEquals(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException
public Query buildLuceneLessThanOrEquals(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException
{
throw new UnsupportedOperationException();
}
@@ -177,7 +189,7 @@ public class AlfrescoFunctionEvaluationContext implements FunctionEvaluationCont
return propertyName;
}
if(propertyName.startsWith("{"))
if (propertyName.startsWith("{"))
{
QName qname = QName.createQName(propertyName);
if (dictionaryService.getProperty(qname) != null)
@@ -186,10 +198,10 @@ public class AlfrescoFunctionEvaluationContext implements FunctionEvaluationCont
}
else
{
throw new FTSQueryException("Unknown property: "+propertyName);
throw new FTSQueryException("Unknown property: " + propertyName);
}
}
int index = propertyName.indexOf(':');
if (index != -1)
{
@@ -201,30 +213,30 @@ public class AlfrescoFunctionEvaluationContext implements FunctionEvaluationCont
}
else
{
throw new FTSQueryException("Unknown property: "+propertyName);
throw new FTSQueryException("Unknown property: " + propertyName);
}
}
index = propertyName.indexOf('_');
if (index != -1)
{
// Try as a property, if invalid pass through
QName qname = QName.createQName(propertyName.substring(0, index), propertyName.substring(index+1), namespacePrefixResolver);
QName qname = QName.createQName(propertyName.substring(0, index), propertyName.substring(index + 1), namespacePrefixResolver);
if (dictionaryService.getProperty(qname) != null)
{
return "@" + qname.toString();
}
else
{
throw new FTSQueryException("Unknown property: "+propertyName);
throw new FTSQueryException("Unknown property: " + propertyName);
}
}
if(EXPOSED_FIELDS.contains(propertyName))
if (EXPOSED_FIELDS.contains(propertyName))
{
return propertyName;
}
QName qname = QName.createQName(defaultNamespace, propertyName);
if (dictionaryService.getProperty(qname) != null)
{
@@ -232,9 +244,14 @@ public class AlfrescoFunctionEvaluationContext implements FunctionEvaluationCont
}
else
{
throw new FTSQueryException("Unknown property: "+propertyName);
throw new FTSQueryException("Unknown property: " + propertyName);
}
}
public LuceneFunction getLuceneFunction(FunctionArgument functionArgument)
{
throw new UnsupportedOperationException();
}
}

View File

@@ -28,53 +28,184 @@ import java.io.Serializable;
import java.util.Collection;
import java.util.Map;
import org.alfresco.repo.search.impl.lucene.LuceneFunction;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.search.Query;
/**
* The function evaluation context for lucene query implementations.
*
* This context is used at query time and also when navigating the results to get column values.
*
* @author andyh
*/
public interface FunctionEvaluationContext
{
/**
* @return the matching nodes by selector (at navigation time)
*/
public Map<String, NodeRef> getNodeRefs();
/**
* @return the scores by selector (at navigation time)
*/
public Map<String, Float> getScores();
/**
* Get a property
* @param nodeRef
* @param propertyName
* @return the property (at navigation time)
*/
public Serializable getProperty(NodeRef nodeRef, String propertyName);
/**
* @return the node service
*/
public NodeService getNodeService();
/**
* @return the score (at navigation time)
*/
public Float getScore();
public Query buildLuceneEquality(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException;
/**
* @param lqp
* @param propertyName
* @param value
* @param mode
* @param luceneFunction
* @return the query
* @throws ParseException
*/
public Query buildLuceneEquality(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException;
/**
* Note: null and not null are not required to support functions from the spec
* @param lqp
* @param propertyName
* @param not
* @return the query
* @throws ParseException
*/
public Query buildLuceneExists(LuceneQueryParser lqp, String propertyName, Boolean not) throws ParseException;
public Query buildLuceneGreaterThan(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException;
/**
* @param lqp
* @param propertyName
* @param value
* @param mode
* @param luceneFunction
* @return the query
* @throws ParseException
*/
public Query buildLuceneGreaterThan(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException;
public Query buildLuceneGreaterThanOrEquals(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException;
/**
* @param lqp
* @param propertyName
* @param value
* @param mode
* @param luceneFunction
* @return the query
* @throws ParseException
*/
public Query buildLuceneGreaterThanOrEquals(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException;
public Query buildLuceneLessThan(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException;
/**
* @param lqp
* @param propertyName
* @param value
* @param mode
* @param luceneFunction
* @return the query
* @throws ParseException
*/
public Query buildLuceneLessThan(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException;
public Query buildLuceneLessThanOrEquals(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException;
/**
* @param lqp
* @param propertyName
* @param value
* @param mode
* @param luceneFunction
* @return the query
* @throws ParseException
*/
public Query buildLuceneLessThanOrEquals(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException;
/**
* Note: Like is not required to support functions from the spec
* @param lqp
* @param propertyName
* @param value
* @param not
* @return the query
* @throws ParseException
*/
public Query buildLuceneLike(LuceneQueryParser lqp, String propertyName, Serializable value, Boolean not) throws ParseException;
public Query buildLuceneInequality(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode) throws ParseException;
/**
* @param lqp
* @param propertyName
* @param value
* @param mode
* @param luceneFunction
* @return the query
* @throws ParseException
*/
public Query buildLuceneInequality(LuceneQueryParser lqp, String propertyName, Serializable value, PredicateMode mode, LuceneFunction luceneFunction) throws ParseException;
/**
* Note: In is not required to support functions from the spec
* @param lqp
* @param propertyName
* @param values
* @param not
* @param mode
* @return the query
* @throws ParseException
*/
public Query buildLuceneIn(LuceneQueryParser lqp, String propertyName, Collection<Serializable> values, Boolean not, PredicateMode mode) throws ParseException;
/**
* @param propertyName
* @return the field used for sorting the given property
*/
public String getLuceneSortField(String propertyName);
/**
* @param propertyName
* @return - is this an object id
*/
public boolean isObjectId(String propertyName);
/**
* @param propertyName
* @return is this property queryable
*/
public boolean isQueryable(String propertyName);
/**
* @param propertyName
* @return Is this property orderable
*/
public boolean isOrderable(String propertyName);
/**
* @param propertyName
* @return the lucene field name for the property
*/
public String getLuceneFieldName(String propertyName);
/**
* @param functionArgument
* @return the lucene function appropriate to a function argument
*/
public LuceneFunction getLuceneFunction(FunctionArgument functionArgument);
}

View File

@@ -29,10 +29,13 @@ import java.util.Map;
import org.alfresco.repo.search.impl.querymodel.Argument;
import org.alfresco.repo.search.impl.querymodel.ArgumentDefinition;
import org.alfresco.repo.search.impl.querymodel.FunctionArgument;
import org.alfresco.repo.search.impl.querymodel.Multiplicity;
import org.alfresco.repo.search.impl.querymodel.PropertyArgument;
import org.alfresco.repo.search.impl.querymodel.QueryModelException;
import org.alfresco.repo.search.impl.querymodel.StaticArgument;
import org.alfresco.repo.search.impl.querymodel.impl.functions.Lower;
import org.alfresco.repo.search.impl.querymodel.impl.functions.Upper;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.namespace.QName;
@@ -41,21 +44,32 @@ import org.alfresco.service.namespace.QName;
*/
public abstract class BaseComparison extends BaseFunction
{
/**
* Left hand side
*/
public final static String ARG_LHS = "LHS";
/**
* Right hand side
*/
public final static String ARG_RHS = "RHS";
public static LinkedHashMap<String, ArgumentDefinition> args;
/**
* Args
*/
public static LinkedHashMap<String, ArgumentDefinition> ARGS;
private PropertyArgument propertyArgument;
private StaticArgument staticArgument;
private FunctionArgument functionArgument;
static
{
args = new LinkedHashMap<String, ArgumentDefinition>();
args.put(ARG_LHS, new BaseArgumentDefinition(Multiplicity.ANY, ARG_LHS, DataTypeDefinition.ANY, true));
args.put(ARG_RHS, new BaseArgumentDefinition(Multiplicity.ANY, ARG_RHS, DataTypeDefinition.ANY, true));
ARGS = new LinkedHashMap<String, ArgumentDefinition>();
ARGS.put(ARG_LHS, new BaseArgumentDefinition(Multiplicity.ANY, ARG_LHS, DataTypeDefinition.ANY, true));
ARGS.put(ARG_RHS, new BaseArgumentDefinition(Multiplicity.ANY, ARG_RHS, DataTypeDefinition.ANY, true));
}
/**
@@ -68,14 +82,14 @@ public abstract class BaseComparison extends BaseFunction
super(name, returnType, argumentDefinitions);
}
public void setPropertyAndStaticArguments(Map<String, Argument> functionArgs)
protected void setPropertyAndStaticArguments(Map<String, Argument> functionArgs)
{
Argument lhs = functionArgs.get(ARG_LHS);
Argument rhs = functionArgs.get(ARG_RHS);
if (lhs instanceof PropertyArgument)
{
if (rhs instanceof PropertyArgument)
if ((rhs instanceof PropertyArgument) || (rhs instanceof FunctionArgument))
{
throw new QueryModelException("Implicit join is not supported");
}
@@ -89,9 +103,29 @@ public abstract class BaseComparison extends BaseFunction
throw new QueryModelException("Argument of type " + rhs.getClass().getName() + " is not supported");
}
}
else if (lhs instanceof FunctionArgument)
{
if ((rhs instanceof PropertyArgument) || (rhs instanceof FunctionArgument))
{
throw new QueryModelException("Implicit join is not supported");
}
else if (rhs instanceof StaticArgument)
{
functionArgument = (FunctionArgument) lhs;
staticArgument = (StaticArgument) rhs;
}
else
{
throw new QueryModelException("Argument of type " + rhs.getClass().getName() + " is not supported");
}
}
else if (rhs instanceof PropertyArgument)
{
if (lhs instanceof StaticArgument)
if ((lhs instanceof PropertyArgument) || (lhs instanceof FunctionArgument))
{
throw new QueryModelException("Implicit join is not supported");
}
else if (lhs instanceof StaticArgument)
{
propertyArgument = (PropertyArgument) rhs;
staticArgument = (StaticArgument) lhs;
@@ -101,6 +135,22 @@ public abstract class BaseComparison extends BaseFunction
throw new QueryModelException("Argument of type " + lhs.getClass().getName() + " is not supported");
}
}
else if (rhs instanceof FunctionArgument)
{
if ((lhs instanceof PropertyArgument) || (lhs instanceof FunctionArgument))
{
throw new QueryModelException("Implicit join is not supported");
}
else if (lhs instanceof StaticArgument)
{
functionArgument = (FunctionArgument) rhs;
staticArgument = (StaticArgument) lhs;
}
else
{
throw new QueryModelException("Argument of type " + lhs.getClass().getName() + " is not supported");
}
}
else
{
throw new QueryModelException("Equals must have one property argument");
@@ -108,7 +158,7 @@ public abstract class BaseComparison extends BaseFunction
}
/**
* @return the propertyArgument
* @return the propertyArgument - there must be a property argument of a function argument
*/
protected PropertyArgument getPropertyArgument()
{
@@ -116,13 +166,63 @@ public abstract class BaseComparison extends BaseFunction
}
/**
* @return the staticArgument
* @return the staticArgument - must be set
*/
protected StaticArgument getStaticArgument()
{
return staticArgument;
}
/**
* @return the functionArgument
*/
protected FunctionArgument getFunctionArgument()
{
return functionArgument;
}
protected String getPropertyName()
{
if (propertyArgument != null)
{
return propertyArgument.getPropertyName();
}
else if (functionArgument != null)
{
String functionName = functionArgument.getFunction().getName();
if (functionName.equals(Upper.NAME))
{
Argument arg = functionArgument.getFunctionArguments().get(Upper.ARG_ARG);
if (arg instanceof PropertyArgument)
{
return ((PropertyArgument) arg).getPropertyName();
}
else
{
throw new QueryModelException("Upper must have a column argument " + arg);
}
}
else if (functionName.equals(Lower.NAME))
{
Argument arg = functionArgument.getFunctionArguments().get(Lower.ARG_ARG);
if (arg instanceof PropertyArgument)
{
return ((PropertyArgument) arg).getPropertyName();
}
else
{
throw new QueryModelException("Lower must have a column argument " + arg);
}
}
else
{
throw new QueryModelException("Unsupported function: " + functionName);
}
}
else
{
throw new QueryModelException("A property of function argument must be provided");
}
}
}

View File

@@ -47,7 +47,7 @@ public class Equals extends BaseComparison
*/
public Equals()
{
super(NAME, DataTypeDefinition.BOOLEAN, args);
super(NAME, DataTypeDefinition.BOOLEAN, ARGS);
}
/* (non-Javadoc)

View File

@@ -47,7 +47,7 @@ public class GreaterThan extends BaseComparison
*/
public GreaterThan()
{
super(NAME, DataTypeDefinition.BOOLEAN, args);
super(NAME, DataTypeDefinition.BOOLEAN, ARGS);
}
/* (non-Javadoc)

View File

@@ -47,7 +47,7 @@ public class GreaterThanOrEquals extends BaseComparison
*/
public GreaterThanOrEquals()
{
super(NAME, DataTypeDefinition.BOOLEAN, args);
super(NAME, DataTypeDefinition.BOOLEAN, ARGS);
}
/* (non-Javadoc)

View File

@@ -46,7 +46,7 @@ public class LessThan extends BaseComparison
*/
public LessThan()
{
super(NAME, DataTypeDefinition.BOOLEAN, args);
super(NAME, DataTypeDefinition.BOOLEAN, ARGS);
}
/*

View File

@@ -46,7 +46,7 @@ public class LessThanOrEquals extends BaseComparison
*/
public LessThanOrEquals()
{
super(NAME, DataTypeDefinition.BOOLEAN, args);
super(NAME, DataTypeDefinition.BOOLEAN, ARGS);
}
/*

View File

@@ -46,7 +46,7 @@ public class NotEquals extends BaseComparison
*/
public NotEquals()
{
super(NAME, DataTypeDefinition.BOOLEAN, args);
super(NAME, DataTypeDefinition.BOOLEAN, ARGS);
}
/*

View File

@@ -65,7 +65,7 @@ public class LuceneEquals extends Equals implements LuceneQueryBuilderComponent
LuceneQueryParser lqp = luceneContext.getLuceneQueryParser();
setPropertyAndStaticArguments(functionArgs);
Query query = functionContext.buildLuceneEquality(lqp, getPropertyArgument().getPropertyName(), getStaticArgument().getValue(functionContext), PredicateMode.ANY);
Query query = functionContext.buildLuceneEquality(lqp, getPropertyName(), getStaticArgument().getValue(functionContext), PredicateMode.ANY, functionContext.getLuceneFunction(getFunctionArgument()));
if(query == null)
{

View File

@@ -28,6 +28,7 @@ import java.util.Map;
import java.util.Set;
import org.alfresco.repo.search.impl.lucene.AnalysisMode;
import org.alfresco.repo.search.impl.lucene.LuceneFunction;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.search.impl.querymodel.Argument;
import org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext;
@@ -78,11 +79,11 @@ public class LuceneFTSPhrase extends FTSPhrase implements LuceneQueryBuilderComp
if (propArg != null)
{
String prop = propArg.getPropertyName();
query = lqp.getFieldQuery(functionContext.getLuceneFieldName(prop), term, AnalysisMode.TOKENISE, slop);
query = lqp.getFieldQuery(functionContext.getLuceneFieldName(prop), term, AnalysisMode.TOKENISE, slop, LuceneFunction.FIELD);
}
else
{
query = lqp.getFieldQuery("TEXT", term, AnalysisMode.TOKENISE, slop);
query = lqp.getFieldQuery("TEXT", term, AnalysisMode.TOKENISE, slop, LuceneFunction.FIELD);
}
return query;

View File

@@ -28,6 +28,7 @@ import java.util.Map;
import java.util.Set;
import org.alfresco.repo.search.impl.lucene.AnalysisMode;
import org.alfresco.repo.search.impl.lucene.LuceneFunction;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.search.impl.querymodel.Argument;
import org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext;
@@ -78,11 +79,11 @@ public class LuceneFTSRange extends FTSRange implements LuceneQueryBuilderCompon
if (propArg != null)
{
String prop = propArg.getPropertyName();
query = lqp.getRangeQuery(functionContext.getLuceneFieldName(prop), from, to, fromInc, toInc, AnalysisMode.DEFAULT);
query = lqp.getRangeQuery(functionContext.getLuceneFieldName(prop), from, to, fromInc, toInc, AnalysisMode.DEFAULT, LuceneFunction.FIELD);
}
else
{
query = lqp.getRangeQuery("TEXT", from, to, fromInc, toInc, AnalysisMode.DEFAULT);
query = lqp.getRangeQuery("TEXT", from, to, fromInc, toInc, AnalysisMode.DEFAULT, LuceneFunction.FIELD);
}
return query;
}

View File

@@ -27,6 +27,7 @@ package org.alfresco.repo.search.impl.querymodel.impl.lucene.functions;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.search.impl.lucene.LuceneFunction;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.search.impl.lucene.AnalysisMode;
import org.alfresco.repo.search.impl.querymodel.Argument;
@@ -72,11 +73,11 @@ public class LuceneFTSTerm extends FTSTerm implements LuceneQueryBuilderComponen
if (propArg != null)
{
String prop = propArg.getPropertyName();
query = lqp.getFieldQuery(functionContext.getLuceneFieldName(prop), term, mode);
query = lqp.getFieldQuery(functionContext.getLuceneFieldName(prop), term, mode, LuceneFunction.FIELD);
}
else
{
query = lqp.getFieldQuery("TEXT", term, mode);
query = lqp.getFieldQuery("TEXT", term, mode, LuceneFunction.FIELD);
}
return query;

View File

@@ -65,7 +65,7 @@ public class LuceneGreaterThan extends GreaterThan implements LuceneQueryBuilder
LuceneQueryParser lqp = luceneContext.getLuceneQueryParser();
setPropertyAndStaticArguments(functionArgs);
Query query = functionContext.buildLuceneGreaterThan(lqp, getPropertyArgument().getPropertyName(), getStaticArgument().getValue(functionContext), PredicateMode.ANY);
Query query = functionContext.buildLuceneGreaterThan(lqp, getPropertyName(), getStaticArgument().getValue(functionContext), PredicateMode.ANY, functionContext.getLuceneFunction(getFunctionArgument()));
if(query == null)
{

View File

@@ -66,7 +66,7 @@ public class LuceneGreaterThanOrEquals extends GreaterThanOrEquals implements Lu
LuceneQueryParser lqp = luceneContext.getLuceneQueryParser();
setPropertyAndStaticArguments(functionArgs);
Query query = functionContext.buildLuceneGreaterThanOrEquals(lqp, getPropertyArgument().getPropertyName(), getStaticArgument().getValue(functionContext), PredicateMode.ANY);
Query query = functionContext.buildLuceneGreaterThanOrEquals(lqp, getPropertyName(), getStaticArgument().getValue(functionContext), PredicateMode.ANY, functionContext.getLuceneFunction(getFunctionArgument()));
if(query == null)
{

View File

@@ -66,7 +66,7 @@ public class LuceneLessThan extends LessThan implements LuceneQueryBuilderCompon
LuceneQueryParser lqp = luceneContext.getLuceneQueryParser();
setPropertyAndStaticArguments(functionArgs);
Query query = functionContext.buildLuceneLessThan(lqp, getPropertyArgument().getPropertyName(), getStaticArgument().getValue(functionContext), PredicateMode.ANY);
Query query = functionContext.buildLuceneLessThan(lqp, getPropertyName(), getStaticArgument().getValue(functionContext), PredicateMode.ANY, functionContext.getLuceneFunction(getFunctionArgument()));
if(query == null)
{

View File

@@ -66,7 +66,7 @@ public class LuceneLessThanOrEquals extends LessThanOrEquals implements LuceneQu
LuceneQueryParser lqp = luceneContext.getLuceneQueryParser();
setPropertyAndStaticArguments(functionArgs);
Query query = functionContext.buildLuceneLessThanOrEquals(lqp, getPropertyArgument().getPropertyName(), getStaticArgument().getValue(functionContext), PredicateMode.ANY);
Query query = functionContext.buildLuceneLessThanOrEquals(lqp, getPropertyName(), getStaticArgument().getValue(functionContext), PredicateMode.ANY, functionContext.getLuceneFunction(getFunctionArgument()));
if(query == null)
{
throw new QueryModelException("No query time mapping for property "+getPropertyArgument().getPropertyName()+", it should not be allowed in predicates");

View File

@@ -40,7 +40,6 @@ import org.apache.lucene.search.Query;
/**
* @author andyh
*
*/
public class LuceneNotEquals extends NotEquals implements LuceneQueryBuilderComponent
{
@@ -65,16 +64,16 @@ public class LuceneNotEquals extends NotEquals implements LuceneQueryBuilderComp
{
LuceneQueryParser lqp = luceneContext.getLuceneQueryParser();
setPropertyAndStaticArguments(functionArgs);
Query query = functionContext.buildLuceneInequality(lqp, getPropertyArgument().getPropertyName(), getStaticArgument().getValue(functionContext), PredicateMode.ANY);
if(query == null)
Query query = functionContext.buildLuceneInequality(lqp, getPropertyName(), getStaticArgument().getValue(functionContext), PredicateMode.ANY, functionContext
.getLuceneFunction(getFunctionArgument()));
if (query == null)
{
throw new QueryModelException("No query time mapping for property "+getPropertyArgument().getPropertyName()+", it should not be allowed in predicates");
throw new QueryModelException("No query time mapping for property " + getPropertyArgument().getPropertyName() + ", it should not be allowed in predicates");
}
return query;
}
}