Thanks very much Erik. This sounds promising. I'll try it out.

Best,

Tim Finney

On 06/01/2013 08:48 PM, Erik Hennum wrote:
> Hi, Tim:
>
> This sounds like a job for boost query.
>
> Today, you can write a boost query with a boolean that has an and-query 
> combining the required match criteria and nested or-query.  The nested 
> or-query combines the optional boost criteria and an empty and-query (which 
> matches anything, so the boosting criteria contributes to scoring but does 
> not restrict results).
>
> Let's say you've got the following documents. Both should match, but the 
> first should be scored higher:
>
> <doc><match>matchvalue</match><boost>boostvalue</boost></doc>
> <doc><match>matchvalue</match><nonboost>nonboostvalue</nonboost></doc>
>
> Here's the implementation in structured search (which has an implicit 
> and-query over top-level criteria):
>
> search:resolve(
>      <query xmlns="http://marklogic.com/appservices/search";>
>          <value-constraint-query>
>              <constraint-name>matcher</constraint-name>
>              <text>matchvalue</text>
>          </value-constraint-query>
>          <or-query>
>              <value-constraint-query>
>                  <constraint-name>booster</constraint-name>
>                  <text>boostvalue</text>
>              </value-constraint-query>
>              <and-query/>
>          </or-query>
>      </query>,
>      <options xmlns="http://marklogic.com/appservices/search";>
>        <constraint name="matcher">
>            <value>
>                <element ns="" name="match"/>
>            </value>
>        </constraint>
>        <constraint name="booster">
>            <value>
>                <element ns="" name="boost"/>
>            </value>
>        </constraint>
>      </options>
>      )
>
> And here's the implementation in string search:
>
> search:search(
>      "matcher:matchvalue",
>      <options xmlns="http://marklogic.com/appservices/search";>
>        <constraint name="matcher">
>            <value>
>                <element ns="" name="match"/>
>            </value>
>        </constraint>
>        <additional-query>{
>            cts:or-query((
>                cts:element-value-query(xs:QName("boost"), "boostvalue"),
>                cts:and-query(())
>                ))
>        }</additional-query>
>      </options>
>      )
>
> In your case, my:title would be playing the role of the "boost" element.  You 
> could modify the weight on the match and boost queries as needed to get the 
> ranking right.
>
>
> Does that get you closer to your goal?
>
>
> Erik Hennum
>
> ________________________________________
> From: [email protected] 
> [[email protected]] on behalf of Tim Finney 
> [[email protected]]
> Sent: Saturday, June 01, 2013 2:27 AM
> To: MarkLogic Developer Discussion
> Subject: Re: [MarkLogic Dev General] Additional query when sorting by score
>
> Thanks Erik.
>
> An <additional-query> element is allowed inside the <state> element, but
> I think that translates to an and-query. Is there a way to get an
> or-query in there? In pseudo-code:
>
> <operator name="sort">
>      <state name="relevance">
>        <sort-order><score/></sort-order>
>        
> <or-query>{myfn:something_in_query_string_is_inside_my:title}</or-query>
>      </state>
> </operator>
>
> (I can do a quick and dirty tokenize of the query string to avoid
> parsing it first.)
>
> What I'd like is a way in search:search options to make docs with query
> terms inside the <my:title> element rank higher than docs with query
> terms elsewhere.
>
> Best,
>
> Tim Finney
>
> On 05/31/2013 08:03 PM, Erik Hennum wrote:
>> Hi, Tim:
>>
>> If I understand your goals correctly:
>>
>> *  Your options should create a word constraint on the my:title element that 
>> contains a weight element with a number larger than the default (1.0)
>> *  If you are using a structured query, your query should use an or query 
>> that makes the word constraint optional.  If you are using a string query, 
>> the word constraint will be included only if the user supplies the string.
>>
>> You might need to experiment to get the weighting factor right.
>>
>> The documentation for weight:
>>
>>       http://docs.marklogic.com/guide/search-dev/relevance#id_22791
>>
>>
>> Hoping that helps,
>>
>>
>> Erik Hennum
>>
>> ________________________________________
>> From: [email protected] 
>> [[email protected]] on behalf of Tim Finney 
>> [[email protected]]
>> Sent: Friday, May 31, 2013 4:33 AM
>> To: MarkLogic Developer Discussion
>> Subject: [MarkLogic Dev General] Additional query when sorting by score
>>
>> Hi All,
>>
>> I want to change the behavior of a sort operator using the options node
>> for search:search. I have this at the moment:
>>
>> <operator name="sort">
>>      <state name="relevance">
>>        <sort-order><score/></sort-order>
>>      </state>
>> </operator>
>>
>> I'd like to change things so that a doc which includes search terms in
>> its <my:title> element is returned higher in the results. Can I do this
>> using an additional query in the options node or in some other way? I'd
>> like to be able to do things in one pass (i.e. not have to parse the
>> query separately).
>>
>> Best,
>>
>> Tim Finney
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://developer.marklogic.com/mailman/listinfo/general
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://developer.marklogic.com/mailman/listinfo/general
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to