1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QCLucene library and is distributable under
|
---|
7 | ** the terms of the LGPL license as specified in the license.txt file.
|
---|
8 | **
|
---|
9 | ****************************************************************************/
|
---|
10 |
|
---|
11 | #include "qhits_p.h"
|
---|
12 | #include "qsearchable_p.h"
|
---|
13 |
|
---|
14 | #include <CLucene.h>
|
---|
15 | #include <CLucene/search/SearchHeader.h>
|
---|
16 |
|
---|
17 | QT_BEGIN_NAMESPACE
|
---|
18 |
|
---|
19 | QCLuceneHitsPrivate::QCLuceneHitsPrivate()
|
---|
20 | : QSharedData()
|
---|
21 | {
|
---|
22 | hits = 0;
|
---|
23 | deleteCLuceneHits = true;
|
---|
24 | }
|
---|
25 |
|
---|
26 | QCLuceneHitsPrivate::QCLuceneHitsPrivate(const QCLuceneHitsPrivate &other)
|
---|
27 | : QSharedData()
|
---|
28 | {
|
---|
29 | hits = _CL_POINTER(other.hits);
|
---|
30 | }
|
---|
31 |
|
---|
32 | QCLuceneHitsPrivate::~QCLuceneHitsPrivate()
|
---|
33 | {
|
---|
34 | if (deleteCLuceneHits)
|
---|
35 | _CLDECDELETE(hits);
|
---|
36 | }
|
---|
37 |
|
---|
38 |
|
---|
39 | QCLuceneHits::QCLuceneHits(const QCLuceneSearcher &searcher,
|
---|
40 | const QCLuceneQuery &query, const QCLuceneFilter &filter)
|
---|
41 | : d(new QCLuceneHitsPrivate())
|
---|
42 | {
|
---|
43 | d->hits = new lucene::search::Hits(searcher.d->searchable, query.d->query,
|
---|
44 | filter.d->filter);
|
---|
45 | }
|
---|
46 |
|
---|
47 | QCLuceneHits::QCLuceneHits(const QCLuceneSearcher &searcher, const QCLuceneQuery &query,
|
---|
48 | const QCLuceneFilter &filter, const QCLuceneSort &sort)
|
---|
49 | : d(new QCLuceneHitsPrivate())
|
---|
50 | {
|
---|
51 | d->hits = new lucene::search::Hits(searcher.d->searchable, query.d->query,
|
---|
52 | filter.d->filter, sort.d->sort);
|
---|
53 | }
|
---|
54 |
|
---|
55 | QCLuceneHits::~QCLuceneHits()
|
---|
56 | {
|
---|
57 | // nothing todo
|
---|
58 | }
|
---|
59 |
|
---|
60 | QCLuceneDocument QCLuceneHits::document(const qint32 index)
|
---|
61 | {
|
---|
62 | // TODO: check this
|
---|
63 | QCLuceneDocument document;
|
---|
64 | document.d->deleteCLuceneDocument = false;
|
---|
65 | lucene::document::Document &doc = d->hits->doc(int32_t(index));
|
---|
66 | document.d->document = &doc;
|
---|
67 |
|
---|
68 | return document;
|
---|
69 | }
|
---|
70 |
|
---|
71 | qint32 QCLuceneHits::length() const
|
---|
72 | {
|
---|
73 | return qint32(d->hits->length());
|
---|
74 | }
|
---|
75 |
|
---|
76 | qint32 QCLuceneHits::id(const qint32 index)
|
---|
77 | {
|
---|
78 | return qint32(d->hits->id(int32_t(index)));
|
---|
79 | }
|
---|
80 |
|
---|
81 | qreal QCLuceneHits::score(const qint32 index)
|
---|
82 | {
|
---|
83 | return qreal(d->hits->score(int32_t(index)));
|
---|
84 | }
|
---|
85 |
|
---|
86 | QT_END_NAMESPACE
|
---|