1
/*------------------------------------------------------------------------------
2
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
4
* Distributable under the terms of either the Apache License (Version 2.0) or
5
* the GNU Lesser General Public License, as specified in the COPYING file.
6
------------------------------------------------------------------------------*/
7
#ifndef _lucene_search_spans_SpanNearQuery_
8
#define _lucene_search_spans_SpanNearQuery_
10
CL_CLASS_DEF(index, IndexReader);
11
#include "SpanQuery.h"
13
CL_NS_DEF2( search, spans )
15
/** Matches spans which are near one another. One can specify <i>slop</i>, the
16
* maximum number of intervening unmatched positions, as well as whether
17
* matches are required to be in-order. */
18
class CLUCENE_EXPORT SpanNearQuery : public SpanQuery
31
SpanNearQuery( const SpanNearQuery& clone );
34
/** Construct a SpanNearQuery. Matches spans matching a span from each
35
* clause, with up to <code>slop</code> total unmatched positions between
36
* them. * When <code>inOrder</code> is true, the spans from each clause
37
* must be * ordered as in <code>clauses</code>. */
38
template<class ClauseIterator>
39
SpanNearQuery( ClauseIterator first, ClauseIterator last, int32_t slop, bool inOrder, bool bDeleteClauses )
41
// CLucene specific: at least one clause must be here
43
_CLTHROWA( CL_ERR_IllegalArgument, "Missing query clauses." );
45
this->bDeleteClauses = bDeleteClauses;
46
this->clausesCount = last - first;
47
this->clauses = _CL_NEWARRAY( SpanQuery *, clausesCount );
50
// copy clauses array into an array and check fields
51
for( size_t i = 0; first != last; first++, i++ )
53
SpanQuery * clause = *first;
56
setField( clause->getField() );
58
else if( 0 != _tcscmp( clause->getField(), field ))
60
_CLTHROWA( CL_ERR_IllegalArgument, "Clauses must have same field." );
62
this->clauses[ i ] = clause;
66
this->inOrder = inOrder;
69
virtual ~SpanNearQuery();
71
CL_NS(search)::Query * clone() const;
73
static const char * getClassName();
74
const char * getObjectName() const;
76
/** Return the clauses whose spans are matched.
77
* CLucene: pointer to the internal array
79
SpanQuery ** getClauses() const;
80
size_t getClausesCount() const;
82
/** Return the maximum number of intervening unmatched positions permitted.*/
83
int32_t getSlop() const;
85
/** Return true if matches are required to be in-order.*/
86
bool isInOrder() const;
88
const TCHAR * getField() const;
90
/** Returns a collection of all terms matched by this query.
91
* @deprecated use extractTerms instead
92
* @see #extractTerms(Set)
94
// public Collection getTerms()
96
void extractTerms( CL_NS(search)::TermSet * terms ) const;
98
CL_NS(search)::Query * rewrite( CL_NS(index)::IndexReader * reader );
100
using Query::toString;
101
TCHAR* toString( const TCHAR* field ) const;
102
bool equals( Query* other ) const;
103
size_t hashCode() const;
105
Spans * getSpans( CL_NS(index)::IndexReader * reader );
108
void setField( const TCHAR * field );
112
#endif // _lucene_search_spans_SpanNearQuery_