Convert Figma logo to code with AI

lapism logosearch

Material You Search component for Android, SearchView

2,232
376
2,232
0

Top Related Projects

🔮 Fast and full-featured autocomplete library

Fast SublimeText-like fuzzy search for JavaScript.

18,051

Lightweight fuzzy-search, in JavaScript

Next-Generation full text search library for Browser and Node.js

JS Search is an efficient, client-side search library for JavaScript and JSON objects

8,902

A bit like Solr, but much smaller and not as bright

Quick Overview

Search is a lightweight, customizable search component for web applications. It provides a clean and modern interface for implementing search functionality, with support for various search types and customization options.

Pros

  • Easy to integrate and customize
  • Responsive design, works well on mobile and desktop
  • Supports multiple search types (e.g., standard, autocomplete, and voice search)
  • Lightweight and performant

Cons

  • Limited documentation and examples
  • May require additional styling for complex layouts
  • No built-in server-side search functionality
  • Limited advanced features compared to some larger search libraries

Code Examples

Basic search implementation:

<div class="search">
  <input type="search" class="search-input" placeholder="Search...">
  <button class="search-button">
    <svg class="search-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
      <path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
    </svg>
  </button>
</div>

Implementing autocomplete:

const search = new Search({
  element: '.search',
  input: '.search-input',
  button: '.search-button',
  autocomplete: true,
  source: ['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry']
});

Adding voice search functionality:

const search = new Search({
  element: '.search',
  input: '.search-input',
  button: '.search-button',
  voice: true
});

Getting Started

  1. Include the Search library in your project:
<link rel="stylesheet" href="path/to/search.css">
<script src="path/to/search.js"></script>
  1. Add the search HTML to your page:
<div class="search">
  <input type="search" class="search-input" placeholder="Search...">
  <button class="search-button">Search</button>
</div>
  1. Initialize the Search component:
const search = new Search({
  element: '.search',
  input: '.search-input',
  button: '.search-button'
});
  1. Customize the search options as needed, such as adding autocomplete or voice search functionality.

Competitor Comparisons

🔮 Fast and full-featured autocomplete library

Pros of Autocomplete

  • More comprehensive and feature-rich, offering advanced functionalities like multi-source search and customizable UI components
  • Better documentation and extensive examples, making it easier for developers to implement and customize
  • Actively maintained with frequent updates and a larger community support

Cons of Autocomplete

  • Steeper learning curve due to its complexity and extensive API
  • Potentially heavier in terms of bundle size and performance impact, especially for simpler use cases
  • Tied to Algolia's ecosystem, which may not be ideal for projects not using Algolia as their search provider

Code Comparison

Search:

const search = new Search({
  el: '#search',
  data: ['apple', 'banana', 'cherry']
});

Autocomplete:

autocomplete({
  container: '#autocomplete',
  getSources({ query }) {
    return [{
      sourceId: 'fruits',
      getItems() {
        return ['apple', 'banana', 'cherry'].filter(item => item.includes(query));
      }
    }];
  }
});

Both libraries provide search functionality, but Autocomplete offers more flexibility and configuration options out of the box. Search is simpler and more straightforward for basic use cases, while Autocomplete provides a more powerful and customizable solution for complex search requirements.

Fast SublimeText-like fuzzy search for JavaScript.

Pros of fuzzysort

  • Lightweight and fast, optimized for performance
  • Supports multiple search modes (exact, fuzzy, etc.)
  • Easy to integrate with minimal setup required

Cons of fuzzysort

  • Limited to client-side JavaScript implementations
  • Fewer customization options for search behavior
  • Less comprehensive documentation compared to search

Code Comparison

fuzzysort:

const results = fuzzysort.go('qck', ['quick', 'brown', 'fox'])
console.log(results.map(result => result.target))

search:

const search = new Search({
  el: '#search',
  data: ['quick', 'brown', 'fox']
});
search.find('qck');

Key Differences

  • fuzzysort focuses on pure string matching, while search provides a more comprehensive search solution with UI components
  • search offers more extensive customization options and supports server-side implementations
  • fuzzysort is better suited for simple, lightweight fuzzy search tasks, while search is more appropriate for complex search requirements with additional features

Use Cases

  • Choose fuzzysort for client-side applications requiring fast, simple fuzzy search functionality
  • Opt for search when building more complex search interfaces with advanced filtering and customization needs
