Skip to content

Commit 50b9f7e

Browse files
committed
chore: update image placement
1 parent 75e4199 commit 50b9f7e

File tree

2 files changed

+10
-143
lines changed

2 files changed

+10
-143
lines changed

README.md

Lines changed: 7 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ Fuse is a super lightweight library which provides a simple way to do fuzzy sear
1010
Fuse-RS is a port of https://github.com/krisk/fuse-swift written purely in rust.
1111

1212
## Usage
13+
14+
<img src="/.github/Demo.gif" align="right" width="400px"/>
15+
1316
An example of a real use case, a search bar made using [iced](https://github.com/iced-rs/iced) is also available.
1417

1518
Try it using
1619
```shell
1720
cargo run --package search_bar
1821
```
19-
20-
![Demo](/.github/Demo.gif)
21-
22-
2322
> Check all available examples and their source code [here.](/examples/)
2423
24+
2525
### Async
2626
Use the feature flag "async" to also be able to use async functions.
2727
```toml
@@ -41,144 +41,7 @@ Fuse::default() = Fuse{
4141
tokenize: false, // the input search text should be tokenized
4242
}
4343
```
44-
45-
#### Example 1
46-
47-
Simple search.
48-
```shell
49-
cargo run --example simple-search
50-
```
51-
52-
```rust
53-
let fuse = Fuse::default();
54-
let text = "Old Man's War";
55-
let search_text = "od mn war";
56-
57-
let result = fuse.search_text_in_string(search_text, text);
58-
assert_eq!(result, Some(ScoreResult{
59-
score: 0.4444444444444444,
60-
ranges: vec!((0..1), (2..7), (9..13)),
61-
}), "Simple search returned incorrect results");
62-
```
63-
64-
#### Example 2
65-
66-
Search over a string iterable.
67-
```shell
68-
cargo run --example iterable-search
69-
```
70-
71-
```rust
72-
let fuse = Fuse::default();
73-
let books = [
74-
"The Silmarillion",
75-
"The Lock Artist",
76-
"The Lost Symbol"
77-
];
78-
79-
// Improve performance by creating the pattern before hand.
80-
let search_pattern = fuse.create_pattern("Te silm");
81-
82-
let results = fuse.search_text_in_iterable("Te silm", books.iter());
83-
assert_eq!(results, vec!(
84-
SearchResult{
85-
index: 0,
86-
score: 0.14285714285714285,
87-
ranges: vec!((0..1), (2..8), (10..14)),
88-
},
89-
SearchResult{
90-
index: 2,
91-
score: 0.49857142857142855,
92-
ranges: vec!((0..1), (2..5), (6..10), (11..12), (14..15)),
93-
},
94-
SearchResult{
95-
index: 1,
96-
score: 0.5714285714285714,
97-
ranges: vec!((0..1), (2..5), (8..9), (11..15)),
98-
},
99-
), "Iterable search returned incorrect results");
100-
```
101-
102-
#### Example 3
103-
104-
Search over a list of items implementing the Fuseable trait.
105-
106-
```shell
107-
cargo run --example fuseable-search
108-
```
109-
110-
```rust
111-
struct Book<'a> {
112-
title: &'a str,
113-
author: &'a str,
114-
}
115-
116-
impl Fuseable for Book<'_>{
117-
fn properties(&self) -> Vec<FuseProperty> {
118-
return vec!(
119-
FuseProperty{value: String::from("title"), weight: 0.3},
120-
FuseProperty{value: String::from("author"), weight: 0.7},
121-
)
122-
}
123-
124-
fn lookup(&self, key: &str) -> Option<&str> {
125-
return match key {
126-
"title" => Some(self.title),
127-
"author" => Some(self.author),
128-
_ => None
129-
}
130-
}
131-
}
132-
fn main() {
133-
let books = [
134-
Book{author: "John X", title: "Old Man's War fiction"},
135-
Book{author: "P.D. Mans", title: "Right Ho Jeeves"},
136-
];
137-
138-
let fuse = Fuse::default();
139-
let results = fuse.search_text_in_fuse_list("man", &books);
140-
141-
assert_eq!(results, vec!(
142-
FusableSearchResult{
143-
index: 1,
144-
score: 0.015000000000000003,
145-
results: vec!(FResult{
146-
value: String::from("author"),
147-
score: 0.015000000000000003,
148-
ranges: vec!((5..8)),
149-
}),
150-
},
151-
FusableSearchResult{
152-
index: 0,
153-
score: 0.027999999999999997,
154-
results: vec!(FResult{
155-
value: String::from("title"),
156-
score: 0.027999999999999997,
157-
ranges: vec!((4..7)),
158-
})
159-
}
160-
), "Fuseable Search returned incorrect results");
161-
}
162-
```
163-
164-
Furthermore, you can add a chunk size to run this over multiple threads.
165-
166-
Currently, the chunk size is one, so the chunks of size 1 will be run on seperate threads.
167-
```rust
168-
fuse.search_text_in_fuse_list_with_chunk_size("man", &books, 1, |x: FuseableSearchResult| {
169-
dbg!(x);
170-
});
171-
```
172-
173-
#### Example 4
174-
175-
You can look into examples/chunk-search.rs for the source code, and can run the same with:
176-
177-
```shell
178-
cargo run --example chunk-search
179-
```
180-
181-
This searches for a text over a list of 100 items with a chunk size of 10.
44+
For how to implement individual searching operations, check the [examples.](/examples/)
18245

18346
## Options
18447

@@ -189,3 +52,5 @@ As given above, Fuse takes the following options
18952
- `threshold`: At what point does the match algorithm give up. A threshold of `0.0` requires a perfect match (of both letters and location), a threshold of `1.0` would match anything. Defaults to `0.6`
19053
- `maxPatternLength`: The maximum valid pattern length. The longer the pattern, the more intensive the search operation will be. If the pattern exceeds the `maxPatternLength`, the `search` operation will return `nil`. Why is this important? [Read this](https://en.wikipedia.org/wiki/Word_(computer_architecture)#Word_size_choice). Defaults to `32`
19154
- `isCaseSensitive`: Indicates whether comparisons should be case sensitive. Defaults to `false`
55+
56+
<br clear="right"/>

examples/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Search Bar
44

5+
<img src="/.github/Demo.gif" align="right" width="400px"/>
6+
57
Demo made using [iced-rs](https://github.com/iced-rs/iced).
68

79
You can run this example locally by running
@@ -10,7 +12,7 @@ You can run this example locally by running
1012
cargo run --package search_bar
1113
```
1214

13-
![Demo](/.github/Demo.gif)
15+
<br clear="right"/>
1416

1517
#### Simple search
1618

0 commit comments

Comments
 (0)