Skip to content

Commit

Permalink
refactor: reorganize search widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
Sivan22 committed Jan 29, 2025
1 parent 15d6d05 commit eeca041
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 94 deletions.
2 changes: 1 addition & 1 deletion lib/data/data_providers/tantivy_data_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class TantivyDataProvider {
}
}
if (!fuzzy) {
query = distance > 0 ? '"$query"~$distance' : '"$query"';
query = distance > 0 ? '*"$query"~$distance' : '"$query"';
}
return await index.search(
query: query, facets: facets, limit: limit, fuzzy: fuzzy, order: order);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_spinbox/flutter_spinbox.dart';
import 'package:otzaria/models/tabs/searching_tab.dart';
import 'package:otzaria/screens/full_text_search/tantivy_search_results.dart';
import 'package:search_engine/search_engine.dart';
import 'package:toggle_switch/toggle_switch.dart';

class FullTextSettingsScreen extends StatelessWidget {
const FullTextSettingsScreen({
Key? key,
required this.tab,
}) : super(key: key);
final SearchingTab tab;

@override
Widget build(BuildContext context) {
return Column(mainAxisSize: MainAxisSize.min, children: [
Row(children: [
Expanded(
child: NumOfResults(tab: tab),
),
Expanded(
child: FuzzyDistance(tab: tab),
),
]),
Center(
child: FuzzyToggle(tab: tab),
),
Expanded(child: Container())
]);
}
}

class FuzzyToggle extends StatelessWidget {
const FuzzyToggle({
super.key,
Expand All @@ -42,17 +18,21 @@ class FuzzyToggle extends StatelessWidget {
return ValueListenableBuilder(
valueListenable: tab.fuzzy,
builder: (context, aproximateSearch, child) {
return ToggleSwitch(
minWidth: 150,
inactiveBgColor: Colors.grey,
inactiveFgColor: Colors.white,
initialLabelIndex: aproximateSearch ? 1 : 0,
totalSwitches: 2,
labels: const ['חיפוש מדוייק', 'חיפוש מקורב'],
radiusStyle: true,
onToggle: (index) {
tab.fuzzy.value = index != 0;
},
return Padding(
padding: const EdgeInsets.all(8.0),
child: ToggleSwitch(
minWidth: 150,
minHeight: 45,
inactiveBgColor: Colors.grey,
inactiveFgColor: Colors.white,
initialLabelIndex: aproximateSearch ? 1 : 0,
totalSwitches: 2,
labels: const ['חיפוש מדוייק', 'חיפוש מקורב'],
radiusStyle: true,
onToggle: (index) {
tab.fuzzy.value = index != 0;
},
),
);
});
}
Expand Down Expand Up @@ -123,3 +103,40 @@ class NumOfResults extends StatelessWidget {
});
}
}

class OrderOfResults extends StatelessWidget {
const OrderOfResults({
super.key,
required this.widget,
});

final TantivySearchResults widget;

@override
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable: widget.tab.sortBy,
builder: (context, sortBy, child) {
return SizedBox(
width: 300,
child: Center(
child: DropdownButton<ResultsOrder>(
value: sortBy,
items: const [
DropdownMenuItem(
value: ResultsOrder.relevance,
child: Text('מיון לפי רלוונטיות'),
),
DropdownMenuItem(
value: ResultsOrder.catalogue,
child: Text('מיון לפי סדר קטלוגי'),
),
],
onChanged: (value) {
widget.tab.sortBy.value = value!;
}),
),
);
});
}
}
4 changes: 2 additions & 2 deletions lib/screens/full_text_search/tantivy_full_text_search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import 'package:flutter/material.dart';
import 'package:otzaria/data/data_providers/tantivy_data_provider.dart';
import 'package:otzaria/models/app_model.dart';
import 'package:otzaria/models/tabs/searching_tab.dart';
import 'package:otzaria/screens/full_text_search/full_text_settings_screen.dart';
import 'package:otzaria/screens/full_text_search/full_text_settings_widgets.dart';
import 'package:otzaria/screens/full_text_search/tantivy_search_field.dart';
import 'package:otzaria/screens/full_text_search/tantivy_search_results.dart';
import 'package:otzaria/screens/full_text_search/full_text_left_pane.dart';
import 'package:otzaria/screens/full_text_search/full_text_facet_filtering.dart';
import 'package:provider/provider.dart';

class TantivyFullTextSearch extends StatefulWidget {
Expand Down
35 changes: 19 additions & 16 deletions lib/screens/full_text_search/tantivy_search_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,27 @@ class TantivySearchField extends StatelessWidget {

@override
Widget build(BuildContext context) {
return TextField(
autofocus: true,
controller: widget.tab.queryController,
onSubmitted: (e) => widget.tab.updateResults(),
decoration: InputDecoration(
border: const OutlineInputBorder(),
hintText: "חפש כאן..",
labelText: "לחיפוש הקש אנטר או לחץ על סמל החיפוש",
prefixIcon: IconButton(
return Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
autofocus: true,
controller: widget.tab.queryController,
onSubmitted: (e) => widget.tab.updateResults(),
decoration: InputDecoration(
border: const OutlineInputBorder(),
hintText: "חפש כאן..",
labelText: "לחיפוש הקש אנטר או לחץ על סמל החיפוש",
prefixIcon: IconButton(
onPressed: () {
widget.tab.updateResults();
},
icon: const Icon(Icons.search)),
suffixIcon: IconButton(
icon: const Icon(Icons.clear),
onPressed: () {
widget.tab.updateResults();
widget.tab.queryController.clear();
},
icon: const Icon(Icons.search)),
suffixIcon: IconButton(
icon: const Icon(Icons.clear),
onPressed: () {
widget.tab.queryController.clear();
},
),
),
),
);
Expand Down
39 changes: 1 addition & 38 deletions lib/screens/full_text_search/tantivy_search_results.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:otzaria/models/books.dart';
import 'package:otzaria/models/tabs/pdf_tab.dart';
import 'package:otzaria/models/tabs/searching_tab.dart';
import 'package:otzaria/models/tabs/text_tab.dart';
import 'package:otzaria/screens/full_text_search/full_text_settings_screen.dart';
import 'package:otzaria/screens/full_text_search/full_text_settings_widgets.dart';
import 'package:provider/provider.dart';
import 'package:search_engine/search_engine.dart';

Expand Down Expand Up @@ -131,40 +131,3 @@ class _TantivySearchResultsState extends State<TantivySearchResults> {
});
}
}

class OrderOfResults extends StatelessWidget {
const OrderOfResults({
super.key,
required this.widget,
});

final TantivySearchResults widget;

@override
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable: widget.tab.sortBy,
builder: (context, sortBy, child) {
return SizedBox(
width: 300,
child: Center(
child: DropdownButton<ResultsOrder>(
value: sortBy,
items: const [
DropdownMenuItem(
value: ResultsOrder.relevance,
child: Text('מיון לפי רלוונטיות'),
),
DropdownMenuItem(
value: ResultsOrder.catalogue,
child: Text('מיון לפי סדר קטלוגי'),
),
],
onChanged: (value) {
widget.tab.sortBy.value = value!;
}),
),
);
});
}
}

0 comments on commit eeca041

Please sign in to comment.