2 * Copyright 2010, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Clemens Zeidler <haiku@clemens-zeidler.de>
8 #include "FullTextAnalyser.h"
12 #include <Directory.h>
14 #include <TranslatorFormats.h>
15 #include <TranslatorRoster.h>
17 #include "CLuceneDataBase.h"
18 #include "IndexServerPrivate.h"
21 #define DEBUG_FULLTEXT_ANALYSER
22 #ifdef DEBUG_FULLTEXT_ANALYSER
24 # define STRACE(x...) printf("FullTextAnalyser: " x)
26 # define STRACE(x...) ;
30 FullTextAnalyser::FullTextAnalyser(BString name
, const BVolume
& volume
)
32 FileAnalyser(name
, volume
),
38 volume
.GetRootDirectory(&dir
);
39 fDataBasePath
.SetTo(&dir
);
40 fDataBasePath
.Append(kIndexServerDirectory
);
41 status_t status
= fDataBasePath
.Append(kFullTextDirectory
);
44 fWriteDataBase
= new CLuceneWriteDataBase(fDataBasePath
);
48 FullTextAnalyser::~FullTextAnalyser()
50 delete fWriteDataBase
;
55 FullTextAnalyser::InitCheck()
57 if (fDataBasePath
.InitCheck() != B_OK
)
58 return fDataBasePath
.InitCheck();
62 return fWriteDataBase
->InitCheck();
67 FullTextAnalyser::AnalyseEntry(const entry_ref
& ref
)
69 if (!_InterestingEntry(ref
))
72 //STRACE("FullTextAnalyser AnalyseEntry: %s %s\n", ref.name, path.Path());
73 fWriteDataBase
->AddDocument(ref
);
76 if (fNUncommited
> 100)
82 FullTextAnalyser::DeleteEntry(const entry_ref
& ref
)
84 if (_IsInIndexDirectory(ref
))
86 STRACE("FullTextAnalyser DeleteEntry: %s\n", ref
.name
);
87 fWriteDataBase
->RemoveDocument(ref
);
92 FullTextAnalyser::MoveEntry(const entry_ref
& oldRef
, const entry_ref
& newRef
)
94 if (!_InterestingEntry(newRef
))
96 STRACE("FullTextAnalyser MoveEntry: %s to %s\n", oldRef
.name
, newRef
.name
);
97 fWriteDataBase
->RemoveDocument(oldRef
);
103 FullTextAnalyser::LastEntry()
105 fWriteDataBase
->Commit();
111 FullTextAnalyser::_InterestingEntry(const entry_ref
& ref
)
113 if (_IsInIndexDirectory(ref
))
116 BFile
file(&ref
, B_READ_ONLY
);
117 translator_info translatorInfo
;
118 if (BTranslatorRoster::Default()->Identify(&file
, NULL
, &translatorInfo
, 0,
119 NULL
, B_TRANSLATOR_TEXT
) != B_OK
)
127 FullTextAnalyser::_IsInIndexDirectory(const entry_ref
& ref
)
130 if (BString(path
.Path()).FindFirst(fDataBasePath
.Path()) == 0)
133 if (BString(path
.Path()).FindFirst("/boot/system/cache/tmp") == 0)
140 FullTextAddOn::FullTextAddOn(image_id id
, const char* name
)
142 IndexServerAddOn(id
, name
)
149 FullTextAddOn::CreateFileAnalyser(const BVolume
& volume
)
151 return new (std::nothrow
)FullTextAnalyser(Name(), volume
);
155 extern "C" IndexServerAddOn
* (instantiate_index_server_addon
)(image_id id
,
158 return new (std::nothrow
)FullTextAddOn(id
, name
);