throw new ParseException( "Query cannot start with '*' or '?'!" );
}
if ( Field.NOT_PRESENT.equals( query ) )
{
return new WildcardQuery( new Term( indexerField.getKey(), "*" ) );
}
if ( SearchType.EXACT.equals( type ) )
{
if ( indexerField.isKeyword() )
{
// no tokenization should happen against the field!
if ( query.contains( "*" ) || query.contains( "?" ) )
{
return new WildcardQuery( new Term( indexerField.getKey(), query ) );
}
else
{
// exactly what callee wants
return new TermQuery( new Term( indexerField.getKey(), query ) );
}
}
else if ( !indexerField.isKeyword() && indexerField.isStored() )
{
// TODO: resolve this better! Decouple QueryCreator and IndexCreators!
// This is a hack/workaround here
if ( JarFileContentsIndexCreator.FLD_CLASSNAMES_KW.equals( indexerField ) )
{
if ( query.startsWith( "/" ) )
{
return new TermQuery( new Term( indexerField.getKey(), query.toLowerCase().replaceAll( "\\.",
"/" ) ) );
}
else
{
return new TermQuery( new Term( indexerField.getKey(), "/"
+ query.toLowerCase().replaceAll( "\\.", "/" ) ) );
}
}
else
{
getLogger().warn(
type.toString()
+ " type of querying for non-keyword (but stored) field "
+ indexerField.getOntology().toString()
+ " was tried. Please review your code, or indexCreator involved, since this type of querying of this field is currently unsupported." );
// will never succeed (unless we supply him "filter" too, but that would kill performance)
// and is possible with stored fields only
return null;
}
}
else
{
getLogger().warn(
type.toString()
+ " type of querying for non-keyword (and not stored) field "
+ indexerField.getOntology().toString()
+ " was tried. Please review your code, or indexCreator involved, since this type of querying of this field is impossible." );
// not a keyword indexerField, nor stored. No hope at all. Impossible even with "filtering"
return null;
}
}
else if ( SearchType.SCORED.equals( type ) )
{
if ( JarFileContentsIndexCreator.FLD_CLASSNAMES.equals( indexerField ) )
{
String qpQuery = query.toLowerCase().replaceAll( "\\.", " " ).replaceAll( "/", " " );
// tokenization should happen against the field!
QueryParser qp = new QueryParser( Version.LUCENE_30, indexerField.getKey(), new NexusAnalyzer() );
qp.setDefaultOperator( Operator.AND );
return qp.parse( qpQuery );
}
else if ( indexerField.isKeyword() )
{
// no tokenization should happen against the field!
if ( query.contains( "*" ) || query.contains( "?" ) )
{
return new WildcardQuery( new Term( indexerField.getKey(), query ) );
}
else
{
BooleanQuery bq = new BooleanQuery();