question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Method to cancel search?

See original GitHub issue

Hello, I’ve just started using fuse.

I search a very large array of objects (~15000), each with one property (let’s call it name). Every search returns thousands of results.

I can’t tell if fuse has performance issues, probably not, it’s just a very large array. Anyway, I put it in a web worker, and now the UI is perfectly responsive but the results returned from the web worker still lag behind because it’s still executing old searches.

I’d like to be able to cancel all pending searches before I start a new one.

I imagine this wouldn’t be very difficult to implement?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kriskcommented, Feb 23, 2017

This is not a Fuse issue 😄 Sounds like you should throttle/debounce the searching that is executed on the Web Worker.

The idea of a cancel operation would only make sense if Fuse contained some asynchronous behavior, which it doesn’t have.

0reactions
KonradHoeffnercommented, May 5, 2021

You can also wait with searches if the last one was long and a short time ago and check later if it is still needed. I am using this implementation:

  search(query)
  {
    if(!query||query.length<2) {return this.data;}
    const start = new Date().getTime();
    this.lastSearchStart=start;
    const items = this.fuse.search(query).map(x=>x.item.bezeichnung);
    const hits = new Set(items);
    const filteredData = this.data.filter(row=>hits.has(row.bezeichnung));
    const end = new Date().getTime();
    this.lastSearchDuration=end-start;
    return filteredData;
  }

  throttledSearch(query)
  {
    // throttle searches to not overload the CPU
    const start = new Date().getTime();
    this.lastSearchTaskStart = start;
    if(this.lastSearchDuration>100&&(start-this.lastSearchStart<this.lastSearchDuration*4))
    {
      setTimeout(() =>
      {
        // do we still need the search?
        if(this.lastSearchTaskStart===start) {search(query);}
      }, this.lastSearchDuration*4);
    } else
    {
      search(query);
    }
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Manage & delete your Search history - Android
Delete Search history · On your Android phone or tablet, open the Google app . · At the top right, tap your Profile...
Read more >
In vim, is there a way to cancel a search *without* resetting ...
When I start a search, it immediately goes to the first match. If I press return to accept the search, the result is...
Read more >
Canceling a search
Procedure ; From the Search menu, select Manage Search Results. ; Click Cancel. ; Click Yes.
Read more >
How to Delete All Google Search History - 2021 - YouTube
How to delete all Google search history? In this tutorial, I show you how to delete and clear all search history from Google....
Read more >
ICallHierarchyMemberItem.CancelSearch(String) Method
The category in which to cancel the search. Applies to. Product, Versions. Visual Studio SDK, 2015, 2017 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found