Ravi
Ravi

Reputation: 1179

Marklogic field search options

I am having search options like the following

let $options :=
 <options xmlns="http://marklogic.com/appservices/search">
    <constraint name="collection">
        <collection prefix=""/>
    </constraint>
    <constraint name="concept_name">
        <word>
            <field name="concept_name" collation="http://marklogic.com/collation/en/S1"/>
        </word>
    </constraint>
    <term>
        <term-option>case-insensitive</term-option>
        <term-option>punctuation-insensitive</term-option>
        <term-option>whitespace-insensitive</term-option>
        <term-option>wildcarded</term-option>
    </term>
    <return-facets>false</return-facets>
    <return-values>false</return-values>
    <return-constraints>false</return-constraints>
    <return-frequencies>false</return-frequencies>
    <return-qtext>false</return-qtext>
    <search-option>format-json</search-option>
    <search-option>score-simple</search-option>
</options>

And doing the search search:search($q, $options, $start, $page-length)

But the search is not doing case-insensitive. How do I tell in this scenario to specify options for a field.. I want it to be case-insensitive

When I do cts:field-value-match("concept_name", $q ("case-insensitive", "diacritic-insensitive")) , I do get the correct results, so how do I specify using the search options like above to do the same.

Upvotes: 1

Views: 144

Answers (1)

Sam Mefford
Sam Mefford

Reputation: 2475

I think you want your <term-option>case-insensitive</term-option> inside your <constraint...><word> element. That way the option affects your search with that constraint. However, you haven't shared your $q (serach string), so I don't know for sure what search you're testing with.

You should note that cts:field-word-match will search in the field word lexicon and is therefore a better fit for what you're doing with your search:search than cts:field-value-match which matches the values in the field range index.

In any case, I'm not sure what your options are on your database or field, so it's not clear why you're struggling to get case-insensitive matches. When I try cts:field-word-match("concept_name", "alexa488", ("collation=http://marklogic.com/collation/en/S1")) I get a match even though I didn't add the case-insensitive option. Similarly, when I try the search:search with no <term-option>case-insensitive</term-option> I get a match.

Upvotes: 1

Related Questions