Search for html files with keyword inside?

1

Well I tell you, I have a website where I have products for sale. Previously I could put them on the main page without worrying that customers would not find what they were looking for because they were few products. But now I have increased the catalog and start to require a search method that finds each product. I do not want to use a CMS and I do not want to design my website from scratch with Databases . I had planned to do a Search Box that will search Keywords with the relevant data for the search.

For example: I have a product on sale, let's say Auto in color red then I have a file autorojo.html where is all the info about the car. (Yes, I am perfectly aware that it is not the best way to make a page, it is preferable to use Databases, and do everything with PHP, but my knowledge does not give so much for now, so I hope you respect my way of do things)

Now: let's say I have, in the file autorojo.html and in, in <head> I have a <meta> tag as follows: <meta name="keywords" content="auto, rojo"> I would like to know if there is any way with PHP or JS, through a Search Box to search the Keywords present in the HTML file and make a call to that file and then make a display in the part of the relevant website.

I know some will seem a bit obsolete but I plan to learn PHP thoroughly and use MVC in the near future to redesign the page.

I will accept suggestions for other design methods, if you think that mine has no remedy haha.

Thank you very much in advance!

    
asked by Nicolas Echeverry 21.01.2017 в 21:52
source

1 answer

0

My suggestion is this:

Doing something that you look for in other files with the expressed limitations would be a headache. I also assume that you have a moderate volume and that you are adding the products by hand.

In these circumstances, the easiest thing is that within the homepage where you have the search engine, put an index of your products with your url and its labels, either visibly or not.

Then with Jquery you search within that same index in that same file, which is much easier to do.

You can use data to achieve it easily:

<a href="LaURLdeTuProducto" data-etiquetas='["a","b","c"]'>Mi Producto</a>
<a href="LaURLdeTuProducto2" data-etiquetas='["x","y","z"]'>Mi Producto2</a>

Then you retrieve the labels of each element like this:

  var etiquetas = $('a').data('etiquetas');

And you can use .each () to cycle through all the elements and do some search criteria there.

It is neither the most efficient nor the most technically adequate, but I think it solves the limitations you ask for.

    
answered by 07.02.2017 в 16:10