Add simple audio tag add-on and rename FullText dir to fulltext.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39185 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Clemens Zeidler
2010-10-29 13:03:03 +00:00
parent 2ad1d63bf9
commit 1a794e7f63
9 changed files with 129 additions and 3 deletions
@@ -0,0 +1,159 @@
/*
* Copyright 2010, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Clemens Zeidler <[email protected]>
*/
#include "FullTextAnalyser.h"
#include <new>
#include <Directory.h>
#include <String.h>
#include <TranslatorFormats.h>
#include <TranslatorRoster.h>
#include "CLuceneDataBase.h"
#include "IndexServerPrivate.h"
#define DEBUG_FULLTEXT_ANALYSER
#ifdef DEBUG_FULLTEXT_ANALYSER
#include <stdio.h>
# define STRACE(x...) printf("FullTextAnalyser: " x)
#else
# define STRACE(x...) ;
#endif
FullTextAnalyser::FullTextAnalyser(BString name, const BVolume& volume)
:
FileAnalyser(name, volume),
fWriteDataBase(NULL),
fNUncommited(0)
{
BDirectory dir;
volume.GetRootDirectory(&dir);
fDataBasePath.SetTo(&dir);
fDataBasePath.Append(kIndexServerDirectory);
status_t status = fDataBasePath.Append(kFullTextDirectory);
if (status == B_OK)
fWriteDataBase = new CLuceneWriteDataBase(fDataBasePath);
}
FullTextAnalyser::~FullTextAnalyser()
{
delete fWriteDataBase;
}
status_t
FullTextAnalyser::InitCheck()
{
if (fDataBasePath.InitCheck() != B_OK)
return fDataBasePath.InitCheck();
if (!fWriteDataBase)
return B_NO_MEMORY;
return fWriteDataBase->InitCheck();
}
void
FullTextAnalyser::AnalyseEntry(const entry_ref& ref)
{
if (!_InterestingEntry(ref))
return;
//STRACE("FullTextAnalyser AnalyseEntry: %s %s\n", ref.name, path.Path());
fWriteDataBase->AddDocument(ref);
fNUncommited++;
if (fNUncommited > 100)
LastEntry();
}
void
FullTextAnalyser::DeleteEntry(const entry_ref& ref)
{
if (_IsInIndexDirectory(ref))
return;
STRACE("FullTextAnalyser DeleteEntry: %s\n", ref.name);
fWriteDataBase->RemoveDocument(ref);
}
void
FullTextAnalyser::MoveEntry(const entry_ref& oldRef, const entry_ref& newRef)
{
if (!_InterestingEntry(newRef))
return;
STRACE("FullTextAnalyser MoveEntry: %s to %s\n", oldRef.name, newRef.name);
fWriteDataBase->RemoveDocument(oldRef);
AnalyseEntry(newRef);
}
void
FullTextAnalyser::LastEntry()
{
fWriteDataBase->Commit();
fNUncommited = 0;
}
bool
FullTextAnalyser::_InterestingEntry(const entry_ref& ref)
{
if (_IsInIndexDirectory(ref))
return false;
BFile file(&ref, B_READ_ONLY);
translator_info translatorInfo;
if (BTranslatorRoster::Default()->Identify(&file, NULL, &translatorInfo, 0,
NULL, B_TRANSLATOR_TEXT) != B_OK)
return false;
return true;
}
bool
FullTextAnalyser::_IsInIndexDirectory(const entry_ref& ref)
{
BPath path(&ref);
if (BString(path.Path()).FindFirst(fDataBasePath.Path()) == 0)
return true;
if (BString(path.Path()).FindFirst("/boot/common/cache/tmp") == 0)
return true;
return false;
}
FullTextAddOn::FullTextAddOn(image_id id, const char* name)
:
IndexServerAddOn(id, name)
{
}
FileAnalyser*
FullTextAddOn::CreateFileAnalyser(const BVolume& volume)
{
return new (std::nothrow)FullTextAnalyser(Name(), volume);
}
extern "C" IndexServerAddOn* (instantiate_index_server_addon)(image_id id,
const char* name)
{
return new (std::nothrow)FullTextAddOn(id, name);
}