I'm creating a website which will collect posts from facebook's pages to show to the users posts they are interested in (as my graduating project).

I'd like to be able to rank the posts that contain the words which are queried. Hence, I use (solr)for full text indexing which allows me to effciently get the posts containing the words the user searches for.

Now, I am looking for a ranking function for returning most relevant search results first. But there are many variables which could influence the relevance and ranking of the post. I found these factors:

  1. date of the post.

  2. likes number of the post.

  3. comments number of the post(not very correct).

  4. is the published page verified ?

  5. likes count for the published page.

  6. location of the page and the user.

I need a formula to combine these factors, and I think that there is something missing - there must be a weighting for the search keywords themselves in the post. And maybe I am missing something more?

Is there any other way to determine relevance?

Some additional information:

  • I think that there is an important factor I am not using. This factor should deal with the other keywords in the post and see if they are related to the major keyword.

Take, for example, these two posts:

  1. I love sports.

  2. I love basketball , football and all other sports and i think that they are very healthy.

Lets say these posts have the same above factors, but the second has more keywords in the required domain (sports). How to determine that the second post is more related to the "sports" domain?


1 Answer 1


For creating a formula to map those parameters to a ranking value, first map each parameter to a positive real number. Then a simple approach is to make a weighted sum from these numbers. The Wikipedia article also contains further links to more sophisticated approaches.

Of course, you need to determine "good weights", but hey, it is your graduate project, and you should do some research here on your own.

Moreover, you should definitely inform yourself how the page ranking algorithms of those bigger search engines work and if there are parts of it applicable to your problem.

I cannot tell you why Facebook search changes results after each refresh, and I don't think this is a good question for this site, since we also could only guess here (I would actually recommend to delete that part from the question, some "site cop" guys here are often looking for a reason to close questions because they contain a minor off-topic section).

The missing factor you are looking for could be the number of additional words in that post which do not match any of the search keywords exactly, but are "semantically related" to one or more of them. So how do you measure "semantically related"? Actually, I am not an expert on this, but AFAIK this is whole scientific research area, and tools like CoreNLP or SML might be worth a try.

  • thanks for you, I have searched a lot but I have not reached to what i need. Mar 15, 2018 at 16:47
  • thank you for your answer. you are all right. i have edited the question. Mar 15, 2018 at 23:54
  • @MohammedNosirat: just a hint: you can increase your chance to get more answers by not accepting mine too early.
    – Doc Brown
    Mar 16, 2018 at 19:27
  • you are right, but it was good and it has solved a big problem. so thank you again. Mar 16, 2018 at 22:57
  • @MohammedNosirat: I am curious here if there is an expert who can give answer the second part of the question, which falls into the realm of semantical analysis of texts. Nevertheless I will try give you at least a pointer where to look, expect my next edit.
    – Doc Brown
    Mar 17, 2018 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.