Search code examples
wildcardmarklogicmarklogic-8marklogic-9

Wildcard search not working for path-index


Here is the query which gives the desired results:

import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";

search:search("( ( collectionId: ( "54930050DETB6CP71D38" ) )  )  sort:documentCreationDateDES", 
<options xmlns="http://marklogic.com/appservices/search">

    <term>
        <empty apply="all-results"/>
        <term-option>unstemmed</term-option>
        <term-option>case-insensitive</term-option>
        <term-option>punctuation-insensitive</term-option>
        <term-option>wildcarded</term-option>
    </term>

    <additional-query>{cts:directory-query('/dir/subdir01/', "1")}</additional-query>

    <transform-results apply="transformed-result" ns="http://searchgui/search" at="/customResultSet.xqy"/>

    (:
    Constraints or Search Criteria.
    - collectionId
    - creationDate
    :)

    <search:constraint name="collectionId">
        <search:range type="xs:string" facet="false" collation="http://marklogic.com/collation/en">
            <search:path-index ns="http://any.anyns.com/2013/doc">
                //cd:documentCollections/cd:collection/cd:id
            </search:path-index>
        </search:range>
    </search:constraint>

    <search:constraint name="creationDateRange">
        <search:range type="xs:dateTime" facet="false">
            <search:bucket ge="0" lt="0" name="documentCreationDate">
                Search by Document Creation date / uploaded date
            </search:bucket>
            <search:element ns="http://any.anyns.com/2013/doc" name="documentCreationDate"/>
            <facet-option>limit=10</facet-option>
            <facet-option>item-order</facet-option>
            <facet-option>descending</facet-option>
        </search:range>
    </search:constraint>

    (:
    Sorting options:
    - collectionId
    - creationDate
    :)
    <search:operator name="sort">

        (: Document Collection Id :)
        <search:state name="collectionIdASC">
            <search:sort-order direction="ascending" type="xs:string">
                <search:path-index ns="http://any.anyns.com/2013/doc">
                    //cd:documentCollections/cd:collection/cd:id
                </search:path-index>
            </search:sort-order>
        </search:state>
        <search:state name="collectionIdDES">
            <search:sort-order direction="descending" type="xs:string">
                <search:path-index ns="http://any.anyns.com/2013/doc">
                    //cd:documentCollections/cd:collection/cd:id
                </search:path-index>
            </search:sort-order>
        </search:state>

        (: Creation Date :)
        <search:state name="documentCreationDateASC">
            <search:sort-order direction="ascending" type="xs:dateTime">
                <search:element ns="http://any.anyns.com/2013/doc" name="documentCreationDate"/>
            </search:sort-order>
        </search:state>
        <search:state name="documentCreationDateDES">
            <search:sort-order direction="descending" type="xs:dateTime">
                <search:element ns="http://any.anyns.com/2013/doc" name="documentCreationDate"/>
            </search:sort-order>
        </search:state>

    </search:operator>
</options>, 1, 100);

But when i replace the search-criteria with wild-cards as below, it does not return any results:

"( ( collectionId: ( &quot;* *54930050DETB6CP71D38* *&quot; ) )  )  sort:documentCreationDateDES"

Though i set the <term-option> as wildcarded still it does not work, any suggestions or pointer as to what i might be missing would help.

I have tried changing other term-option from sensitive to insensitive and back in different combinations but it does not work, nor does stemmed or unstemmed works.


Solution

  • Term-options don't apply to range constraints, only facet-options do. And a facet-option wildcarded does not exist. Range constraints are ideal for selecting ranges, e.g. num GT x AND num LT y, but not suited for mid-string matches.

    I think you'll have to create a word or value constraint for the same path to be able to use wildcards on it. Unfortunately, you can't just create a word or value constraint on a path as specific as you have in your collectionId constraint. You'd have to create a field with that path.

    HTH!