3 Replies Latest reply: May 8, 2012 9:18 AM by Roger Ford-Oracle RSS

    Question about relevance weighting

    Gwydion
      Hi,

      our text index contains XML documents and we weight the relevance score depending on the tag in which the search term appears.
      I would like to do the following: I want to search for all documents that contain the search tag "X" within tag A. But I want to give documents that contain "X" also in tag B a heavier weight
      Probably I could use two text queries, something like
      SELECT * FROM foo WHERE CONTAINS( xml, '(X within A)', 1 ) OR CONTAINS( xml, '(X within A) and (X within B)*2' , 1)
      I don't know if that would work at all, but using two CONTAINS would require us to change our search logic significantly.
      Is it possible to write such a query with a single CONTAINS clause?
        • 1. Re: Question about relevance weighting
          Roger Ford-Oracle
          Yes, you can do that all in a single contains:
          SELECT * FROM foo WHERE CONTAINS( xml, '(X within A) OR ( (X within A) AND (X within B) )*2' , 1)
          The OR operator scores the higher of its two sides, so this will work in most situations. However there is an edge-case where it won't - if "X within B" scores less than half of "X within A" then the score of the second part will become just that for "X within A" (because AND scores the lower of its two sides) and therefore X within B will not add to the overall score.
          SELECT * FROM foo WHERE CONTAINS( xml, '(X within A) ACCUM ( (X within A) AND (X within B) )' , 1)
          Will always work. ACCUM guarantees that hits on both sides always score higher than hits on one side only, and the right-hand side here subsumes the left-hand side.

          As an aside - the syntax as you have it would NOT work, as you have the same third argument (,1) in each of your CONTAINS clauses. The third argument - which is used to correlate the SCORE(n) operator with a particular CONTAINS clause - must be unique to each CONTAINS.
          • 2. Re: Question about relevance weighting
            Gwydion
            ( (X within A) AND (X within B) )*2
            Ok, so it looks as if I had a basic misunderstanding how weighting works. The weight isn't applied to a certain XML tag, it is applied to a search predicate?
            • 3. Re: Question about relevance weighting
              Roger Ford-Oracle
              Yes, that's correct.