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

« back to all changes in this revision

Viewing changes to src/contribs-lib/CLucene/highlighter/TokenSources.h

  • 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
 
 
8
#ifndef _lucene_search_highlight_tokensources_
 
9
#define _lucene_search_highlight_tokensources_
 
10
 
 
11
#include "CLucene/analysis/AnalysisHeader.h"
 
12
CL_CLASS_DEF(index, IndexReader)
 
13
CL_CLASS_DEF(index, TermPositionVector)
 
14
//#include "CLucene/index/IndexReader.h"
 
15
//#include "CLucene/index/TermVector.h"
 
16
 
 
17
CL_NS_DEF2(search,highlight)
 
18
 
 
19
class CLUCENE_CONTRIBS_EXPORT TokenSources: LUCENE_BASE
 
20
{
 
21
        //an object used to iterate across an array of tokens
 
22
        class StoredTokenStream:public CL_NS(analysis)::TokenStream
 
23
    {
 
24
        public:
 
25
        CL_NS(analysis)::Token** tokens;
 
26
                size_t length;
 
27
        int32_t currentToken;
 
28
        StoredTokenStream(CL_NS(analysis)::Token** tokens, size_t len);
 
29
                CL_NS(analysis)::Token* next(CL_NS(analysis)::Token* token);
 
30
                void close();
 
31
    };
 
32
public:
 
33
        TokenSources(void);
 
34
        ~TokenSources(void);
 
35
 
 
36
        /**
 
37
     * A convenience method that tries a number of approaches to getting a token stream.
 
38
     * The cost of finding there are no termVectors in the index is minimal (1000 invocations still 
 
39
     * registers 0 ms). So this "lazy" (flexible?) approach to coding is probably acceptable
 
40
     * @param reader
 
41
     * @param docId
 
42
     * @param field
 
43
     * @param analyzer
 
44
     * @return null if field not stored correctly 
 
45
     * @throws IOException
 
46
     */
 
47
        static CL_NS(analysis)::TokenStream* getAnyTokenStream(CL_NS(index)::IndexReader* reader,int32_t docId, TCHAR* field, CL_NS(analysis)::Analyzer* analyzer);
 
48
    
 
49
    static CL_NS(analysis)::TokenStream* getTokenStream(CL_NS(index)::TermPositionVector* tpv);
 
50
 
 
51
    /**
 
52
     * Low level api.
 
53
     * Returns a token stream or null if no offset info available in index.
 
54
     * This can be used to feed the highlighter with a pre-parsed token stream 
 
55
     * 
 
56
     * In my tests the speeds to recreate 1000 token streams using this method are:
 
57
     * - with TermVector offset only data stored - 420  milliseconds 
 
58
     * - with TermVector offset AND position data stored - 271 milliseconds
 
59
     *  (nb timings for TermVector with position data are based on a tokenizer with contiguous
 
60
     *  positions - no overlaps or gaps)
 
61
     * The cost of not using TermPositionVector to store
 
62
     * pre-parsed content and using an analyzer to re-parse the original content: 
 
63
     * - reanalyzing the original content - 980 milliseconds
 
64
     * 
 
65
     * The re-analyze timings will typically vary depending on -
 
66
     *  1) The complexity of the analyzer code (timings above were using a 
 
67
     *     stemmer/lowercaser/stopword combo)
 
68
     *  2) The  number of other fields (Lucene reads ALL fields off the disk 
 
69
     *     when accessing just one document field - can cost dear!)
 
70
     *  3) Use of compression on field storage - could be faster cos of compression (less disk IO)
 
71
     *     or slower (more CPU burn) depending on the content.
 
72
     *
 
73
     * @param tpv
 
74
     * @param tokenPositionsGuaranteedContiguous true if the token position numbers have no overlaps or gaps. If looking
 
75
     * to eek out the last drops of performance, set to true. If in doubt, set to false.
 
76
     */
 
77
    static CL_NS(analysis)::TokenStream* getTokenStream(CL_NS(index)::TermPositionVector* tpv, bool tokenPositionsGuaranteedContiguous);
 
78
 
 
79
        static CL_NS(analysis)::TokenStream* getTokenStream(CL_NS(index)::IndexReader* reader,int32_t docId, TCHAR* field);
 
80
 
 
81
    //convenience method
 
82
        static CL_NS(analysis)::TokenStream* getTokenStream(CL_NS(index)::IndexReader* reader,int32_t docId, TCHAR* field,CL_NS(analysis)::Analyzer* analyzer);
 
83
};
 
84
 
 
85
CL_NS_END2
 
86
#endif