16
/** Represents sorting by document score (relevancy). */
17
15
SortField* SortField::FIELD_SCORE = _CLNEW SortField (NULL, DOCSCORE,false);
19
/** Represents sorting by document number (index order). */
20
16
SortField* SortField::FIELD_DOC = _CLNEW SortField (NULL, DOC,false);
23
/** Represents sorting by computed relevance. Using this sort criteria
24
* returns the same results as calling {@link Searcher#search(Query) Searcher#search()}
25
* without a sort criteria, only with slightly more overhead. */
26
Sort* Sort::RELEVANCE = _CLNEW Sort();
28
/** Represents sorting by index order. */
29
Sort* Sort::INDEXORDER = _CLNEW Sort (SortField::FIELD_DOC);
34
/** Creates a sort by terms in the given field where the type of term value
35
* is determined dynamically ({@link #AUTO AUTO}).
36
* @param field Name of field to sort by, cannot be <code>null</code>.
17
Sort* Sort::RELEVANCE = _CLNEW Sort();
18
Sort* Sort::INDEXORDER = _CLNEW Sort (SortField::FIELD_DOC);
38
23
SortField::SortField (const TCHAR* field) {
40
25
this->reverse = false;
42
27
this->factory = NULL;
45
/** Creates a sort, possibly in reverse, by terms in the given field where
46
* the type of term value is determined dynamically ({@link #AUTO AUTO}).
47
* @param field Name of field to sort by, cannot be <code>null</code>.
48
* @param reverse True if natural order should be reversed.
50
SortField::SortField (const TCHAR* field, bool reverse) {
51
this->field = CLStringIntern::intern(field CL_FILELINE);
52
this->reverse = reverse;
58
/** Creates a sort, possibly in reverse, by terms in the given field with the
59
* type of term values explicitly given.
60
* @param field Name of field to sort by. Can be <code>null</code> if
61
* <code>type</code> is SCORE or DOC.
62
* @param type Type of values in the terms.
63
* @param reverse True if natural order should be reversed (default=false).
65
30
SortField::SortField (const TCHAR* field, int32_t type, bool reverse) {
66
31
this->field = (field != NULL) ? CLStringIntern::intern(field CL_FILELINE) : field;
106
/** Creates a sort, possibly in reverse, with a custom comparison function.
107
* @param field Name of field to sort by; cannot be <code>null</code>.
108
* @param comparator Returns a comparator for sorting hits.
109
* @param reverse True if natural order should be reversed (default=false).
111
71
SortField::SortField (const TCHAR* field, SortComparatorSource* comparator, bool reverse) {
112
72
this->field = (field != NULL) ? CLStringIntern::intern(field CL_FILELINE): field;
113
73
this->type = CUSTOM;
119
79
CLStringIntern::unintern(field);
122
const TCHAR* SortField::toString() const {
82
TCHAR* SortField::toString() const {
123
83
CL_NS(util)::StringBuffer buffer;
125
85
case DOCSCORE: buffer.append(_T("<score>"));
162
/** Sorts by computed relevance. This is the same sort criteria as
163
* calling {@link Searcher#search(Query) Searcher#search()} without a sort criteria, only with
164
* slightly more overhead. */
167
123
SortField** fields=_CL_NEWARRAY(SortField*,3);
188
144
_CLDELETE_ARRAY(fields);
192
/** Sorts possibly in reverse by the terms in <code>field</code> then by
193
* index order (document number). The type of value in <code>field</code> is determined
195
* @see SortField#AUTO
197
148
Sort::Sort (const TCHAR* field, bool reverse) {
198
149
this->fields=NULL;
199
150
setSort (field, reverse);
203
/** Sorts in succession by the terms in each field.
204
* The type of value in <code>field</code> is determined
206
* @see SortField#AUTO
208
153
Sort::Sort (const TCHAR** fields) {
209
154
this->fields=NULL;
210
155
setSort (fields);
214
/** Sorts by the criteria in the given SortField. */
215
157
Sort::Sort (SortField* field) {
216
158
this->fields=NULL;
221
/** Sorts in succession by the criteria in each SortField. */
222
162
Sort::Sort (SortField** fields) {
223
163
this->fields=NULL;
224
164
setSort (fields);
228
/** Sets the sort to the terms in <code>field</code> possibly in reverse,
229
* then by index order (document number). */
230
167
void Sort::setSort (const TCHAR* field, bool reverse) {
232
169
fields = _CL_NEWARRAY(SortField*,3);
274
206
this->fields[i]=fields[i];
277
const TCHAR* Sort::toString() const {
209
TCHAR* Sort::toString() const {
278
210
CL_NS(util)::StringBuffer buffer;
281
213
while ( fields[i] != NULL ){
283
buffer.appendChar(',');
215
buffer.appendChar(',');
285
const TCHAR* p = fields[i]->toString();
217
const TCHAR* p = fields[i]->toString();
292
224
return buffer.toString();
302
234
ScoreDocComparator::~ScoreDocComparator(){
306
/*ScoreDocComparator* SortComparator::newComparator (CL_NS(index)::IndexReader* reader, TCHAR* fieldname){
307
TCHAR* field = CLStringIntern::intern(fieldname);
238
class ScoreDocComparatorImpl: public ScoreDocComparator{
239
Comparable** cachedValues;
241
int32_t cachedValuesLen;
243
ScoreDocComparatorImpl(FieldCacheAuto* fca){
245
if ( fca->contentType != FieldCacheAuto::COMPARABLE_ARRAY )
246
_CLTHROWA(CL_ERR_InvalidCast,"Invalid field cache auto type");
247
this->cachedValues = fca->comparableArray;
248
this->cachedValuesLen = fca->contentLen;
250
~ScoreDocComparatorImpl(){
252
int32_t compare (struct ScoreDoc* i, struct ScoreDoc* j){
253
CND_PRECONDITION(i->doc >= 0 && i->doc < cachedValuesLen, "i->doc out of range")
254
CND_PRECONDITION(j->doc >= 0 && j->doc < cachedValuesLen, "j->doc out of range")
255
return cachedValues[i->doc]->compareTo (cachedValues[j->doc]);
258
CL_NS(util)::Comparable* sortValue (struct ScoreDoc* i){
259
CND_PRECONDITION(i->doc >= 0 && i->doc < cachedValuesLen, "i->doc out of range")
260
return cachedValues[i->doc];
264
return SortField::CUSTOM;
309
Comparable** cachedValues = FieldCache::DEFAULT().getCustom (reader, field, _this);
310
return _CLNEW ScoreDocComparator(cachedValues);
314
SortComparator::SortComparator(ScoreDocComparator* _this):SortComparatorSource(){
317
SortComparator::~SortComparator(){
268
ScoreDocComparator* SortComparator::newComparator (CL_NS(index)::IndexReader* reader, const TCHAR* fieldname){
269
return _CLNEW ScoreDocComparatorImpl(FieldCache::DEFAULT->getCustom (reader, fieldname, this));
271
SortComparator::SortComparator(){
273
SortComparator::~SortComparator(){