FTS - add range support - MOB-571

- range is not suported for TEXT and ALL

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14114 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Andrew Hind
2009-04-29 08:56:36 +00:00
parent 1cf01544d8
commit 7cd1ccae96
7 changed files with 238 additions and 6 deletions

View File

@@ -70,8 +70,7 @@ public class FTSProximity extends BaseFunction
}
public Serializable getValue(Map<String, Argument> args, FunctionEvaluationContext context)
{
// TODO Auto-generated method stub
return null;
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,81 @@
/*
* 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.querymodel.impl.functions;
import java.io.Serializable;
import java.util.LinkedHashMap;
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.FunctionEvaluationContext;
import org.alfresco.repo.search.impl.querymodel.Multiplicity;
import org.alfresco.repo.search.impl.querymodel.impl.BaseArgumentDefinition;
import org.alfresco.repo.search.impl.querymodel.impl.BaseFunction;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
public class FTSRange extends BaseFunction
{
public final static String NAME = "FTSRange";
public final static String ARG_FROM_INC = "FromInc";
public final static String ARG_FROM = "From";
public final static String ARG_TO = "To";
public final static String ARG_TO_INC = "ToInc";
public final static String ARG_PROPERTY = "Property";
public static LinkedHashMap<String, ArgumentDefinition> args;
static
{
args = new LinkedHashMap<String, ArgumentDefinition>();
args.put(ARG_FROM_INC, new BaseArgumentDefinition(Multiplicity.SINGLE_VALUED, ARG_FROM_INC, DataTypeDefinition.BOOLEAN, true));
args.put(ARG_FROM, new BaseArgumentDefinition(Multiplicity.SINGLE_VALUED, ARG_FROM, DataTypeDefinition.TEXT, true));
args.put(ARG_TO, new BaseArgumentDefinition(Multiplicity.SINGLE_VALUED, ARG_TO, DataTypeDefinition.TEXT, true));
args.put(ARG_TO_INC, new BaseArgumentDefinition(Multiplicity.SINGLE_VALUED, ARG_TO_INC, DataTypeDefinition.BOOLEAN, true));
args.put(ARG_PROPERTY, new BaseArgumentDefinition(Multiplicity.SINGLE_VALUED, ARG_PROPERTY, DataTypeDefinition.ANY, false));
}
/**
* @param name
* @param returnType
* @param argumentDefinitions
*/
public FTSRange()
{
super(NAME, DataTypeDefinition.BOOLEAN, args);
}
public Serializable getValue(Map<String, Argument> args, FunctionEvaluationContext context)
{
throw new UnsupportedOperationException();
}
}

View File

@@ -74,6 +74,7 @@ import org.alfresco.repo.search.impl.querymodel.impl.lucene.functions.LuceneFTSE
import org.alfresco.repo.search.impl.querymodel.impl.lucene.functions.LuceneFTSExpandTerm;
import org.alfresco.repo.search.impl.querymodel.impl.lucene.functions.LuceneFTSPhrase;
import org.alfresco.repo.search.impl.querymodel.impl.lucene.functions.LuceneFTSProximity;
import org.alfresco.repo.search.impl.querymodel.impl.lucene.functions.LuceneFTSRange;
import org.alfresco.repo.search.impl.querymodel.impl.lucene.functions.LuceneFTSTerm;
import org.alfresco.repo.search.impl.querymodel.impl.lucene.functions.LuceneGreaterThan;
import org.alfresco.repo.search.impl.querymodel.impl.lucene.functions.LuceneGreaterThanOrEquals;
@@ -121,6 +122,7 @@ public class LuceneQueryModelFactory implements QueryModelFactory
functions.put(FTSPhrase.NAME, new LuceneFTSPhrase());
functions.put(LuceneFTSExpandTerm.NAME, new LuceneFTSExpandTerm());
functions.put(LuceneFTSProximity.NAME, new LuceneFTSProximity());
functions.put(LuceneFTSRange.NAME, new LuceneFTSRange());
}

View File

@@ -78,7 +78,7 @@ public class LuceneFTSProximity extends FTSProximity implements LuceneQueryBuild
if (propArg != null)
{
String prop = propArg.getPropertyName();
query = lqp.getSpanQuery(prop, first, last, slop, true);
query = lqp.getSpanQuery(functionContext.getLuceneFieldName(prop), first, last, slop, true);
}
else
{

View File

@@ -0,0 +1,83 @@
/*
* 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.querymodel.impl.lucene.functions;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.search.impl.lucene.LuceneQueryParser;
import org.alfresco.repo.search.impl.querymodel.Argument;
import org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext;
import org.alfresco.repo.search.impl.querymodel.PropertyArgument;
import org.alfresco.repo.search.impl.querymodel.impl.functions.FTSRange;
import org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryBuilderComponent;
import org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryBuilderContext;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.search.Query;
public class LuceneFTSRange extends FTSRange implements LuceneQueryBuilderComponent
{
/**
*
*/
public LuceneFTSRange()
{
super();
}
/*
* (non-Javadoc)
*
* @see org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryBuilderComponent#addComponent(org.apache.lucene.search.BooleanQuery,
* org.apache.lucene.search.BooleanQuery, org.alfresco.service.cmr.dictionary.DictionaryService,
* java.lang.String)
*/
public Query addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext luceneContext, FunctionEvaluationContext functionContext)
throws ParseException
{
LuceneQueryParser lqp = luceneContext.getLuceneQueryParser();
Argument argument = functionArgs.get(ARG_FROM_INC);
Boolean fromInc = (Boolean) argument.getValue(functionContext);
argument = functionArgs.get(ARG_FROM);
String from = (String) argument.getValue(functionContext);
argument = functionArgs.get(ARG_TO);
String to = (String) argument.getValue(functionContext);
argument = functionArgs.get(ARG_TO_INC);
Boolean toInc = (Boolean) argument.getValue(functionContext);
PropertyArgument propArg = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
Query query;
if (propArg != null)
{
String prop = propArg.getPropertyName();
query = lqp.getRangeQuery(functionContext.getLuceneFieldName(prop), from, to, fromInc, toInc);
}
else
{
query = lqp.getRangeQuery("TEXT", from, to, fromInc, toInc);
}
return query;
}
}