ianldgs / material_search

https://pub.dartlang.org/packages/material_search
MIT License
75 stars 39 forks source link

Feature: Search Engine #10

Open ghost opened 6 years ago

ghost commented 6 years ago

There is a search engine for dart and golang that I use alot. Bleve is the golang one. Ducene is the dart one.

Might be able to get it working with your search widget. But for facets we will need to find a way to display facets options and then tags in the results.

If your interested I can try but maybe you have other plans in your roadmap ?

ianldgs commented 6 years ago

I think it's a very good functionality, maybe to 0.4.0 milestone. It would have to be optional, so don't make the widget too complicated to use. If you think you can make that work, a PR would be welcome! But I would like first to have a little bit more of unit tests, that I'm planning for 0.3.0.

ghost commented 6 years ago

Ok. Just realised it's better if I Incorporate your widget into my demo first on my side. Then you can see what's useful to you when your ready.

defemz commented 5 years ago

The search results being returned when a search string is supplied is not listed according to order of relevance e.g if i enter search text "goo" for good, if 5 results are displayed, "good" is the most relevant result of my search, it will be displayed at fifth position of search result, instead of first position. Please how can this be fixed.

ianldgs commented 5 years ago

@defemz you can use the sort option. It's up to you to decide which results are the most relevant to your application.

defemz commented 5 years ago

@defemz you can use the sort option. It's up to you to decide which results are the most relevant to your application.

@ianldgs Thanks for the reply. Please can you kindly point to where and how this can be done. Below is my implementation:

` _buildMaterialSearchPage(BuildContext context) { //The ff line convert String List to dynamic(var) before the search package can work var _paramNames = new List.from(ListPlaceHolder().returnParamNames(widget.myListParamNames));

return new MaterialPageRoute<String>(
    settings: new RouteSettings(
      name: 'material_search',
      isInitialRoute: false,
    ),
    builder: (BuildContext context) {
      return new Material(
        child: new MaterialSearch<String>(
          placeholder: 'Search',
          results: _paramNames.map((String v) =>
          new MaterialSearchResult<String>(
            icon: Icons.search,
            value: v,
            text: "$v",
          )).toList(),
          filter: (dynamic value, String criteria) {
            return value.toLowerCase().trim()
                .contains(
                new RegExp(r'' + criteria.toLowerCase().trim() + ''));
          },
          onSelect: (dynamic value) {
           // print(value);
            if(_dropDown1Or2 == 1){
              setState(() {
                selectedItemState = value;
                _calcHub();
              });

            }
            else if(_dropDown1Or2 == 2){
              setState(() {
                selectedItemState2 = value;
                _calcHub();
              });
            }
            Navigator.of(context).pop(value);
          },//Navigator.of(context).pop(value),
          onSubmit: (String value) => Navigator.of(context).pop(value),
        ),
      );
    }
);

} }`

_showMaterialSearch(BuildContext context) { Navigator.of(context) .push(_buildMaterialSearchPage(context)) .then((dynamic value) { setState(() => _name = value as String); }); } Thanks for the help.

ianldgs commented 5 years ago

@defemz

See dart's sort documentation for how to sort arrays. Only difference is that you will receive the current string typed in the search box, which might be useful to show results that start with the criteria first, for example.

        ...
        child: new MaterialSearch<String>(
          placeholder: 'Search',
          results: _paramNames.map((String v) =>
          new MaterialSearchResult<String>(
            icon: Icons.search,
            value: v,
            text: "$v",
          )).toList(),
          filter: (dynamic value, String criteria) {
            return value.toLowerCase().trim()
                .contains(
                new RegExp(r'' + criteria.toLowerCase().trim() + ''));
          },
+          sort: (dynamic a, dynamic b, String criteria) {
+            return 0; // 
+          }
          onSelect: (dynamic value) {
           // print(value);
            if(_dropDown1Or2 == 1){
              setState(() {
                selectedItemState = value;
                _calcHub();
              });

            }
            else if(_dropDown1Or2 == 2){
              setState(() {
                selectedItemState2 = value;
                _calcHub();
              });
            }
            Navigator.of(context).pop(value);
          },//Navigator.of(context).pop(value),
          onSubmit: (String value) => Navigator.of(context).pop(value),
          ...