11use tantivy:: collector:: { Count , TopDocs } ;
22use tantivy:: query:: {
3- BooleanQuery , BoostQuery , FuzzyTermQuery , MoreLikeThisQuery , Occur , PhraseQuery , Query ,
4- QueryParser , TermQuery ,
3+ BooleanQuery , BoostQuery , FuzzyTermQuery , Occur , PhraseQuery , Query , QueryParser , TermQuery ,
54} ;
65use tantivy:: schema:: { Facet , IndexRecordOption } ;
76use tantivy:: snippet:: SnippetGenerator ;
@@ -12,8 +11,8 @@ use crate::query::build_created_at_range_query;
1211use crate :: schema:: { extract_search_document, get_fields} ;
1312use crate :: tokenizer:: register_tokenizers;
1413use crate :: {
15- CollectionConfig , CollectionIndex , HighlightRange , IndexState , MoreLikeThisRequest ,
16- SearchDocument , SearchHit , SearchRequest , SearchResult , Snippet ,
14+ CollectionConfig , CollectionIndex , HighlightRange , IndexState , SearchDocument , SearchHit ,
15+ SearchRequest , SearchResult , Snippet ,
1716} ;
1817
1918pub fn detect_language ( text : & str ) -> hypr_language:: Language {
@@ -502,93 +501,6 @@ impl<'a, R: tauri::Runtime, M: tauri::Manager<R>> Tantivy<'a, R, M> {
502501
503502 Ok ( ( ) )
504503 }
505-
506- pub async fn more_like_this (
507- & self ,
508- request : MoreLikeThisRequest ,
509- ) -> Result < SearchResult , crate :: Error > {
510- let collection_name = Self :: get_collection_name ( request. collection ) ;
511- let state = self . manager . state :: < IndexState > ( ) ;
512- let guard = state. inner . lock ( ) . await ;
513-
514- let collection_index = guard
515- . collections
516- . get ( & collection_name)
517- . ok_or_else ( || crate :: Error :: CollectionNotFound ( collection_name. clone ( ) ) ) ?;
518-
519- let schema = & collection_index. schema ;
520- let reader = & collection_index. reader ;
521-
522- let fields = get_fields ( schema) ;
523- let searcher = reader. searcher ( ) ;
524-
525- let id_term = Term :: from_field_text ( fields. id , & request. document_id ) ;
526- let id_query = TermQuery :: new ( id_term, IndexRecordOption :: Basic ) ;
527-
528- let ( top_docs, _) = searcher. search ( & id_query, & ( TopDocs :: with_limit ( 1 ) , Count ) ) ?;
529-
530- let ( _, doc_address) = top_docs
531- . first ( )
532- . ok_or_else ( || crate :: Error :: DocumentNotFound ( request. document_id . clone ( ) ) ) ?;
533-
534- let mut mlt_builder = MoreLikeThisQuery :: builder ( ) ;
535-
536- if let Some ( min_doc_freq) = request. options . min_doc_frequency {
537- mlt_builder = mlt_builder. with_min_doc_frequency ( min_doc_freq) ;
538- }
539- if let Some ( max_doc_freq) = request. options . max_doc_frequency {
540- mlt_builder = mlt_builder. with_max_doc_frequency ( max_doc_freq) ;
541- }
542- if let Some ( min_term_freq) = request. options . min_term_frequency {
543- mlt_builder = mlt_builder. with_min_term_frequency ( min_term_freq) ;
544- }
545- if let Some ( min_word_len) = request. options . min_word_length {
546- mlt_builder = mlt_builder. with_min_word_length ( min_word_len) ;
547- }
548- if let Some ( max_word_len) = request. options . max_word_length {
549- mlt_builder = mlt_builder. with_max_word_length ( max_word_len) ;
550- }
551- if let Some ( boost) = request. options . boost_factor {
552- mlt_builder = mlt_builder. with_boost_factor ( boost) ;
553- }
554- if let Some ( ref stop_words) = request. options . stop_words {
555- mlt_builder = mlt_builder. with_stop_words ( stop_words. clone ( ) ) ;
556- }
557-
558- let mlt_query = mlt_builder. with_document ( * doc_address) ;
559-
560- let ( similar_docs, count) =
561- searcher. search ( & mlt_query, & ( TopDocs :: with_limit ( request. limit + 1 ) , Count ) ) ?;
562-
563- let mut hits = Vec :: new ( ) ;
564- for ( score, similar_doc_address) in similar_docs {
565- if similar_doc_address == * doc_address {
566- continue ;
567- }
568-
569- let retrieved_doc: TantivyDocument = searcher. doc ( similar_doc_address) ?;
570-
571- if let Some ( search_doc) = extract_search_document ( schema, & fields, & retrieved_doc) {
572- hits. push ( SearchHit {
573- score,
574- document : search_doc,
575- title_snippet : None ,
576- content_snippet : None ,
577- } ) ;
578- }
579-
580- if hits. len ( ) >= request. limit {
581- break ;
582- }
583- }
584-
585- let actual_count = if count > 0 { count - 1 } else { 0 } ;
586-
587- Ok ( SearchResult {
588- hits,
589- count : actual_count,
590- } )
591- }
592504}
593505
594506pub trait TantivyPluginExt < R : tauri:: Runtime > {
0 commit comments