11namespace tracktion {
inline namespace engine
22 ids.
resize ((
size_t) numIDs);
23 in.
read (ids.
data(), (
int) sizeof (
int) * numIDs);
44 if (ids.
size() > 32766)
54ProjectSearchIndex::ProjectSearchIndex (
Project& p) : project (p)
89void ProjectSearchIndex::addClip (
const ProjectItem::Ptr& item)
93 for (
auto newWord : item->getSearchTokens())
97 if (! (word.isEmpty() || isNoiseWord (word)))
99 if (
auto w = findWordMatch (word))
101 w->addID (item->getID().getItemID());
105 index.add (
new IndexedWord (word, item->getID().getItemID()));
108 [] (IndexedWord* a, IndexedWord* b) { return a->word < b->word; });
119 for (
auto&& i : index)
120 i->writeToStream (out);
127 for (
int i = in.
readInt(); --i >= 0;)
128 index.add (
new IndexedWord (in));
131IndexedWord* ProjectSearchIndex::findWordMatch (
const juce::String& word)
const
134 int end = index.size();
141 auto w = index.getUnchecked (start);
146 const int halfway = (start +
end) >> 1;
148 if (halfway == start)
151 if (word.
compare (index[halfway]->word) >= 0)
162 for (
auto& res :
search.getMatches (*this))
163 results.add (ProjectItemID (res, project.getProjectID()));
168SearchOperation::SearchOperation (SearchOperation* o1, SearchOperation* o2) : in1 (o1), in2 (o2)
172SearchOperation::~SearchOperation()
185 if (
auto w = psi.findWordMatch (word))
186 for (
auto id : w->ids)
201 auto i1 = in1->getMatches (psi);
202 auto i2 = in2->getMatches (psi);
210 for (
int i = i2.size(); --i >= 0;)
211 i1.addIfNotAlreadyThere (i2[i]);
223 auto i1 = in1->getMatches (psi);
228 auto i2 = in2->getMatches (psi);
233 i1.removeValuesNotIn (i2);
246 i1 = psi.project.getAllItemIDs();
291 c =
new OrOperation (c,
new WordMatchOperation (s));
292 c =
new OrOperation (c,
new WordMatchOperation (s +
"e"));
308 c =
new OrOperation (
new OrOperation (c,
new WordMatchOperation (s.
dropLastCharacters (1))),
309 new WordMatchOperation (s +
"es"));
321 c =
new OrOperation (c,
new WordMatchOperation (s +
"es"));
325 c =
new OrOperation (c,
new WordMatchOperation (s +
"s"));
331inline SearchOperation* multipleWordMatch (
const juce::String& s)
336 SearchOperation* c =
nullptr;
338 for (
int i = a.
size(); --i >= 0;)
341 c =
new WordMatchOperation (a[i]);
343 c =
new AndOperation (c,
new WordMatchOperation (a[i]));
349inline SearchOperation* createCondition (
const juce::StringArray& words,
int start,
int length)
356 if (words[start] ==
TRANS(
"All"))
357 return new NotOperation (
new FalseOperation());
359 return createPluralOptions (words[start]);
362 if (length > 1 && words[start] ==
TRANS(
"Not"))
363 return new NotOperation (createCondition (words, start + 1, length - 1));
367 auto c = createCondition (words, start, 1);
369 if (words[start + 1] ==
TRANS(
"Or"))
370 return new OrOperation (c, createCondition (words, start + 2, length - 2));
372 if (words[start + 1] ==
TRANS(
"And"))
373 return new AndOperation (c, createCondition (words, start + 2, length - 2));
375 if (words[start + 1] ==
TRANS(
"But")
376 && words[start + 2] ==
TRANS(
"Not")
378 return new AndOperation (c,
new NotOperation (createCondition (words, start + 3, length - 3)));
380 if (words[start + 1] ==
TRANS(
"Not"))
381 return new AndOperation (c,
new NotOperation (createCondition (words, start + 2, length - 2)));
384 return new AndOperation (createCondition (words, start, 1),
385 createCondition (words, start + 1, length - 1));
394 .
retainCharacters (
juce::CharPointer_UTF8 (
"abcdefghijklmnopqrstuvwxyz0123456789\xc3\xa0\xc3\xa1\xc3\xa2\xc3\xa3\xc3\xa4\xc3\xa5\xc3\xa6\xc3\xa7\xc3\xa8\xc3\xa9\xc3\xaa\xc3\xab\xc3\xac\xc3\xad\xc3\xae\xc3\xaf\xc3\xb0\xc3\xb1\xc3\xb2\xc3\xb3\xc3\xb4\xc3\xb5\xc3\xb6\xc3\xb8\xc3\xb9\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3\xbf\xc3\x9f"))
402 for (
int i = words.
size(); --i >= 0;)
403 if (isNoiseWord (words[i])
404 && words[i] !=
TRANS(
"Not")
405 && words[i] !=
TRANS(
"Or")
406 && words[i] !=
TRANS(
"And"))
409 if (
auto sc = createCondition (words, 0, words.
size()))
void removeValuesIn(const OtherArrayType &otherArray)
void add(const ElementType &newElement)
virtual bool write(const void *dataToWrite, size_t numberOfBytes)=0
virtual bool writeShort(short value)
virtual bool writeInt(int value)
virtual bool writeString(const String &text)
void removeEmptyStrings(bool removeWhitespaceStrings=true)
int size() const noexcept
int addTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
int length() const noexcept
String retainCharacters(StringRef charactersToRetain) const
String dropLastCharacters(int numberToDrop) const
String toLowerCase() const
String replace(StringRef stringToReplace, StringRef stringToInsertInstead, bool ignoreCase=false) const
bool endsWith(StringRef text) const noexcept
int compare(const String &other) const noexcept
#define TRANS(stringLiteral)
SearchOperation * createSearchForKeywords(const juce::String &keywords)
Turns a keyword string into a search condition tree.