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_FieldDocSortedHitQueue_
8
#define _lucene_search_FieldDocSortedHitQueue_
10
#if defined(_LUCENE_PRAGMA_ONCE)
15
#include "CLucene/util/PriorityQueue.h"
20
* Expert: A ScoreDoc which also contains information about
21
* how to sort the referenced document. In addition to the
22
* document number and score, this object contains an array
23
* of values for the document from the field(s) used to sort.
24
* For example, if the sort criteria was to sort by fields
25
* "a", "b" then "c", the <code>fields</code> object array
26
* will have three elements, corresponding respectively to
27
* the term values for the document in fields "a", "b" and "c".
28
* The class of each element in the array will be either
29
* Integer, Float or String depending on the type of values
30
* in the terms of each field.
35
class FieldDoc: LUCENE_BASE {
37
//FieldDoc did inherit from ScoreDoc, but now we make the scoredoc a member
38
struct ScoreDoc scoreDoc;
40
/** Expert: The values which are used to sort the referenced document.
41
* The order of these will match the original sort criteria given by a
42
* Sort object. Each Object will be either an Integer, Float or String,
43
* depending on the type of values in the terms of the original field.
45
* @see Searchable#search(Query,Filter,int32_t,Sort)
47
CL_NS(util)::Comparable** fields;
49
/** Expert: Creates one of these objects with empty sort information. */
50
FieldDoc (int32_t doc, float_t score);
51
/** Expert: Creates one of these objects with the given sort information. */
52
FieldDoc (int32_t doc, float_t score, CL_NS(util)::Comparable** fields);
57
* Expert: Collects sorted results from Searchable's and collates them.
58
* The elements put into this queue must be of type FieldDoc.
60
class FieldDocSortedHitQueue:
61
public CL_NS(util)::PriorityQueue<FieldDoc*,CL_NS(util)::Deletor::Object<FieldDoc> >
64
DEFINE_MUTEX(THIS_LOCK)
66
// this cannot contain AUTO fields - any AUTO fields should
67
// have been resolved by the time this class is used.
73
while(fields[fieldsLen]!=NULL)
77
// used in the case where the fields are sorted by locale
79
//todo: not implemented in clucene because locales has not been implemented
80
//Collator[] collators; //volatile
84
* Creates a hit queue sorted by the given list of fields.
85
* @param fields Field names, in priority order (highest priority first).
86
* @param size The number of hits to retain. Must be greater than zero.
88
FieldDocSortedHitQueue (SortField** fields, int32_t size);
89
~FieldDocSortedHitQueue();
93
* Allows redefinition of sort fields if they are <code>NULL</code>.
94
* This is to handle the case using ParallelMultiSearcher where the
95
* original list contains AUTO and we don't know the actual sort
96
* type until the values come back. The fields can only be set once.
97
* This method is thread safe.
100
void setFields (SortField** fields);
102
/** Returns the fields being used to sort. */
103
SortField** getFields() {
107
/** Returns an array of collators, possibly <code>NULL</code>. The collators
108
* correspond to any SortFields which were given a specific locale.
109
* @param fields Array of sort fields.
110
* @return Array, possibly <code>NULL</code>.
112
private Collator[] hasCollators (SortField[] fields) {
113
if (fields == NULL) return NULL;
114
Collator[] ret = new Collator[fields.length];
115
for (int32_t i=0; i<fields.length; ++i) {
116
Locale locale = fields[i].getLocale();
118
ret[i] = Collator.getInstance (locale);
125
* Returns whether <code>a</code> is less relevant than <code>b</code>.
128
* @return <code>true</code> if document <code>a</code> should be sorted after document <code>b</code>.
130
bool lessThan (FieldDoc* docA, FieldDoc* docB);
135
* Expert: Returned by low-level sorted search implementations.
137
* @see Searchable#search(Query,Filter,int32_t,Sort)
139
class TopFieldDocs: public TopDocs {
141
/// The fields which were used to sort results by.
144
FieldDoc** fieldDocs;
146
/** Creates one of these objects.
147
* @param totalHits Total number of hits for the query.
148
* @param fieldDocs The top hits for the query.
149
* @param scoreDocs The top hits for the query.
150
* @param scoreDocsLen Length of fieldDocs and scoreDocs
151
* @param fields The sort criteria used to find the top hits.
153
TopFieldDocs (int32_t totalHits, FieldDoc** fieldDocs, int32_t scoreDocsLen, SortField** fields);