18,051

Lightweight fuzzy-search, in JavaScript

Pros of Fuse

  • Lightweight and dependency-free, making it easy to integrate into various projects
  • Supports fuzzy searching with customizable scoring algorithms
  • Works in both browser and Node.js environments

Cons of Fuse

  • Limited to in-memory searching, which may not be suitable for large datasets
  • Lacks advanced features like highlighting or autocomplete out of the box
  • May require more manual configuration for complex search scenarios

Code Comparison

Fuse:

const fuse = new Fuse(list, {
  keys: ['title', 'author.firstName']
})

const result = fuse.search('old man')

Search:

const search = new Search(document.querySelector('.search'))
search.init()

search.input.addEventListener('keyup', (event) => {
  search.search(event.target.value)
})

While both libraries provide search functionality, Fuse focuses on fuzzy searching with a simple API, whereas Search offers a more comprehensive set of features for web-based search implementations, including UI components and advanced options. Fuse is better suited for lightweight, client-side searching, while Search is more appropriate for complex web applications requiring extensive search capabilities.

Next-Generation full text search library for Browser and Node.js

Pros of FlexSearch

  • Higher performance and faster search capabilities
  • More flexible configuration options for fine-tuning search behavior
  • Supports multiple languages and custom tokenizers

Cons of FlexSearch

  • Larger file size and potentially higher memory usage
  • Steeper learning curve due to more complex API and configuration options
  • May be overkill for simpler search requirements

Code Comparison

FlexSearch:

const index = new FlexSearch({
  encode: "icase",
  tokenize: "forward",
  threshold: 0,
  resolution: 9
});
index.add(1, "John Doe");
const results = index.search("john");

Search:

const search = new Search({
  el: '#search',
  data: [
    { id: 1, name: 'John Doe' }
  ]
});
search.start();

Summary

FlexSearch offers more advanced features and better performance, making it suitable for complex search requirements and large datasets. However, it comes with a steeper learning curve and potentially higher resource usage. Search provides a simpler, more lightweight solution that may be sufficient for basic search functionality in smaller applications. The choice between the two depends on the specific needs of the project, balancing performance and features against simplicity and ease of implementation.

JS Search is an efficient, client-side search library for JavaScript and JSON objects

Pros of js-search

  • Lightweight and focused on JavaScript, making it ideal for client-side search
  • Supports multiple search strategies (prefix, substring, exact match)
  • Allows custom tokenization and indexing for flexible search configurations

Cons of js-search

  • Limited to in-memory search, which may not be suitable for large datasets
  • Lacks advanced features like fuzzy search or relevance scoring
  • No built-in UI components, requiring more work to implement a complete search solution

Code Comparison

search:

<m-search>
  <input type="search" placeholder="Search">
</m-search>

js-search:

const search = new JsSearch.Search('id');
search.addIndex('title');
search.addDocuments(books);
const results = search.search('query');

Key Differences

  • search is a full-featured search component with UI, while js-search is a pure JavaScript search library
  • search offers a more comprehensive solution with built-in styling and customization options
  • js-search provides more flexibility in terms of search algorithms and indexing strategies
  • search is better suited for larger applications with complex search requirements, while js-search is ideal for simpler, client-side search implementations

Both libraries have their strengths, and the choice between them depends on the specific needs of your project, such as performance requirements, dataset size, and desired level of customization.

8,902

A bit like Solr, but much smaller and not as bright

Pros of lunr.js

  • Lightweight and client-side search engine, suitable for small to medium-sized datasets
  • Supports advanced search features like boosting, fuzzy matching, and field-specific searches
  • Well-documented with extensive API and configuration options

Cons of lunr.js

  • Limited scalability for large datasets due to in-memory indexing
  • Requires manual index updates when content changes
  • May have performance issues with complex queries on larger datasets

Code Comparison

lunr.js:

var idx = lunr(function () {
  this.field('title', { boost: 10 })
  this.field('body')
  this.ref('id')
})

search:

const search = new Search({
  element: '#search',
  placeholder: 'Search...',
  data: './data/index.json'
})

