java - Searching related stories based on tag on priority basis -
i need search related stories based on tags of story..
say have story 4 tags related story logic be
step 1: search 4 tags under story >> display story
step 2: search 3 tags creating different permutation & combination related tags >> display story
- step 3: search 2 tags creating different permutation & combination related tags >> display story
- step 4: search tag 1 after other, if found display same in “more this” field.
how can achieve this. newbee in solr please guide me...
thomas' suggestion in comments idea, can give wrong result - example if have 2 common tags , 2 that's unique 2 stories in question. i.e.:
- story 1 (foo, bar, the, is)
- story 2 (foo, bar, ask, barf)
- story 3 (baz, bar, the, is)
- .. repeat thousands of other stories "the" , "is" tags
if search tag:(foo or bar or or is)
when displaying first entry, might story 2 instead - has "valuable" tags (and default calculation solr uses number of times term appear in document divided total number of documents appears in).
the best result (this depend on use case) still story 2, if really want document matches 3 of tags, you'll have different way.
if need second option, can solve using function query: termfreq
returns number of times term in document (and if tags distinct in document, 1
). sum
allows sum values each function, like:
sum(termfreq(tag, 'foo'), termfreq(tag, 'bar'), termfreq(tag, 'the'), termfreq('is'))
.. give distinct tag count each document use sorting.
you have option of using custom similarity class, return same similarity score each term (and depending on solr version you're using, similarity may set each field (and not core)). don't think there's 1 included, but there's plenty of examples available.
Comments
Post a Comment