What methods should I use in order for my query to return hits with at least 2 keywords in the text from an input phrase.
For example, if the input "hello friend" I want the return results to contain documents where "hello" and "friend" somewhere in the text. If the input "hello good friend" I want results where 2 of 3 keyword in the text. Or at least results with best combinations be on top. If I use code like one below I get results where "hello" or "friend" but not both.
var searchResults = client.Search<Thread>(s => s
.Type("threads")
.From(0)
.Size(100)
.Query(q => q
.Match(qs => qs
.OnField(p => p.Posttext)
.Query("hello friend")
)
)
.Highlight(h => h
.OnFields(
f => f.OnField("posttext").PreTags("<b>").PostTags("</b>").FragmentSize(150)
)
)
);
I can get results I want by code like this one but it is not flexible because phrase can be with arbitrary number of words.
var searchResults = client.Search<Thread>(s => s
.Type("threads")
.From(0)
.Size(100)
.Query(q => q
.Match(qs => qs
.OnField(p => p.Posttext)
.Query("hello")
)
&&
q.Match(qs => qs
.OnField(p => p.Posttext)
.Query("friend")
)
)
.Highlight(h => h
.OnFields(
f => f.OnField("posttext").PreTags("<b>").PostTags("</b>").FragmentSize(150)
)
)
);
I think I am missing something. Please help.
Thanks in advance.