问题
We are planning on using Solr to show the users the "n" most frequent terms from a field and we want to apply stemming so that similar terms get grouped.
Now, we need to show the terms to the users but the stemmed terms are not always human readable. Is there any way to get an example of the original terms that got stemmed so that those could be shown to the user?
The only solution we can think of is quering two different fields, one with stemming and one without and then do the matching ourselves. But we think that is going to be expensive (two queries) and may be error prone (the matching may produce errors).
Is there any other way to implement this on Solr? Thanks in advance.
回答1:
Stemming is applied at both query time and index time so I don't think there is an easy way to accomplish what you're trying to do. However, it may be possible, depending on the number of results in your database, to do this by employing a combination of faceting and highlighting. The highlighted term will be the entire matching term rather than the stemmed term (so, for example, the stemmed term might be "associ" but the highlighted terms will be "associated", "association", "associations", etc.). Perhaps what you could do is the following:
?q=keyword&facet=true&facet.field=myfield&&facet.limit=20hl=true&hl.fl=myfield&hl.fragsize=0&rows=10
Getting 10 rows and examining the highlighted results (by default, these are highlighted using <em>
</em>
tags but you can change this by using hl.simple.pre
and hl.simple.post
-- for example, using &hl.simple.pre=[&hl.simple.post=]
would wrap the matching terms in square brackets) should at least give a sample of the "original" matching terms. hl.fragsize=0
returns the entire field along with highlighting.
Hope this helps. You can read more about highlighting parameters here: http://wiki.apache.org/solr/HighlightingParameters
来源:https://stackoverflow.com/questions/9669343/showing-human-readable-most-frequent-indexed-terms-using-a-stemmed-field-with-so