Key Differences

  • lunr.js is a pure JavaScript library, while search is a more comprehensive UI component
  • search provides a ready-to-use search interface, whereas lunr.js requires custom UI implementation
  • lunr.js offers more flexibility in index configuration and search algorithms
  • search focuses on simplicity and ease of integration for basic search functionality

Use Cases

  • Choose lunr.js for client-side search with advanced features and customization needs
  • Opt for search when looking for a quick, pre-built search solution with minimal setup

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

API API Kotlin Version Maven Central License

DEPRECATED

Please use:

  • com.google.android.material.search.SearchBar
  • com.google.android.material.search.SearchView

Search

  • Search component for Android
  • Material You Design
  • Styling
  • Kotlin

Search

Api

  • Java = 1.8
  • Kotlin = 1.8

Add the dependency to your gradle file:

repositories {
    google()
    mavenCentral()
}

dependencies {
    implementation 'io.github.lapism:search:2.0.1'
}

Usage

        binding.materialSearchView.requestFocus()
        binding.materialSearchView.clearFocus()

MaterialSearchBar

        val toolbar = binding.materialSearchBar.getToolbar()
        setSupportActionBar(toolbar)

        binding.materialSearchBar.apply {
            navigationIconCompat = NavigationIconCompat.SEARCH
            setHint(getString(R.string.search))
            setOnClickListener {
                binding.materialSearchView.requestFocus()
            }
            setNavigationOnClickListener {
                binding.materialSearchView.requestFocus()
            }
        }

MaterialSearchView

        binding.materialSearchView.apply {
            addView(recyclerView)
            navigationIconCompat = NavigationIconCompat.ARROW
            setNavigationOnClickListener {
                binding.materialSearchView.clearFocus()
            }
            setHint(getString(R.string.search))
            setOnQueryTextListener(object : MaterialSearchView.OnQueryTextListener {
                override fun onQueryTextChange(newText: CharSequence) {
                    adapter.filter(newText)
                }

                override fun onQueryTextSubmit(query: CharSequence) {

                }
            })
            setOnFocusChangeListener(object : MaterialSearchView.OnFocusChangeListener {
                override fun onFocusChange(hasFocus: Boolean) {

                }
            })
        }

Layout

You have to use app theme Theme.Material3.* or Theme.MaterialComponents.*.

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false"
    tools:context=".activity.MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <!-- Simple MaterialToolbar extension -->
        <com.lapism.search.widget.MaterialSearchBar
            android:id="@+id/material_search_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlways|snap" />

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.fragment.app.FragmentContainerView
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"

        app:layout_behavior="@string/material_search_bar_scrolling_view_behavior"

        app:navGraph="@navigation/mobile_navigation" />

    <com.lapism.search.widget.MaterialSearchView
        android:id="@+id/material_search_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_anchor="@id/material_search_bar" />

    <BottomNavigationView
        android:id="@+id/bottom_navigation_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:orientation="vertical"
        app:layout_insetEdge="bottom"
        app:menu="@menu/menu_bottom_nav" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

XML attributes


<declare-styleable name="MaterialSearchBar">
    <attr name="search_navigationIconCompat" format="enum">
        <enum name="none" value="0" />
        <enum name="arrow" value="1" />
        <enum name="search" value="2" />
    </attr>
    <attr name="search_navigationIcon" format="reference" />
    <attr name="search_navigationContentDescription" format="reference" />
    <attr name="search_navigationBackgroundColor" format="reference" />
    <attr name="search_navigationElevation" format="dimension" />
    <attr name="search_radius" format="dimension" />
    <attr name="android:hint" />
    <attr name="android:layout_marginStart" />
    <attr name="android:layout_marginEnd" />
    <attr name="android:layout_marginTop" />
    <attr name="android:layout_marginBottom" />
</declare-styleable>

<declare-styleable name="MaterialSearchView">
    <attr name="search_navigationIconCompat" />
    <attr name="search_navigationIcon" />
    <attr name="search_navigationContentDescription" />
    <attr name="search_navigationBackgroundColor" />
    <attr name="search_navigationElevation" />
    <attr name="search_clearIcon" format="reference" />
    <attr name="search_dividerColor" format="reference" />
    <attr name="search_scrimColor" format="reference" />
    <attr name="android:hint" />
    <attr name="android:imeOptions" />
    <attr name="android:inputType" />
</declare-styleable>

Todo

Animation

  • animation like Google, needs help :)

Author

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.