Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic occurs when search with + and - query #457

Closed
Leonqn opened this issue Dec 17, 2018 · 5 comments
Closed

Panic occurs when search with + and - query #457

Leonqn opened this issue Dec 17, 2018 · 5 comments

Comments

@Leonqn
Copy link

Leonqn commented Dec 17, 2018

Describe the bug
Code below panics with thread 'main' panicked at 'assertion failed: target >= self.doc()', but if you run this code with range 0..193 there will be no panic.

Which version of tantivy are you using?
0.7.1

To Reproduce

use tantivy::Index;
use tantivy::schema::*;
use tantivy::collector::TopCollector;
use tantivy::query::QueryParser;

pub fn main() {
    let mut schema_builder = SchemaBuilder::new();
    let test_field = schema_builder.add_text_field("test", STRING);
    let index = Index::create_in_ram(schema_builder.build());

    let mut index_writer = index.writer(3000000).unwrap();

    for i in 0..194 {
        let mut doc = Document::new();
        if i % 3 == 0 {
            doc.add_text(test_field, "f");
        } else {
            doc.add_text(test_field, "m");
        }

        index_writer.add_document(doc);
    }
    index_writer.commit().unwrap();

    index.load_searchers().unwrap();

    let searcher = index.searcher();

    let query_parser = QueryParser::for_index(&index, vec![test_field]);
    let query = query_parser.parse_query("-m +f").unwrap();

    let mut collector = TopCollector::with_limit(1);
    searcher.search(&*query, &mut collector).unwrap();

    println!("{}", collector.docs().len())
}
@fulmicoton fulmicoton added the bug label Dec 17, 2018
@fulmicoton
Copy link
Collaborator

fulmicoton commented Dec 17, 2018

Thank you for the great bug report. (That sounds terrible though) @Leonqn

I'll have a look as soon as possible and publish a fix as a 0.7.2

@fulmicoton
Copy link
Collaborator

I confirm I can reproduce. The bug is in the TermScorer itself.

@fulmicoton
Copy link
Collaborator

I'll publish the fix today

@fulmicoton
Copy link
Collaborator

This bug happens "fairly often".

If you have a product running with tantivy in release without debug_assert, no sweat, the result are actually correct. The debug_assert itself is not useful anymore.

@fulmicoton
Copy link
Collaborator

Published fix in tantivy 0.7.2. Yanking tantivy 0.7.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants