~ubuntu-branches/ubuntu/raring/clucene-core/raring-proposed

« back to all changes in this revision

Viewing changes to src/core/CLucene/search/CachingSpanFilter.cpp

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2012-08-11 09:33:38 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120811093338-fgrx41ftqew3qt6a
Tags: 2.3.3.4-1
* New upstream release (Closes: #661703).
* Convert package to multiarch.
* Drop obsolete patches:
  - 01_add_missing_include_bug505667.diff
  - 02_posixness_fix_bug530308.diff
* Add patches:
  - Fixing_ZLIB_configuration_in_shared_CMakeLists.patch
  - Fix-pkgconfig-file-by-adding-clucene-shared-library.patch
  - Install-contribs-lib.patch
  - multiarch.patch
* Update debian/compat: bump to 8.
* Update debian/control:
  - update build dependencies (add cmake, libboost-dev and libz-dev).
  - bump Standards-Version to 3.9.3.
  - rename packages due to ABI bump: libclucene0ldbl -> libclucene-core1.
  - add libclucene-contribs1 package.
* Update debian/rules:
  - rewrite to use CMake.
  - add multiarch support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*------------------------------------------------------------------------------
 
2
 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
 
3
 * 
 
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
#include "CLucene/_ApiHeader.h"
 
8
#include "CachingSpanFilter.h"
 
9
#include "CLucene/index/IndexReader.h"
 
10
 
 
11
 
 
12
CL_NS_DEF(search)
 
13
 
 
14
/**
 
15
 * Result wrapper for the cache
 
16
 */
 
17
class ResultHolder : LUCENE_BASE
 
18
{
 
19
        bool deleteResult;
 
20
public:
 
21
        SpanFilterResult * result;
 
22
        
 
23
        ResultHolder(SpanFilterResult * result, bool deleteResult )
 
24
    {
 
25
                this->result = result;
 
26
                this->deleteResult = deleteResult;
 
27
        }
 
28
        ~ResultHolder()
 
29
    {
 
30
                if ( deleteResult )
 
31
                        _CLDELETE( result );
 
32
        }       
 
33
};
 
34
 
 
35
struct CachingSpanFilter::Internal
 
36
{
 
37
        typedef CL_NS(util)::CLHashMap<
 
38
        CL_NS(index)::IndexReader *, 
 
39
        ResultHolder *, 
 
40
        CL_NS(util)::Compare::Void<CL_NS(index)::IndexReader>,
 
41
        CL_NS(util)::Equals::Void<CL_NS(index)::IndexReader>,
 
42
        CL_NS(util)::Deletor::Object<CL_NS(index)::IndexReader>, 
 
43
        CL_NS(util)::Deletor::Object<ResultHolder> 
 
44
    > ResultCacheType; 
 
45
 
 
46
        ResultCacheType     cache;
 
47
        DEFINE_MUTEX(cache_LOCK)
 
48
 
 
49
        Internal() : cache(false,true)
 
50
        {}
 
51
};
 
52
 
 
53
CachingSpanFilter::CachingSpanFilter( SpanFilter * filter, bool deleteFilter )
 
54
{
 
55
    _internal = _CLNEW Internal();
 
56
    this->filter = filter;
 
57
    this->deleteFilter = deleteFilter;
 
58
}
 
59
 
 
60
CachingSpanFilter::CachingSpanFilter( const CachingSpanFilter& copy )
 
61
{
 
62
    _internal = _CLNEW Internal();
 
63
        this->filter = (SpanFilter*)copy.filter->clone();
 
64
    this->deleteFilter = true;
 
65
}
 
66
 
 
67
CachingSpanFilter::~CachingSpanFilter()
 
68
{
 
69
    _CLDELETE( _internal );
 
70
    if( deleteFilter )
 
71
    {
 
72
        _CLDELETE( filter );
 
73
    }
 
74
    else
 
75
        filter = NULL;
 
76
}
 
77
 
 
78
Filter* CachingSpanFilter::clone() const 
 
79
{
 
80
        return _CLNEW CachingSpanFilter( *this );
 
81
}
 
82
 
 
83
CL_NS(util)::BitSet* CachingSpanFilter::bits( CL_NS(index)::IndexReader * reader )
 
84
{
 
85
    SpanFilterResult * result = getCachedResult( reader );
 
86
    return result != NULL ? result->getBits() : NULL;
 
87
}
 
88
 
 
89
SpanFilterResult * CachingSpanFilter::getCachedResult( CL_NS(index)::IndexReader * reader )
 
90
{
 
91
        SCOPED_LOCK_MUTEX( _internal->cache_LOCK )
 
92
 
 
93
    ResultHolder * resultHolder = _internal->cache.get( reader );
 
94
    if( ! resultHolder )
 
95
    {
 
96
        SpanFilterResult * result = filter->bitSpans( reader );
 
97
        resultHolder = _CLNEW ResultHolder( result, true );
 
98
        _internal->cache.put( reader, resultHolder );
 
99
    }
 
100
 
 
101
    return resultHolder->result;
 
102
}
 
103
 
 
104
SpanFilterResult * CachingSpanFilter::bitSpans( CL_NS(index)::IndexReader * reader )
 
105
{
 
106
    return getCachedResult( reader );
 
107
}
 
108
 
 
109
TCHAR* CachingSpanFilter::toString()
 
110
{
 
111
        TCHAR* ft = filter->toString();
 
112
        size_t len = _tcslen( ft ) + 20;
 
113
        TCHAR* ret = _CL_NEWARRAY( TCHAR, len );
 
114
        ret[0] = 0;
 
115
        _sntprintf( ret, len, _T( "CachingSpanFilter(%s)" ), ft );
 
116
        _CLDELETE_CARRAY( ft );
 
117
        return ret;
 
118
}
 
119
 
 
120
CL_NS_END
 
 
b'\\ No newline at end of file'