evaristoc / fCC_R3

freeCodeCamp Resources' Ranking and Reviews
2 stars 2 forks source link

Solving ranking of params in the Compare page by relevance #10

Closed evaristoc closed 7 years ago

evaristoc commented 7 years ago

The list of "Other links that might interest you" should be sorted by relevance to the selected subject. For that:

evaristoc commented 7 years ago

For point 1, data is passed using SESSION Storage (easy).

evaristoc commented 7 years ago

For point 2, apparently there are ways to use Javascript libraries inside the Typescript code. I am currently evaluating its use with elasticlunr library. See:

evaristoc commented 7 years ago

The current solution has a weird behaviour: the elasticlunr will rank only if is set to saving documents as FALSE when routing to the corresponding page. After that, it won't reorder. If the page is refreshed, the order will disappear NOT MATTER WHAT I DO. So it is apparently a problem of state. Turning the saving document setting into TRUE will have impact on it (REMEMBER that the functionality is set to be a global one!!!) - it won't update from the first set no matter what I do!!

EDIT:

A detailed description of the problem:

The desired outcome would be that elasticlunr should update the query after refreshing, even if the query is the same: otherwise if the ranking disappears I won't be able to use it to order the documents in the corresponding page (the "params").

There is also apparently a wrapper of the elasticlunr that I have installed in the project, ngx-elasticlunr, but really don't know how it works, if it works.

evaristoc commented 7 years ago

The code involved is this one: https://github.com/evaristoc/fCC_R3/blob/development/src/app/platform/platform.component.ts

and it consists in:

evaristoc commented 7 years ago

Managed to update elasticlunr ranking after changing pages (using ngOnDestroy hack) but the ranking would disappear when reloading over the same page.

Possible solution? localStorage.

evaristoc commented 7 years ago

The best solution so far using elasticlunr library?

The function is created at OnInit and then becomes AN OBJECT so it can be translated into a variable in the HTML DOM where is the residence of the globally defined library !!!

In fact after loading the function, the documents can be saved and survive in browser memory without having to create a localStorage (they are saved on Window anyway) if I don't run the OnDestroy function!

So I was dedicating too much time to try to re-run the search method inside the component but for this case it is easier (maybe better...) to manipulate the resulting instance of elasticlunr in the HTML of the component !! - in-te-res-ting....

I will work on this using this method then.