There is a view that Solomon wrote (and collected) the proverbs when he was young, the Song of Songs before mid-life, and Ecclesiastes when he was old.
After his search for the meaning of life, Solomon tells us something about the futility of his search:
7:23-25 All this I have tested by wisdom; I said, ‘I will be wise’, but it was far from me. That which is, is far off, and deep, very deep; who can find it out? I turned my mind to know and to search out and to seek wisdom and the sum of things, and to know that wickedness is folly and that foolishness is madness.
8:16-17 When I applied my mind to know wisdom, and to see the business that is done on earth, how one’s eyes see sleep neither day nor night, then I saw all the work of God, that no one can find out what is happening under the sun. However much they may toil in seeking, they will not find it out; even though those who are wise claim to know, they cannot find it out.
So he resolved that there is nothing other than to be content with whatever God has given you:
8:15 So I commend enjoyment, for there is nothing better for people under the sun than to eat, and drink, and enjoy themselves, for this will go with them in their toil through the days of life that God gives them under the sun.
Finally, Solomon had a lot of wives. His experience found its way into this book:
7:26I found more bitter than death the woman who is a trap, whose heart is snares and nets, whose hands are fetters; one who pleases God escapes her, but the sinner is taken by her.