The total is 2 because that's how many documents match the searchable part of your query. You could try using xdmp:plan or xdmp:query-trace to see more of what's happening. It might also help to tell us the full version string for the server release you're using, so we know what features are available and what bugs might be present.
A trailing wildcard index can handle terms like "fuba*". But it isn't much help with "fub*r" because that isn't a trailing wildcard term. See https://docs.marklogic.com/guide/search-dev/wildcard – and consider using the recommended configuration from https://docs.marklogic.com/guide/search-dev/wildcard#id_14163 for general-purpose wildcard search. However from what you've shown us of your use-case you might be better off with a more specialized approach. You might get automatic expansion with an element-word lexicon, if the version you're using can do that. Or you could implement a custom constraint with https://docs.marklogic.com/cts:value-match and an element range index. Don't let that idea scare you: custom constraints aren't nearly as difficult as they sound. -- Mike On 11 Sep 2014, at 19:43 , Gary Russo <[email protected]> wrote: > I have a tiny database containing 4 documents with trailing wildcard search > options enabled. > > See Code Snippet #2 below for the data load script. > > Using Query Console, the following wildcard search code snippet returns a > total value of 2 when it should only be 1. > > I’m sure that I’m missing something obvious. Hopefully another pair of eyes > can spot it quickly. > > > Code Snippet 1: Leading Wildcard Search > > import module namespace search = "http://marklogic.com/appservices/search" > at "/MarkLogic/appservices/search/search.xqy"; > > declare variable $DN := "http://demo.org/demo"; > > let $options := > <options xmlns="http://marklogic.com/appservices/search"> > <search-option>unfiltered</search-option> > <return-constraints>true</return-constraints> > <term> > <term-option>wildcarded</term-option> > </term> > <constraint name="ImportedUnitCode"> > <value> > <element ns="http://demo.org/demo" name="ImportedUnitCode"/> > </value> > </constraint> > <sort-order type="xs:string" collation="http://marklogic.com/collation/" > direction="ascending"> > <element ns="http://demo.org/demo" name="ImportedUnitCode"/> > </sort-order> > </options> > > let $q := "ImportedUnitCode:RU000*4" > > let $results := search:search($q, $options) > > return > ($results/search:result//search:highlight/text(), $results) > > > > Code Snippet 2: Data Load > > declare variable $data := > <file name="record1.xml"> > <record xmlns="http://demo.org/demo"> > <Id type="number">999</Id> > <ImportFileId type="number">1</ImportFileId> > <ImportedUnitCode type="string">RU00999</ImportedUnitCode> > <ImportedAccountCode type="string">AC00002</ImportedAccountCode> > <BeginningBalance type="number">0</BeginningBalance> > <EndingBalance type="number">1374.63552475657</EndingBalance> > </record> > </file>, > <file name="record2.xml"> > <record xmlns="http://demo.org/demo"> > <Id type="number">499</Id> > <ImportFileId type="number">2</ImportFileId> > <ImportedUnitCode type="string">RU00499</ImportedUnitCode> > <ImportedAccountCode type="string">AC00502</ImportedAccountCode> > <BeginningBalance type="number">0</BeginningBalance> > <EndingBalance type="number">8524.31456955351</EndingBalance> > </record> > </file>, > <file name="record3.xml"> > <record xmlns="http://demo.org/demo"> > <Id type="number">99</Id> > <ImportFileId type="number">3</ImportFileId> > <ImportedUnitCode type="string">RU00099</ImportedUnitCode> > <ImportedAccountCode type="string">AC00902</ImportedAccountCode> > <BeginningBalance type="number">0</BeginningBalance> > <EndingBalance type="number">7170.55131083846</EndingBalance> > </record> > </file>, > <file name="record4.xml"> > <record xmlns="http://demo.org/demo"> > <Id type="number">4</Id> > <ImportFileId type="number">4</ImportFileId> > <ImportedUnitCode type="string">RU00004</ImportedUnitCode> > <ImportedAccountCode type="string">AC00997</ImportedAccountCode> > <BeginningBalance type="number">0</BeginningBalance> > <EndingBalance type="number">3041.22115626988</EndingBalance> > </record> > </file>; > > $data/xdmp:document-insert(@name, *), > $data!fn:string-join((.//*:ImportedUnitCode,.//*:ImportedAccountCode,.//*:Id), > " ") > > > > > Gary Russo > Thomson Reuters > Enterprise NoSQL Developer > http://twitter.com/garyprusso > > > _______________________________________________ > General mailing list > [email protected] > http://developer.marklogic.com/mailman/listinfo/general _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
