Thanks Danny. I tried the first option with just 2 documents loaded in the database. Both have exactly one occurrence of the word "life". One has it in the "title" element and the other in the "desc" element. Now, when I search for "life" using the new search API (sample code in earlier mail), both documents get returned with exactly the same "score" and "fitness". I have tried setting weights starting from 2.0 to 20.0 for "title" and made sure the documents are reloaded / re-indexed, but still no change.
Thanks for your help. Surajit On Wed, Aug 12, 2009 at 6:04 PM, Danny Sokolsky < [email protected]> wrote: > Hi Surajit, > > I can think of a few ways to accomplish this. > > Probably the easiest is to set a weight for word query on the "title" > element in the "http://www.sb.com/namespaces/sb" namespace. To so this, > go to the word query section of your database configuration and configure an > include for that QName with a weight greater than 1.0. Similarly for the > desc QName. Doing it this way will "bake" that weighting into the indexes. > Note that it will do this for all instances of this QName in the database, > though, so make sure that is OK for your application. > > If you want something more restrictive than the above approach, you can > parse the text yourself and then create your own cts:query, and then pass > that to search:resolve. search:resolve is just like search:search except > that you do the query parsing. You can create your cts:query however you > like, and give each part the weights you desire. You can even use > search:parse to initially parse the query, and then take its output and > modify it to weight the title element differently (although this might be > tricky to get right). You will have to do some slightly tricky boolean > logic to do this, but it is possible. If you use all of the grammar of the > search API, it will be trickier. > > I think there are probably other ways, too, but this ought to give you a > few things to think about. > > -Danny > > > > > From: [email protected] [mailto: > [email protected]] On Behalf Of Surajit > Bhattacharjee > Sent: Wednesday, August 12, 2009 2:01 PM > To: General Mark Logic Developer Discussion > Subject: [MarkLogic Dev General] applying relevance weights to XML tags > > I have 10 documents loaded in Mark Logic, each containing information about > a single book. Below is a sample document. > > <?xml version="1.0" encoding="UTF-8"?> > <book xmlns="http://www.sb.com/namespaces/sb"> > <title>The Life of David Gale</title> > <genre>fiction</genre> > <desc>....</desc> > <review>...</review> > </book> > > My search goes against the entire document but I want it to apply a higher > weight to matches in the TITLE as opposed to DESC. I have read the > documentation but it isn't clear how I can get that to happen. > > Below is my search code using the new search API. > > xquery version "1.0-ml"; > import module namespace search = "http://marklogic.com/appservices/search" > at "/MarkLogic/appservices/search/search.xqy"; > search:search("life", > <options xmlns="http://marklogic.com/appservices/search"> > <constraint name="facet-on-genre"> > <range type="xs:string" facet="true"> > <facet-option>limit=10</facet-option> > <element ns="http://www.sb.com/namespaces/sb" name="genre"/> > </range> > </constraint> > </options>) > > Surajit > _______________________________________________ > General mailing list > [email protected] > http://xqzone.com/mailman/listinfo/general >
_______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
