home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / AIAT / Headers / Index / IAIndex.h < prev    next >
Encoding:
Text File  |  1998-04-16  |  5.1 KB  |  169 lines  |  [TEXT/CWIE]

  1. // IAIndex.h
  2. //    Copyright:    © 1994 - 1998 by Apple Computer, Inc., all rights reserved.
  3.  
  4. #pragma once
  5. #ifndef IAIndex_h
  6. #define IAIndex_h
  7.  
  8. #pragma import on
  9.  
  10. #if PRAGMA_STRUCT_ALIGN
  11.     #pragma options align=power
  12. #endif
  13.  
  14. #include "IAAnalysis.h"
  15. #include "IANarrow.h"
  16.  
  17. #include <time.h>
  18.  
  19. #pragma IA_BEGIN_EXPORTS
  20.  
  21. struct IAIndexTypes {
  22.         IAIndexTypes();
  23.         IAIndexTypes(uint32 storageType, uint32 corpusType, uint32 analysisType, uint32 indexType);
  24.  
  25.     // Returns true iff two IAIndexTypes are equal.        
  26.     bool            Equal(IAIndexTypes* other);
  27.     void             Store(IAOutputBlock* output) const;
  28.     void            Restore(IAInputBlock* input);
  29.         
  30.     uint32    storageType;
  31.     uint32    corpusType;
  32.     uint32    analysisType;
  33.     uint32    indexType;
  34.     uint32    osSetType;
  35. private:
  36.     void*    operator new(size_t size);        // stack allocate only
  37. };
  38.  
  39. class IAIndex : public IAObject {
  40. public:    // constructors
  41.         IAIndex(IAStorage* s, IACorpus* c, IAAnalysis* a, uint32 t, IABlockID r = NULL);
  42.  
  43.     virtual        ~IAIndex();                    // deletes corpus, analysis & mutex
  44.  
  45.     // Initializes a new emtpy index in a new empty storage.
  46.     virtual void            Initialize();
  47.     // Opens an existing index.
  48.     // By default, Calls Open() on the storage, corpus and analysis.
  49.     virtual void            Open();
  50.  
  51.     // Uses the corpus iterator to add new documents and delete expired documents.
  52.     // Simple applications should be able to maintain an index with just this method,
  53.     // Complex applications will need the more fine-grained control of the subsequent methods.
  54.     virtual void            Update();
  55.  
  56.     // Adds a document to the index.
  57.     virtual void            AddDoc(IADoc* doc) = 0;
  58.     // Updates the indexes references to an (unchanged) document.
  59.     virtual void            RenameDoc(const IADoc* oldName, const IADoc* newName) = 0;
  60.     // Removes a no-longer extant document (i.e., won’t call Text(id)).
  61.     virtual void            DeleteDoc(const IADoc* doc) = 0;
  62.     // Flushes all changes.  Call just before storage->Commit().
  63.     virtual void            Flush();
  64.     // Returns the time of the last call to Flush().
  65.     time_t                    UpdateTime() { return updateTime; }
  66.     // Attempts to compact the index.
  67.     virtual void            Compact();
  68.  
  69.     // Merges an array of indices into an index.
  70.     // The index, corpus and analysis classes must be the same for all indices.
  71.     // The indices must be disjoint -- no documents may be indexed in more than one index.
  72.     virtual void            Merge(IAIndex** indices, uint32 indexCount) = 0;
  73.  
  74.     // Returns true if a document is indexed.
  75.     virtual bool            IsDocIndexed(const IADoc* doc) = 0;
  76.  
  77.     // Returns the total number of documents indexed.
  78.     virtual uint32            GetDocCount() = 0;
  79.  
  80.     // Returns an iterator over all the documents indexed.
  81.     virtual IADocIterator*    GetDocIterator() = 0;
  82.     virtual IADocIterator*    GetDocIterator(const IADoc* start) = 0;
  83.  
  84.  
  85.     // Accesses the types of an index.  May be called at any time.
  86.     void                    GetIndexTypes(IAIndexTypes* types);
  87.     
  88.     IADefineNarrowMethods(IAIndex, IAIndex);                // support for IANarrow
  89.     
  90.     virtual IAAnalysis*        GetQueryAnalysis() const;
  91.     void            SetPreferredAnalysis(const IAAnalysis* analysis = NULL);
  92.     IAAnalysis*        GetPreferredAnalysis() const;
  93.     
  94.     IAStorage*                GetStorage() const {return storage;}
  95.     IACorpus*                GetCorpus() const {return corpus;}
  96.     IAAnalysis*                GetAnalysis() const {return analysis;}
  97.     uint32                    GetIndexType() const {return indexType;}
  98.     IABlockID                GetIndexRoot() const {return indexRoot;}
  99.     
  100.     void                    SetMaxDocumentSize(uint32 s = 2000) {fMaxDocSize = s;}
  101.     uint32                    GetMaxDocumentSize() const {return fMaxDocSize;}
  102.  
  103. protected:
  104.     // Root is stored by Initialize()--before Initializing() is called--and by Flush().
  105.     // The root is restored by Open().
  106.     // Subclasses can add data to the root block by defining these.
  107.     virtual IABlockSize        RootSize();
  108.     virtual void            StoreRoot(IAOutputBlock* output);
  109.     virtual void            RestoreRoot(IAInputBlock* input);
  110.     // Subclasses can add subsequent initializations by defining this.
  111.     // The base implementation initializes the corpus and analysis.
  112.     virtual void            Initializing();
  113.  
  114.     // Stored in the root block:
  115.     time_t                    updateTime;
  116.     IABlockID                corpusRoot;
  117.     IABlockID                analysisRoot;
  118.  
  119.     bool                    isOpen;
  120.     IAMutex*                mutex;
  121.     
  122.     // default constructor etc. so that this can be a virtual base class
  123.                 IAIndex();
  124.     void        Constructing(IAStorage* s, IACorpus* c, IAAnalysis* a, uint32 t, IABlockID r);
  125.     bool        isConstructed;
  126. private:
  127.     IAAnalysis*            fPreferedAnalysis;  // if set then is used for quey analysis 
  128.     
  129.     IAIndex(IAIndex&);            // don't define a copy constructor
  130.     
  131.     IAStorage*                storage;
  132.     IACorpus*                corpus;
  133.     IAAnalysis*                analysis;
  134.     
  135.     uint32                    indexType;
  136.     IABlockID                indexRoot;
  137.     
  138.     // The maximum number of tokens indexed per doc.
  139.     // Documents longer than this are currently truncated.
  140.     uint32                fMaxDocSize;
  141.  
  142.  
  143. };
  144.  
  145. void IAReadIndexTypes(IAStorage* storage, IABlockID indexRoot, IAIndexTypes* types);
  146.  
  147. IAExceptionCode                    IndexInvalid = 'VIIV';
  148. IAExceptionCode                    IndexNotInitialized = 'VINI';
  149. IAExceptionCode                    IndexNotOpen = 'VINO';
  150. IAExceptionCode                    IndexAlreadyOpen = 'VIAO';
  151. IAExceptionCode                    IndexDocAlreadyIndexed = 'VIAI';
  152. IAExceptionCode                    IndexDocNotIndexed = 'VIDN';
  153.  
  154. inline IAAnalysis* IAIndex::GetPreferredAnalysis() const
  155. {
  156.     return fPreferedAnalysis;
  157. }
  158.  
  159.  
  160. #pragma IA_END_EXPORTS
  161.  
  162. #if PRAGMA_STRUCT_ALIGN
  163.     #pragma options align=reset
  164. #endif
  165.  
  166. #pragma import reset
  167.  
  168. #endif
  169.