mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-04 16:22:55 +00:00
cleaning up imports
This commit is contained in:
@@ -2,54 +2,14 @@ extern crate tantivy;
|
||||
extern crate regex;
|
||||
extern crate tempdir;
|
||||
|
||||
use tantivy::core::postings::VecPostings;
|
||||
use tantivy::core::postings::Postings;
|
||||
use tantivy::core::analyzer::SimpleTokenizer;
|
||||
use tantivy::core::collector::TestCollector;
|
||||
use tantivy::core::serial::*;
|
||||
use tantivy::core::schema::*;
|
||||
use tantivy::core::codec::SimpleCodec;
|
||||
use tantivy::core::global::*;
|
||||
use tantivy::core::postings::IntersectionPostings;
|
||||
use tantivy::core::writer::IndexWriter;
|
||||
use tantivy::core::searcher::Searcher;
|
||||
use tantivy::core::directory::{Directory, generate_segment_name, SegmentId};
|
||||
use std::ops::DerefMut;
|
||||
use tantivy::core::reader::SegmentReader;
|
||||
use std::io::{ BufWriter, Write};
|
||||
use regex::Regex;
|
||||
use std::convert::From;
|
||||
use std::path::PathBuf;
|
||||
use tantivy::core::query;
|
||||
use tantivy::core::query::parse_query;
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_parse_query() {
|
||||
{
|
||||
let (parsed_query, _) = parse_query("toto:titi toto:tutu").unwrap();
|
||||
assert_eq!(parsed_query, vec!(query::Term(String::from("toto"), String::from("titi")), query::Term(String::from("toto"), String::from("tutu"))));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_intersection() {
|
||||
{
|
||||
let left = VecPostings::new(vec!(1, 3, 9));
|
||||
let right = VecPostings::new(vec!(3, 4, 9, 18));
|
||||
let inter = IntersectionPostings::from_postings(vec!(left, right));
|
||||
let vals: Vec<DocId> = inter.collect();
|
||||
assert_eq!(vals, vec!(3, 9));
|
||||
}
|
||||
{
|
||||
let a = VecPostings::new(vec!(1, 3, 9));
|
||||
let b = VecPostings::new(vec!(3, 4, 9, 18));
|
||||
let c = VecPostings::new(vec!(1, 5, 9, 111));
|
||||
let inter = IntersectionPostings::from_postings(vec!(a, b, c));
|
||||
let vals: Vec<DocId> = inter.collect();
|
||||
assert_eq!(vals, vec!(9));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
@@ -85,7 +45,7 @@ fn test_indexing() {
|
||||
let commit_result = index_writer.commit();
|
||||
assert!(commit_result.is_ok());
|
||||
let segment = commit_result.unwrap();
|
||||
let segment_reader = SegmentReader::open(segment).unwrap();
|
||||
SegmentReader::open(segment).unwrap();
|
||||
// TODO ENABLE TEST
|
||||
//let segment_str_after_reading = DebugSegmentSerializer::debug_string(&segment_reader);
|
||||
//assert_eq!(segment_str_before_writing, segment_str_after_reading);
|
||||
@@ -134,8 +94,6 @@ fn test_searcher() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_new_segment() {
|
||||
let SegmentId(segment_name) = generate_segment_name();
|
||||
|
||||
138
tests/skip.rs
138
tests/skip.rs
@@ -1,138 +0,0 @@
|
||||
extern crate tantivy;
|
||||
extern crate byteorder;
|
||||
use std::io::{Write, Seek};
|
||||
use std::io::SeekFrom;
|
||||
use tantivy::core::skip::*;
|
||||
use std::io::Cursor;
|
||||
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
|
||||
|
||||
#[test]
|
||||
fn test_skip_list_builder() {
|
||||
{
|
||||
let mut output: Vec<u8> = Vec::new();
|
||||
let mut skip_list_builder: SkipListBuilder<u32> = SkipListBuilder::new(10);
|
||||
skip_list_builder.insert(2, &3);
|
||||
skip_list_builder.write::<Vec<u8>>(&mut output);
|
||||
assert_eq!(output.len(), 16);
|
||||
assert_eq!(output[0], 0);
|
||||
}
|
||||
{
|
||||
let mut output: Vec<u8> = Vec::new();
|
||||
let mut skip_list_builder: SkipListBuilder<u32> = SkipListBuilder::new(3);
|
||||
for i in (0..9) {
|
||||
skip_list_builder.insert(i, &i);
|
||||
}
|
||||
skip_list_builder.write::<Vec<u8>>(&mut output);
|
||||
assert_eq!(output.len(), 120);
|
||||
assert_eq!(output[0], 0);
|
||||
}
|
||||
{
|
||||
// checking that void gets serialized to nothing.
|
||||
let mut output: Vec<u8> = Vec::new();
|
||||
let mut skip_list_builder: SkipListBuilder<()> = SkipListBuilder::new(3);
|
||||
for i in (0..9) {
|
||||
skip_list_builder.insert(i, &());
|
||||
}
|
||||
skip_list_builder.write::<Vec<u8>>(&mut output);
|
||||
assert_eq!(output.len(), 84);
|
||||
assert_eq!(output[0], 0);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_skip_list_reader() {
|
||||
{
|
||||
let mut output: Vec<u8> = Vec::new();
|
||||
let mut skip_list_builder: SkipListBuilder<u32> = SkipListBuilder::new(10);
|
||||
skip_list_builder.insert(2, &3);
|
||||
skip_list_builder.write::<Vec<u8>>(&mut output);
|
||||
let mut skip_list: SkipList<u32> = SkipList::read(&mut output);
|
||||
assert_eq!(skip_list.next(), Some((2, 3)));
|
||||
}
|
||||
{
|
||||
let mut output: Vec<u8> = Vec::new();
|
||||
let mut skip_list_builder: SkipListBuilder<u32> = SkipListBuilder::new(10);
|
||||
skip_list_builder.write::<Vec<u8>>(&mut output);
|
||||
let mut skip_list: SkipList<u32> = SkipList::read(&mut output);
|
||||
assert_eq!(skip_list.next(), None);
|
||||
}
|
||||
{
|
||||
let mut output: Vec<u8> = Vec::new();
|
||||
let mut skip_list_builder: SkipListBuilder<()> = SkipListBuilder::new(2);
|
||||
skip_list_builder.insert(2, &());
|
||||
skip_list_builder.insert(3, &());
|
||||
skip_list_builder.insert(5, &());
|
||||
skip_list_builder.insert(7, &());
|
||||
skip_list_builder.insert(9, &());
|
||||
skip_list_builder.write::<Vec<u8>>(&mut output);
|
||||
let mut skip_list: SkipList<()> = SkipList::read(&mut output);
|
||||
assert_eq!(skip_list.next().unwrap(), (2, ()));
|
||||
assert_eq!(skip_list.next().unwrap(), (3, ()));
|
||||
assert_eq!(skip_list.next().unwrap(), (5, ()));
|
||||
assert_eq!(skip_list.next().unwrap(), (7, ()));
|
||||
assert_eq!(skip_list.next().unwrap(), (9, ()));
|
||||
assert_eq!(skip_list.next(), None);
|
||||
}
|
||||
{
|
||||
let mut output: Vec<u8> = Vec::new();
|
||||
let mut skip_list_builder: SkipListBuilder<()> = SkipListBuilder::new(2);
|
||||
skip_list_builder.insert(2, &());
|
||||
skip_list_builder.insert(3, &());
|
||||
skip_list_builder.insert(5, &());
|
||||
skip_list_builder.insert(7, &());
|
||||
skip_list_builder.insert(9, &());
|
||||
skip_list_builder.write::<Vec<u8>>(&mut output);
|
||||
let mut skip_list: SkipList<()> = SkipList::read(&mut output);
|
||||
assert_eq!(skip_list.next().unwrap(), (2, ()));
|
||||
skip_list.seek(5);
|
||||
assert_eq!(skip_list.next().unwrap(), (5, ()));
|
||||
assert_eq!(skip_list.next().unwrap(), (7, ()));
|
||||
assert_eq!(skip_list.next().unwrap(), (9, ()));
|
||||
assert_eq!(skip_list.next(), None);
|
||||
}
|
||||
{
|
||||
let mut output: Vec<u8> = Vec::new();
|
||||
let mut skip_list_builder: SkipListBuilder<()> = SkipListBuilder::new(3);
|
||||
skip_list_builder.insert(2, &());
|
||||
skip_list_builder.insert(3, &());
|
||||
skip_list_builder.insert(5, &());
|
||||
skip_list_builder.insert(6, &());
|
||||
skip_list_builder.write::<Vec<u8>>(&mut output);
|
||||
let mut skip_list: SkipList<()> = SkipList::read(&mut output);
|
||||
assert_eq!(skip_list.next().unwrap(), (2, ()));
|
||||
skip_list.seek(6);
|
||||
assert_eq!(skip_list.next().unwrap(), (6, ()));
|
||||
assert_eq!(skip_list.next(), None);
|
||||
|
||||
}
|
||||
{
|
||||
let mut output: Vec<u8> = Vec::new();
|
||||
let mut skip_list_builder: SkipListBuilder<()> = SkipListBuilder::new(2);
|
||||
skip_list_builder.insert(2, &());
|
||||
skip_list_builder.insert(3, &());
|
||||
skip_list_builder.insert(5, &());
|
||||
skip_list_builder.insert(7, &());
|
||||
skip_list_builder.insert(9, &());
|
||||
skip_list_builder.write::<Vec<u8>>(&mut output);
|
||||
let mut skip_list: SkipList<()> = SkipList::read(&mut output);
|
||||
assert_eq!(skip_list.next().unwrap(), (2, ()));
|
||||
skip_list.seek(10);
|
||||
assert_eq!(skip_list.next(), None);
|
||||
}
|
||||
{
|
||||
let mut output: Vec<u8> = Vec::new();
|
||||
let mut skip_list_builder: SkipListBuilder<()> = SkipListBuilder::new(3);
|
||||
for i in (0..1000) {
|
||||
skip_list_builder.insert(i, &());
|
||||
}
|
||||
skip_list_builder.insert(1004, &());
|
||||
skip_list_builder.write::<Vec<u8>>(&mut output);
|
||||
let mut skip_list: SkipList<()> = SkipList::read(&mut output);
|
||||
assert_eq!(skip_list.next().unwrap(), (0, ()));
|
||||
skip_list.seek(431);
|
||||
assert_eq!(skip_list.next().unwrap(), (431,()) );
|
||||
skip_list.seek(1003);
|
||||
assert_eq!(skip_list.next().unwrap(), (1004,()) );
|
||||
assert_eq!(skip_list.next(), None);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user