Skip to content

Commit 2632904

Browse files
committed
trying to rationalize order
1 parent d56d8e3 commit 2632904

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+563
-468
lines changed

benches/and_or_queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl BenchIndex {
4444
fn topk_len(&self, query_str: &str, k: usize) -> usize {
4545
let query = self.query_parser.parse_query(query_str).unwrap();
4646
self.searcher
47-
.search(&query, &TopDocs::with_limit(k))
47+
.search(&query, &TopDocs::with_limit(k).order_by_score())
4848
.unwrap()
4949
.len()
5050
}

examples/basic_search.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ fn main() -> tantivy::Result<()> {
208208
// is the role of the `TopDocs` collector.
209209

210210
// We can now perform our query.
211-
let top_docs = searcher.search(&query, &TopDocs::with_limit(10))?;
211+
let top_docs = searcher.search(&query, &TopDocs::with_limit(10).order_by_score())?;
212212

213213
// The actual documents still need to be
214214
// retrieved from Tantivy's store.
@@ -226,7 +226,7 @@ fn main() -> tantivy::Result<()> {
226226
let query = query_parser.parse_query("title:sea^20 body:whale^70")?;
227227

228228
let (_score, doc_address) = searcher
229-
.search(&query, &TopDocs::with_limit(1))?
229+
.search(&query, &TopDocs::with_limit(1).order_by_score())?
230230
.into_iter()
231231
.next()
232232
.unwrap();

examples/custom_tokenizer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn main() -> tantivy::Result<()> {
100100
// here we want to get a hit on the 'ken' in Frankenstein
101101
let query = query_parser.parse_query("ken")?;
102102

103-
let top_docs = searcher.search(&query, &TopDocs::with_limit(10))?;
103+
let top_docs = searcher.search(&query, &TopDocs::with_limit(10).order_by_score())?;
104104

105105
for (_, doc_address) in top_docs {
106106
let retrieved_doc: TantivyDocument = searcher.doc(doc_address)?;

examples/date_time_field.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ fn main() -> tantivy::Result<()> {
5050
{
5151
// Simple exact search on the date
5252
let query = query_parser.parse_query("occurred_at:\"2022-06-22T12:53:50.53Z\"")?;
53-
let count_docs = searcher.search(&*query, &TopDocs::with_limit(5))?;
53+
let count_docs = searcher.search(&*query, &TopDocs::with_limit(5).order_by_score())?;
5454
assert_eq!(count_docs.len(), 1);
5555
}
5656
{
5757
// Range query on the date field
5858
let query = query_parser
5959
.parse_query(r#"occurred_at:[2022-06-22T12:58:00Z TO 2022-06-23T00:00:00Z}"#)?;
60-
let count_docs = searcher.search(&*query, &TopDocs::with_limit(4))?;
60+
let count_docs = searcher.search(&*query, &TopDocs::with_limit(4).order_by_score())?;
6161
assert_eq!(count_docs.len(), 1);
6262
for (_score, doc_address) in count_docs {
6363
let retrieved_doc = searcher.doc::<TantivyDocument>(doc_address)?;

examples/deleting_updating_documents.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn extract_doc_given_isbn(
2828
// The second argument is here to tell we don't care about decoding positions,
2929
// or term frequencies.
3030
let term_query = TermQuery::new(isbn_term.clone(), IndexRecordOption::Basic);
31-
let top_docs = searcher.search(&term_query, &TopDocs::with_limit(1))?;
31+
let top_docs = searcher.search(&term_query, &TopDocs::with_limit(1).order_by_score())?;
3232

3333
if let Some((_score, doc_address)) = top_docs.first() {
3434
let doc = searcher.doc(*doc_address)?;

examples/fuzzy_search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn main() -> tantivy::Result<()> {
146146
let query = FuzzyTermQuery::new(term, 2, true);
147147

148148
let (top_docs, count) = searcher
149-
.search(&query, &(TopDocs::with_limit(5), Count))
149+
.search(&query, &(TopDocs::with_limit(5).order_by_score(), Count))
150150
.unwrap();
151151
assert_eq!(count, 3);
152152
assert_eq!(top_docs.len(), 3);

examples/ip_field.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,25 @@ fn main() -> tantivy::Result<()> {
6969
{
7070
// Inclusive range queries
7171
let query = query_parser.parse_query("ip:[192.168.0.80 TO 192.168.0.100]")?;
72-
let count_docs = searcher.search(&*query, &TopDocs::with_limit(5))?;
72+
let count_docs = searcher.search(&*query, &TopDocs::with_limit(5).order_by_score())?;
7373
assert_eq!(count_docs.len(), 1);
7474
}
7575
{
7676
// Exclusive range queries
7777
let query = query_parser.parse_query("ip:{192.168.0.80 TO 192.168.1.100]")?;
78-
let count_docs = searcher.search(&*query, &TopDocs::with_limit(2))?;
78+
let count_docs = searcher.search(&*query, &TopDocs::with_limit(2).order_by_score())?;
7979
assert_eq!(count_docs.len(), 0);
8080
}
8181
{
8282
// Find docs with IP addresses smaller equal 192.168.1.100
8383
let query = query_parser.parse_query("ip:[* TO 192.168.1.100]")?;
84-
let count_docs = searcher.search(&*query, &TopDocs::with_limit(2))?;
84+
let count_docs = searcher.search(&*query, &TopDocs::with_limit(2).order_by_score())?;
8585
assert_eq!(count_docs.len(), 2);
8686
}
8787
{
8888
// Find docs with IP addresses smaller than 192.168.1.100
8989
let query = query_parser.parse_query("ip:[* TO 192.168.1.100}")?;
90-
let count_docs = searcher.search(&*query, &TopDocs::with_limit(2))?;
90+
let count_docs = searcher.search(&*query, &TopDocs::with_limit(2).order_by_score())?;
9191
assert_eq!(count_docs.len(), 2);
9292
}
9393

examples/json_field.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ fn main() -> tantivy::Result<()> {
5959
let query_parser = QueryParser::for_index(&index, vec![event_type, attributes]);
6060
{
6161
let query = query_parser.parse_query("target:submit-button")?;
62-
let count_docs = searcher.search(&*query, &TopDocs::with_limit(2))?;
62+
let count_docs = searcher.search(&*query, &TopDocs::with_limit(2).order_by_score())?;
6363
assert_eq!(count_docs.len(), 2);
6464
}
6565
{
6666
let query = query_parser.parse_query("target:submit")?;
67-
let count_docs = searcher.search(&*query, &TopDocs::with_limit(2))?;
67+
let count_docs = searcher.search(&*query, &TopDocs::with_limit(2).order_by_score())?;
6868
assert_eq!(count_docs.len(), 2);
6969
}
7070
{
@@ -74,33 +74,33 @@ fn main() -> tantivy::Result<()> {
7474
}
7575
{
7676
let query = query_parser.parse_query("click AND cart.product_id:133")?;
77-
let hits = searcher.search(&*query, &TopDocs::with_limit(2))?;
77+
let hits = searcher.search(&*query, &TopDocs::with_limit(2).order_by_score())?;
7878
assert_eq!(hits.len(), 1);
7979
}
8080
{
8181
// The sub-fields in the json field marked as default field still need to be explicitly
8282
// addressed
8383
let query = query_parser.parse_query("click AND 133")?;
84-
let hits = searcher.search(&*query, &TopDocs::with_limit(2))?;
84+
let hits = searcher.search(&*query, &TopDocs::with_limit(2).order_by_score())?;
8585
assert_eq!(hits.len(), 0);
8686
}
8787
{
8888
// Default json fields are ignored if they collide with the schema
8989
let query = query_parser.parse_query("event_type:holiday-sale")?;
90-
let hits = searcher.search(&*query, &TopDocs::with_limit(2))?;
90+
let hits = searcher.search(&*query, &TopDocs::with_limit(2).order_by_score())?;
9191
assert_eq!(hits.len(), 0);
9292
}
9393
// # Query via full attribute path
9494
{
9595
// This only searches in our schema's `event_type` field
9696
let query = query_parser.parse_query("event_type:click")?;
97-
let hits = searcher.search(&*query, &TopDocs::with_limit(2))?;
97+
let hits = searcher.search(&*query, &TopDocs::with_limit(2).order_by_score())?;
9898
assert_eq!(hits.len(), 2);
9999
}
100100
{
101101
// Default json fields can still be accessed by full path
102102
let query = query_parser.parse_query("attributes.event_type:holiday-sale")?;
103-
let hits = searcher.search(&*query, &TopDocs::with_limit(2))?;
103+
let hits = searcher.search(&*query, &TopDocs::with_limit(2).order_by_score())?;
104104
assert_eq!(hits.len(), 1);
105105
}
106106
Ok(())

examples/phrase_prefix_search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn main() -> Result<()> {
6363
// but not "in the Gulf Stream".
6464
let query = query_parser.parse_query("\"in the su\"*")?;
6565

66-
let top_docs = searcher.search(&query, &TopDocs::with_limit(10))?;
66+
let top_docs = searcher.search(&query, &TopDocs::with_limit(10).order_by_score())?;
6767
let mut titles = top_docs
6868
.into_iter()
6969
.map(|(_score, doc_address)| {

examples/pre_tokenized_text.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ fn main() -> tantivy::Result<()> {
107107
IndexRecordOption::Basic,
108108
);
109109

110-
let (top_docs, count) = searcher.search(&query, &(TopDocs::with_limit(2), Count))?;
110+
let (top_docs, count) =
111+
searcher.search(&query, &(TopDocs::with_limit(2).order_by_score(), Count))?;
111112

112113
assert_eq!(count, 2);
113114

@@ -128,7 +129,8 @@ fn main() -> tantivy::Result<()> {
128129
IndexRecordOption::Basic,
129130
);
130131

131-
let (_top_docs, count) = searcher.search(&query, &(TopDocs::with_limit(2), Count))?;
132+
let (_top_docs, count) =
133+
searcher.search(&query, &(TopDocs::with_limit(2).order_by_score(), Count))?;
132134

133135
assert_eq!(count, 0);
134136

0 commit comments

Comments
 (0)