Lucene++ - a full-featured, c++ search engine
API Documentation


Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes
Lucene::FieldMaskingSpanQuery Class Reference

Wrapper to allow SpanQuery objects participate in composite single-field SpanQueries by 'lying' about their search field. That is, the masked SpanQuery will function as normal, but SpanQuery#getField() simply hands back the value supplied in this class's constructor. More...

#include <FieldMaskingSpanQuery.h>

+ Inheritance diagram for Lucene::FieldMaskingSpanQuery:

Public Member Functions

 FieldMaskingSpanQuery (const SpanQueryPtr &maskedQuery, const String &maskedField)
 
virtual ~FieldMaskingSpanQuery ()
 
virtual String getClassName ()
 
boost::shared_ptr< FieldMaskingSpanQueryshared_from_this ()
 
virtual String getField ()
 Returns the name of the field matched by this query.
 
SpanQueryPtr getMaskedQuery ()
 
virtual SpansPtr getSpans (const IndexReaderPtr &reader)
 Returns the matches for this query in an index. Used internally to search for spans.
 
virtual void extractTerms (SetTerm terms)
 Adds all terms occurring in this query to the terms set. Only works if this query is in its rewritten form.
 
virtual WeightPtr createWeight (const SearcherPtr &searcher)
 Constructs an appropriate Weight implementation for this query. Only implemented by primitive queries, which re-write to themselves.
 
virtual SimilarityPtr getSimilarity (const SearcherPtr &searcher)
 Returns the Similarity implementation to be used for this query. Subclasses may override this method to specify their own Similarity implementation, perhaps one that delegates through that of the Searcher. By default the Searcher's Similarity implementation is returned.
 
virtual QueryPtr rewrite (const IndexReaderPtr &reader)
 Called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.
 
virtual String toString (const String &field)
 Prints a query to a string, with field assumed to be the default field and omitted.
 
virtual bool equals (const LuceneObjectPtr &other)
 Return whether two objects are equal.
 
virtual int32_t hashCode ()
 Return hash code for this object.
 
virtual LuceneObjectPtr clone (const LuceneObjectPtr &other=LuceneObjectPtr())
 Returns a clone of this query.
 
- Public Member Functions inherited from Lucene::SpanQuery
virtual ~SpanQuery ()
 
boost::shared_ptr< SpanQueryshared_from_this ()
 
- Public Member Functions inherited from Lucene::Query
 Query ()
 
virtual ~Query ()
 
boost::shared_ptr< Queryshared_from_this ()
 
virtual void setBoost (double b)
 Sets the boost for this query clause to b. Documents matching this clause will (in addition to the normal weightings) have their score multiplied by b.
 
virtual double getBoost ()
 Gets the boost for this clause. Documents matching this clause will (in addition to the normal weightings) have their score multiplied by b. The boost is 1.0 by default.
 
virtual String toString ()
 Prints a query to a string.
 
virtual WeightPtr weight (const SearcherPtr &searcher)
 Constructs and initializes a Weight for a top-level query.
 
virtual QueryPtr combine (Collection< QueryPtr > queries)
 Called when re-writing queries under MultiSearcher.
 
String boostString ()
 Return given boost value as a string.
 
- Public Member Functions inherited from Lucene::LuceneObject
virtual ~LuceneObject ()
 
virtual void initialize ()
 Called directly after instantiation to create objects that depend on this object being fully constructed.
 
virtual int32_t compareTo (const LuceneObjectPtr &other)
 Compare two objects.
 
- Public Member Functions inherited from Lucene::LuceneSync
virtual ~LuceneSync ()
 
virtual SynchronizePtr getSync ()
 Return this object synchronize lock.
 
virtual LuceneSignalPtr getSignal ()
 Return this object signal.
 
virtual void lock (int32_t timeout=0)
 Lock this object using an optional timeout.
 
virtual void unlock ()
 Unlock this object.
 
virtual bool holdsLock ()
 Returns true if this object is currently locked by current thread.
 
virtual void wait (int32_t timeout=0)
 Wait for signal using an optional timeout.
 
virtual void notifyAll ()
 Notify all threads waiting for signal.
 

Static Public Member Functions

static String _getClassName ()
 
- Static Public Member Functions inherited from Lucene::SpanQuery
static String _getClassName ()
 
- Static Public Member Functions inherited from Lucene::Query
static String _getClassName ()
 
static QueryPtr mergeBooleanQueries (Collection< BooleanQueryPtr > queries)
 Merges the clauses of a set of BooleanQuery's into a single BooleanQuery.
 

Protected Attributes

SpanQueryPtr maskedQuery
 
String field
 
- Protected Attributes inherited from Lucene::Query
double boost
 
- Protected Attributes inherited from Lucene::LuceneSync
SynchronizePtr objectLock
 
LuceneSignalPtr objectSignal
 

Additional Inherited Members

- Protected Member Functions inherited from Lucene::LuceneObject
 LuceneObject ()
 

Detailed Description

Wrapper to allow SpanQuery objects participate in composite single-field SpanQueries by 'lying' about their search field. That is, the masked SpanQuery will function as normal, but SpanQuery#getField() simply hands back the value supplied in this class's constructor.

This can be used to support Queries like SpanNearQuery or SpanOrQuery across different fields, which is not ordinarily permitted.

This can be useful for denormalized relational data: for example, when indexing a document with conceptually many 'children':

teacherid: 1
studentfirstname: james
studentsurname: jones

teacherid: 2
studenfirstname: james
studentsurname: smith
studentfirstname: sally
studentsurname: jones

A SpanNearQuery with a slop of 0 can be applied across two SpanTermQuery objects as follows:

SpanQueryPtr q1 = newLucene<SpanTermQuery>(newLucene<Term>(L"studentfirstname", L"james"));
SpanQueryPtr q2 = newLucene<SpanTermQuery>(newLucene<Term>(L"studentsurname", L"jones"));
SpanQueryPtr q2m = newLucene<FieldMaskingSpanQuery>(q2, L"studentfirstname");

Collection<SpanQueryPtr> span = newCollection<SpanQueryPtr>(q1, q1);

QueryPtr q = newLucene<SpanNearQuery>(span, -1, false);

to search for 'studentfirstname:james studentsurname:jones' and find teacherid 1 without matching teacherid 2 (which has a 'james' in position 0 and 'jones' in position 1).

Note: as getField() returns the masked field, scoring will be done using the norms of the field name supplied. This may lead to unexpected scoring behaviour.

Constructor & Destructor Documentation

◆ FieldMaskingSpanQuery()

Lucene::FieldMaskingSpanQuery::FieldMaskingSpanQuery ( const SpanQueryPtr maskedQuery,
const String &  maskedField 
)

◆ ~FieldMaskingSpanQuery()

virtual Lucene::FieldMaskingSpanQuery::~FieldMaskingSpanQuery ( )
virtual

Member Function Documentation

◆ _getClassName()

static String Lucene::FieldMaskingSpanQuery::_getClassName ( )
inlinestatic

◆ clone()

virtual LuceneObjectPtr Lucene::FieldMaskingSpanQuery::clone ( const LuceneObjectPtr other = LuceneObjectPtr())
virtual

Returns a clone of this query.

Reimplemented from Lucene::Query.

◆ createWeight()

virtual WeightPtr Lucene::FieldMaskingSpanQuery::createWeight ( const SearcherPtr searcher)
virtual

Constructs an appropriate Weight implementation for this query. Only implemented by primitive queries, which re-write to themselves.

Reimplemented from Lucene::SpanQuery.

◆ equals()

virtual bool Lucene::FieldMaskingSpanQuery::equals ( const LuceneObjectPtr other)
virtual

Return whether two objects are equal.

Reimplemented from Lucene::Query.

◆ extractTerms()

virtual void Lucene::FieldMaskingSpanQuery::extractTerms ( SetTerm  terms)
virtual

Adds all terms occurring in this query to the terms set. Only works if this query is in its rewritten form.

Reimplemented from Lucene::Query.

◆ getClassName()

virtual String Lucene::FieldMaskingSpanQuery::getClassName ( )
inlinevirtual

Reimplemented from Lucene::SpanQuery.

◆ getField()

virtual String Lucene::FieldMaskingSpanQuery::getField ( )
virtual

Returns the name of the field matched by this query.

Implements Lucene::SpanQuery.

◆ getMaskedQuery()

SpanQueryPtr Lucene::FieldMaskingSpanQuery::getMaskedQuery ( )

◆ getSimilarity()

virtual SimilarityPtr Lucene::FieldMaskingSpanQuery::getSimilarity ( const SearcherPtr searcher)
virtual

Returns the Similarity implementation to be used for this query. Subclasses may override this method to specify their own Similarity implementation, perhaps one that delegates through that of the Searcher. By default the Searcher's Similarity implementation is returned.

Reimplemented from Lucene::Query.

◆ getSpans()

virtual SpansPtr Lucene::FieldMaskingSpanQuery::getSpans ( const IndexReaderPtr reader)
virtual

Returns the matches for this query in an index. Used internally to search for spans.

Implements Lucene::SpanQuery.

◆ hashCode()

virtual int32_t Lucene::FieldMaskingSpanQuery::hashCode ( )
virtual

Return hash code for this object.

Reimplemented from Lucene::Query.

◆ rewrite()

virtual QueryPtr Lucene::FieldMaskingSpanQuery::rewrite ( const IndexReaderPtr reader)
virtual

Called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.

Reimplemented from Lucene::Query.

◆ shared_from_this()

boost::shared_ptr< FieldMaskingSpanQuery > Lucene::FieldMaskingSpanQuery::shared_from_this ( )
inline

◆ toString()

virtual String Lucene::FieldMaskingSpanQuery::toString ( const String &  field)
virtual

Prints a query to a string, with field assumed to be the default field and omitted.

The representation used is one that is supposed to be readable by QueryParser. However, there are the following limitations:

If the query was created by the parser, the printed representation may not be exactly what was parsed. For example, characters that need to be escaped will be represented without the required backslash.

Some of the more complicated queries (eg. span queries) don't have a representation that can be parsed by QueryParser.

Reimplemented from Lucene::Query.

Field Documentation

◆ field

String Lucene::FieldMaskingSpanQuery::field
protected

◆ maskedQuery

SpanQueryPtr Lucene::FieldMaskingSpanQuery::maskedQuery
protected

The documentation for this class was generated from the following file:

clucene.sourceforge.net