Alexander Sidorov wrote:
> Hello!
> 
> I came to the most important part of my application - searching. What I need
> in my RDF-based search is to implement Free Text Search for several
> predicates, get relevance for each of them and then combine it some way into
> total relevance. The first idea was to use bif:contains, but I have no idea
> how to combine relevance in this case. Would be very grateful for any
> recommendations.

Hi Alexander,

I came across this myself previously; virtuoso gives us two ways of
getting relevance information, iri_rank for iris, and score for
bif:contains.

select ?s ?p ?o (xsd:integer(<LONG::IRI_RANK>(?s))) as ?iriRank ?oscore
WHERE {
?s ?p ?o . FILTER( lang(?o) = "en" ) . ?o bif:contains '"search text"'
option(score ?oscore)
} ORDER BY desc(?oscore) desc(?iriRank)

As I understand it you want to give different weights to scores
depending on the predicate used. To handle this I can see 3 approaches:

Combine multiple results together with union, modifying the score for
each predicate then grouping at the end:

SELECT DISTINCT ?s (sum(?oscore)) as ?finalWeight WHERE {
{ select ?s (xsd:integer( ?oscore * 1.4 )) as ?weight where {
 ?s <predicate1> ?o . ?o bif:contains '"search text"' option(score ?oscore)
} } UNION {
{ select ?s (xsd:integer( ?oscore * 1.8 )) as ?weight where {
 ?s <predicate2> ?o . ?o bif:contains '"search text"' option(score ?oscore)
}
} GROUP BY ?s
ORDER BY desc(?finalWeight)

Option 2 would be to use a script to iterate over the results of the
first sparql query in this reply to do the weighting of predicates, and
option 3 would be to use the first query style with ultra complex if
logic ( using bif:either ) to do the weighting depending on predicate,
you'd probably want to limit the available predicates with a FILTER( ?
in( list,of,predicates) ) though!

Many Regards & hope that helps a bit,

Nathan

Reply via email to