Package org.terrier.querying.parser
Class MultiTermQuery
- java.lang.Object
-
- org.terrier.querying.parser.Query
-
- org.terrier.querying.parser.MultiTermQuery
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
- Direct Known Subclasses:
DisjunctiveQuery
,ExplicitMultiTermQuery
,PhraseQuery
,SegmentQuery
public class MultiTermQuery extends Query
Represents a query consisting of more than one terms or other sub-queries, qualified with field, requirement or phrase operators.- Author:
- Vassilis Plachouras, Craig Macdonald
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.terrier.querying.parser.Query
Query.ForEachQueryNode, Query.QTPBuilder, Query.QueryTermsParameter
-
-
Constructor Summary
Constructors Constructor Description MultiTermQuery()
A default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(java.lang.String term)
Adds a single query term to the query.void
add(Query query)
Adds a subquery to this query.void
apply(Query.ForEachQueryNode processor)
Apply the specified processor to this node.boolean
applyTermPipeline(TermPipelineAccessor tpa)
Applies the given term pipeline to the query terms and sub-queries that construct this query.java.lang.Object
clone()
Deep copy this Query objectint
getNumberOfTerms()
Returns the number of terms, or subqueries.protected void
getTerms(java.util.List<Query> alist)
Adds all the subqueries and single-term queries to a given array list.void
getTermsOf(java.lang.Class<? extends Query> c, java.util.List<Query> alist, boolean req)
Returns all the query terms, in subqueries that are instances of a given classvoid
obtainAllOf(java.lang.Class<? extends Query> c, java.util.List<Query> a)
Returns all the queries of the specified classboolean
obtainControls(java.util.Set<java.lang.String> allowed, java.util.Map<java.lang.String,java.lang.String> controls)
Checks all child objects to see if they are FieldQuery objects, they are each called to see if the are controls.void
obtainQueryTerms(MatchingQueryTerms terms, java.lang.String field, java.lang.Boolean required, java.lang.Double weight)
void
obtainQueryTerms(Query.QueryTermsParameter parameters)
java.lang.String
parseTree()
Returns the parse tree for the query as a stringvoid
replace(Query childNode, Query replacement)
Replace query nodevoid
setWeight(double w)
Sets the weight of the disjunctive "term".java.lang.String
toString()
Returns a string representation of the query.
-
-
-
Field Detail
-
prefix
protected java.lang.String prefix
-
suffix
protected java.lang.String suffix
-
v
protected java.util.ArrayList<Query> v
A list for holding the sub-queries. A LinkedList is ideal as we have no need to access numbered sub-query elements of the query - only be able to iterate throught them.
-
-
Method Detail
-
setWeight
public void setWeight(double w)
Sets the weight of the disjunctive "term".- Parameters:
w
- double the weight of the disjunctive "term".
-
getNumberOfTerms
public int getNumberOfTerms()
Returns the number of terms, or subqueries.- Returns:
- int the number of terms, or subqueries of this query.
-
add
public void add(java.lang.String term)
Adds a single query term to the query.- Parameters:
term
- String the query term.
-
add
public void add(Query query)
Adds a subquery to this query.- Parameters:
query
- Query a subquery.
-
toString
public java.lang.String toString()
Returns a string representation of the query.
-
applyTermPipeline
public boolean applyTermPipeline(TermPipelineAccessor tpa)
Applies the given term pipeline to the query terms and sub-queries that construct this query.- Overrides:
applyTermPipeline
in classQuery
- Parameters:
tpa
- TermPipelineAccessor the object that gives access to a term pipeline.- Returns:
- boolean true if the query is not empty, otherwise returns false.
-
obtainQueryTerms
public void obtainQueryTerms(MatchingQueryTerms terms, java.lang.String field, java.lang.Boolean required, java.lang.Double weight)
- Specified by:
obtainQueryTerms
in classQuery
-
obtainQueryTerms
public void obtainQueryTerms(Query.QueryTermsParameter parameters)
- Specified by:
obtainQueryTerms
in classQuery
-
getTerms
protected void getTerms(java.util.List<Query> alist)
Adds all the subqueries and single-term queries to a given array list.
-
obtainControls
public boolean obtainControls(java.util.Set<java.lang.String> allowed, java.util.Map<java.lang.String,java.lang.String> controls)
Checks all child objects to see if they are FieldQuery objects, they are each called to see if the are controls. Child objects which return true are removed from the tree. If all child objects return true then this object is also considered dead, and should be removed.- Overrides:
obtainControls
in classQuery
- Parameters:
allowed
- The HashSet of control names that are allowed to be set.controls
- The Hashtable into which child objects much add found controls- Returns:
- true if this object should be considered dead (no longer part of the query), false otherwise.
-
getTermsOf
public void getTermsOf(java.lang.Class<? extends Query> c, java.util.List<Query> alist, boolean req)
Returns all the query terms, in subqueries that are instances of a given class- Specified by:
getTermsOf
in classQuery
- Parameters:
c
- Class a class of queries.alist
- ArrayList the list of query terms.req
- boolean indicates whether the subqueries are required or not.
-
replace
public void replace(Query childNode, Query replacement)
Replace query node- Parameters:
childNode
-replacement
-
-
obtainAllOf
public void obtainAllOf(java.lang.Class<? extends Query> c, java.util.List<Query> a)
Description copied from class:Query
Returns all the queries of the specified class- Overrides:
obtainAllOf
in classQuery
-
apply
public void apply(Query.ForEachQueryNode processor)
Apply the specified processor to this node. If the processor allows, move to any children nodes.
-
-