You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use tantivy::collector::FacetCollector;use tantivy::query::{BooleanQuery,Occur,Query,TermQuery};use tantivy::schema::*;use tantivy::{doc,Index,IndexWriter};fnmain() -> tantivy::Result<()>{letmut schema_builder = Schema::builder();let id = schema_builder.add_text_field("id",TEXT | STORED);let title = schema_builder.add_text_field("title",TEXT | STORED);let category = schema_builder.add_facet_field("category",FacetOptions::default());let schema = schema_builder.build();let index = Index::create_in_ram(schema);letmut index_writer:IndexWriter = index.writer(30_000_000)?;
index_writer.add_document(doc!(
id => "1",
title => "The Quantum Paradox",
category => Facet::from("/science-fiction/space")))?;
index_writer.add_document(doc!(
id => "2",
title => "The Alien Invasion",
category => Facet::from("/science-fiction/alien-invasion")))?;
index_writer.add_document(doc!(
id => "3",
title => "Terraforming Mars",
category => Facet::from("/science-fiction/space-colonization")))?;
index_writer.add_document(doc!(
id => "4",
title => "The Dragon's Oath",
category => Facet::from("/fantasy/epic-fantasy")))?;
index_writer.add_document(doc!(
id => "5",
title => "The Forgotten Kingdom",
category => Facet::from("/fantasy/epic-fantasy/martin")))?;
index_writer.add_document(doc!(
id => "6",
title => "The Last Elf",
category => Facet::from("/fantasy/epic-fantasy/tolkien")))?;
index_writer.add_document(doc!(
id => "7",
title => "Cybernetic Rebellion",
category => Facet::from("/science-fiction/cyberpunk")))?;
index_writer.commit()?;let reader = index.reader()?;let searcher = reader.searcher();letmut facet_collector = FacetCollector::for_field("category");
facet_collector.add_facet("/fantasy/epic-fantasy");let facet = Facet::from("/fantasy/epic-fantasy");let facet_term = Term::from_facet(category,&facet);let occur = Occur::Must;let query:Box<dynQuery> = Box::new(TermQuery::new(facet_term,IndexRecordOption::Basic));letmut sub_queries:Vec<(Occur,Box<dynQuery>)> = vec![];
sub_queries.push((occur, query));let facet_term_query = BooleanQuery::new(sub_queries);let facet_counts = searcher.search(&facet_term_query,&facet_collector)?;let counts:Vec<(&Facet,u64)> = facet_counts.get("/").collect();println!("{:?}", counts);Ok(())}
if you run main you should see the same weird behavior that I am seeing, [(Facet(/fantasy/epic-fantasy/martin), 1), (Facet(/fantasy/epic-fantasy/tolkien), 1), (Facet(/science-fiction), 1)]
The text was updated successfully, but these errors were encountered:
As reported in discord:
if you run main you should see the same weird behavior that I am seeing, [(Facet(/fantasy/epic-fantasy/martin), 1), (Facet(/fantasy/epic-fantasy/tolkien), 1), (Facet(/science-fiction), 1)]
The text was updated successfully, but these errors were encountered: