Repository: TabbyML/tabby
File: crates/tabby-common/src/index/mod.rs (Rust)

Code before:

    /// Build a query to check if the document has specific attribute field.
    pub fn doc_has_attribute_field(&self, corpus: &str, doc_id: &str, field: &str) -> impl Query {
        let doc_id_query = TermQuery::new(
            Term::from_field_text(self.field_id, doc_id),
            tantivy::schema::IndexRecordOption::Basic,
        );

        BooleanQuery::new(vec![
            // Must match the corpus
            (Occur::Must, self.corpus_query(corpus)),
            // Must match the doc id
            (Occur::Must, Box::new(doc_id_query)),
            // Must has the failed_chunks_count field
            (
                Occur::Must,
                Box::new(ExistsQuery::new_exists_query(format!(
                    "{}.{}",
                    FIELD_ATTRIBUTES, field
                ))),
            ),
            // Exclude chunk documents
            (
                Occur::MustNot,
                Box::new(ExistsQuery::new_exists_query(FIELD_CHUNK_ID.into())),
            ),
        ])
    }

    /// Build a query to find the document with the given `doc_id`, include chunks.
    pub fn doc_query_with_chunks(&self, corpus: &str, doc_id: &str) -> impl Query {
        let doc_id_query = TermQuery::new(
            Term::from_field_text(self.field_id, doc_id),
            tantivy::schema::IndexRecordOption::Basic,
        );

        BooleanQuery::new(vec![
            // Must match the corpus
            (Occur::Must, self.corpus_query(corpus)),
            // Must match the doc id
            (Occur::Must, Box::new(doc_id_query)),
        ])
    }

    pub fn corpus_query(&self, corpus: &str) -> Box<dyn Query> {
        Box::new(TermQuery::new(
            Term::from_field_text(self.field_corpus, corpus),
            tantivy::schema::IndexRecordOption::Basic,
        ))
    }


Review comment (suggestion):
```suggestion
```

Not necessary, since `field_attributes` only presents in document.

Code after:
    }

    /// Build a query to check if the document has specific attribute field.
    pub fn doc_has_attribute_field(&self, corpus: &str, doc_id: &str, field: &str) -> impl Query {
        let doc_id_query = TermQuery::new(
            Term::from_field_text(self.field_id, doc_id),
            tantivy::schema::IndexRecordOption::Basic,
        );

        BooleanQuery::new(vec![
            // Must match the corpus
            (Occur::Must, self.corpus_query(corpus)),
            // Must match the doc id
            (Occur::Must, Box::new(doc_id_query)),
            // Must has the attributes.field field
            (
                Occur::Must,
                Box::new(ExistsQuery::new_exists_query(format!(
                    "{}.{}",
                    FIELD_ATTRIBUTES, field
                ))),
            ),
        ])
    }

    /// Build a query to find the document with the given `doc_id`, include chunks.
    pub fn doc_query_with_chunks(&self, corpus: &str, doc_id: &str) -> impl Query {
        let doc_id_query = TermQuery::new(
            Term::from_field_text(self.field_id, doc_id),
            tantivy::schema::IndexRecordOption::Basic,
        );

        BooleanQuery::new(vec![
            // Must match the corpus
            (Occur::Must, self.corpus_query(corpus)),
            // Must match the doc id
            (Occur::Must, Box::new(doc_id_query)),
        ])
    }

    pub fn corpus_query(&self, corpus: &str) -> Box<dyn Query> {
        Box::new(TermQuery::new(
            Term::from_field_text(self.field_corpus, corpus),
            tantivy::schema::IndexRecordOption::Basic,
        ))
    }

    pub fn source_ids_query(&self, source_ids: &[String]) -> impl Query {
        BooleanQuery::new(
            source_ids
                .iter()