Minixed icon indicating copy to clipboard operation
Minixed copied to clipboard

Is there any possibility to add a search engine?

Open alebulo opened this issue 3 years ago • 5 comments

The library that I made from your template, which is perfect, works great, but I have more than 14000 titles and it is tedious to search by category, how do I have them arranged ... is there the possibility of adding a search engine?

alebulo avatar Sep 01 '21 16:09 alebulo

It's not impossible, but might be outside the scope of the project.

The main question is what are you interested in searching on and in? Filenames are easy, but if you are looking for a tagging system, things get more complicated (and more expensive). Additionally, if we are just searching the current directory, that's much easier (and cheaper) than searching the whole indexed directory, as we would need to either recursively index and search the whole directory on the fly, or build an indexing database, which is definitely out of scope.

tim-elmer avatar Sep 01 '21 16:09 tim-elmer

I agree everything @tim-elmer said. If you @alebulo just need a quick way to search filenames on the fly (a-la CTRL+F), you could try implementing a basic (but I guess inefficient) client-side filter in JS, that scans through the plain DOM Minixed already created and hides non-matching entries...

lorenzos avatar Sep 01 '21 20:09 lorenzos

You could also relatively easily modify your own version of Minixed to return an index of pattern-matched results in the current directory if you want it done server-side, but you'll need to know/learn some PHP.

tim-elmer avatar Sep 01 '21 20:09 tim-elmer

thank you for all guys!!!

alebulo avatar Sep 02 '21 18:09 alebulo

It turns out that a local search script is a whole lot simpler in a table as opposed to the current unordered list.

Here is an example for a table:

   <script>
      $(document).ready(function () {
        $("#s").on("keyup", function () {
          var value = $(this).val().toLowerCase();
          $("#list tr").filter(function () {
            $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
          });
        });
      });
    </script>

Here is an example for a list:

window.addEventListener("load", () => {
  // (A) GET HTML ELEMENTS
  var filter = document.getElementById("the-filter"), // search box
      list = document.querySelectorAll("#the-list li"); // all list items
 
  // (B) ATTACH KEY UP LISTENER TO SEARCH BOX
  filter.onkeyup = () => {
    // (B1) GET CURRENT SEARCH TERM
    let search = filter.value.toLowerCase();
 
    // (B2) LOOP THROUGH LIST ITEMS - ONLY SHOW THOSE THAT MATCH SEARCH
    for (let i of list) {
      let item = i.innerHTML.toLowerCase();
      if (item.indexOf(search) == -1) { i.classList.add("hide"); }
      else { i.classList.remove("hide"); }
    }
  };
});

wilbert-vb avatar Sep 09 '22 01:09 wilbert-vb