Database schema optimization - part 4
This commit is contained in:
@@ -12,6 +12,7 @@ use crate::calendar::{
|
||||
ArchivedCalendarEventNotification, ArchivedEventPreferences, CalendarEventNotification,
|
||||
EventPreferences,
|
||||
};
|
||||
use ahash::AHashSet;
|
||||
use calcard::icalendar::{
|
||||
ArchivedICalendarParameterValue, ArchivedICalendarProperty, ArchivedICalendarValue,
|
||||
ICalendarParameterValue, ICalendarProperty, ICalendarValue,
|
||||
@@ -19,7 +20,7 @@ use calcard::icalendar::{
|
||||
use common::storage::index::{IndexValue, IndexableAndSerializableObject, IndexableObject};
|
||||
use nlp::language::Language;
|
||||
use store::{
|
||||
search::{CalendarSearchField, IndexDocument},
|
||||
search::{CalendarSearchField, IndexDocument, SearchField},
|
||||
write::{IndexPropertyClass, SearchIndex, ValueClass},
|
||||
xxhash_rust::xxh3,
|
||||
};
|
||||
@@ -336,10 +337,14 @@ impl ArchivedCalendarEvent {
|
||||
}
|
||||
|
||||
impl ArchivedCalendarEvent {
|
||||
pub fn index_document(&self) -> IndexDocument {
|
||||
pub fn index_document(&self, index_fields: &AHashSet<SearchField>) -> IndexDocument {
|
||||
let mut document = IndexDocument::with_default_language(Language::Unknown);
|
||||
|
||||
document.index_integer(CalendarSearchField::Start, self.data.event_range_start());
|
||||
if index_fields.is_empty()
|
||||
|| index_fields.contains(&SearchField::Calendar(CalendarSearchField::Start))
|
||||
{
|
||||
document.index_integer(CalendarSearchField::Start, self.data.event_range_start());
|
||||
}
|
||||
|
||||
for component in self
|
||||
.data
|
||||
@@ -349,7 +354,7 @@ impl ArchivedCalendarEvent {
|
||||
.filter(|e| e.component_type.is_scheduling_object())
|
||||
{
|
||||
for entry in component.entries.iter() {
|
||||
let field = match entry.name {
|
||||
let field = SearchField::Calendar(match entry.name {
|
||||
ArchivedICalendarProperty::Summary => CalendarSearchField::Title,
|
||||
ArchivedICalendarProperty::Description => CalendarSearchField::Description,
|
||||
ArchivedICalendarProperty::Location => CalendarSearchField::Location,
|
||||
@@ -357,27 +362,29 @@ impl ArchivedCalendarEvent {
|
||||
ArchivedICalendarProperty::Attendee => CalendarSearchField::Attendee,
|
||||
ArchivedICalendarProperty::Uid => CalendarSearchField::Uid,
|
||||
_ => continue,
|
||||
};
|
||||
});
|
||||
|
||||
for value in entry
|
||||
.values
|
||||
.iter()
|
||||
.filter_map(|v| match v {
|
||||
ArchivedICalendarValue::Text(v) => Some(v.as_str()),
|
||||
ArchivedICalendarValue::Uri(uri) => uri.as_str(),
|
||||
_ => None,
|
||||
})
|
||||
.chain(entry.params.iter().filter_map(|p| match &p.value {
|
||||
ArchivedICalendarParameterValue::Text(v) => Some(v.as_str()),
|
||||
ArchivedICalendarParameterValue::Uri(uri) => uri.as_str(),
|
||||
_ => None,
|
||||
}))
|
||||
{
|
||||
document.index_text(
|
||||
field,
|
||||
value.strip_prefix("mailto:").unwrap_or(value),
|
||||
Language::Unknown,
|
||||
);
|
||||
if index_fields.is_empty() || index_fields.contains(&field) {
|
||||
for value in entry
|
||||
.values
|
||||
.iter()
|
||||
.filter_map(|v| match v {
|
||||
ArchivedICalendarValue::Text(v) => Some(v.as_str()),
|
||||
ArchivedICalendarValue::Uri(uri) => uri.as_str(),
|
||||
_ => None,
|
||||
})
|
||||
.chain(entry.params.iter().filter_map(|p| match &p.value {
|
||||
ArchivedICalendarParameterValue::Text(v) => Some(v.as_str()),
|
||||
ArchivedICalendarParameterValue::Uri(uri) => uri.as_str(),
|
||||
_ => None,
|
||||
}))
|
||||
{
|
||||
document.index_text(
|
||||
field.clone(),
|
||||
value.strip_prefix("mailto:").unwrap_or(value),
|
||||
Language::Unknown,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
use super::{AddressBook, ArchivedAddressBook, ArchivedContactCard, ContactCard};
|
||||
use ahash::AHashSet;
|
||||
use calcard::{
|
||||
common::IanaString,
|
||||
vcard::{
|
||||
@@ -15,7 +16,7 @@ use calcard::{
|
||||
use common::storage::index::{IndexValue, IndexableAndSerializableObject, IndexableObject};
|
||||
use nlp::language::Language;
|
||||
use store::{
|
||||
search::{ContactSearchField, IndexDocument},
|
||||
search::{ContactSearchField, IndexDocument, SearchField},
|
||||
write::SearchIndex,
|
||||
xxhash_rust::xxh3,
|
||||
};
|
||||
@@ -242,13 +243,17 @@ impl ArchivedContactCard {
|
||||
}
|
||||
|
||||
impl ArchivedContactCard {
|
||||
pub fn index_document(&self) -> IndexDocument {
|
||||
pub fn index_document(&self, index_fields: &AHashSet<SearchField>) -> IndexDocument {
|
||||
let mut document = IndexDocument::with_default_language(Language::Unknown);
|
||||
|
||||
document.index_integer(ContactSearchField::Created, self.created.to_native());
|
||||
if index_fields.is_empty()
|
||||
|| index_fields.contains(&SearchField::Contact(ContactSearchField::Created))
|
||||
{
|
||||
document.index_integer(ContactSearchField::Created, self.created.to_native());
|
||||
}
|
||||
|
||||
for entry in self.card.entries.iter() {
|
||||
let field = match entry.name {
|
||||
let field = SearchField::Contact(match entry.name {
|
||||
ArchivedVCardProperty::N => ContactSearchField::Name,
|
||||
ArchivedVCardProperty::Nickname => ContactSearchField::Nickname,
|
||||
ArchivedVCardProperty::Org => ContactSearchField::Organization,
|
||||
@@ -263,28 +268,30 @@ impl ArchivedContactCard {
|
||||
ArchivedVCardProperty::Uid => ContactSearchField::Uid,
|
||||
ArchivedVCardProperty::Member => ContactSearchField::Member,
|
||||
_ => continue,
|
||||
};
|
||||
});
|
||||
|
||||
for value in entry.values.iter() {
|
||||
match value {
|
||||
ArchivedVCardValue::Text(v) => {
|
||||
document.index_text(field, v, Language::Unknown);
|
||||
}
|
||||
ArchivedVCardValue::Kind(v) => {
|
||||
document.index_text(field, v.as_str(), Language::Unknown);
|
||||
}
|
||||
ArchivedVCardValue::Component(v) => {
|
||||
for item in v.iter() {
|
||||
document.index_text(field, item, Language::Unknown);
|
||||
if index_fields.is_empty() || index_fields.contains(&field) {
|
||||
for value in entry.values.iter() {
|
||||
match value {
|
||||
ArchivedVCardValue::Text(v) => {
|
||||
document.index_text(field.clone(), v, Language::Unknown);
|
||||
}
|
||||
ArchivedVCardValue::Kind(v) => {
|
||||
document.index_text(field.clone(), v.as_str(), Language::Unknown);
|
||||
}
|
||||
ArchivedVCardValue::Component(v) => {
|
||||
for item in v.iter() {
|
||||
document.index_text(field.clone(), item, Language::Unknown);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
for param in entry.params.iter() {
|
||||
if let ArchivedVCardParameterValue::Text(value) = ¶m.value {
|
||||
document.index_text(field, value, Language::Unknown);
|
||||
for param in entry.params.iter() {
|
||||
if let ArchivedVCardParameterValue::Text(value) = ¶m.value {
|
||||
document.index_text(field.clone(), value, Language::Unknown);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user