I am trying to implement a search suggest for the app I am building. I tried following the guide found here.
I modified things a bit to work with my database. My options now look like this:
String options =
<options xmlns="http://marklogic.com/appservices/search">
<default-suggestion-source>
<range type="xs:string" facet="true">" +
<element ns="http://marklogic.com/xdmp/dls" name="content"/>
</range>
</default-suggestion-source>
</options>;
The name "content" is the name of the XML element I want to search, and the namespace I wasn't sure about, so I just copied the namespace that was in the default range indexes already in my database.
My Java code is as follows:
StringHandle handle = new StringHandle(options);
QueryManager queryManager = client.newQueryManager();
QueryOptionsManager optMgr = client.newServerConfigManager().newQueryOptionsManager();
optMgr.writeOptions("opt-suggest", handle);
SuggestDefinition suggestionDef = queryManager.newSuggestDefinition();
suggestionDef.setLimit(10);
suggestionDef.setStringCriteria(text);
suggestionDef.setOptionsName("opt-suggest");
String[] suggestions = queryManager.suggest(suggestionDef);
The line setting the options name to the suggestion def I added as it was not in the tutorial. The search returns an empty set every time. Is it because of my namespace? Or am I missing something? FWIW I have tried running it with the namespace shown, and with a blank namespace.
Edit: Sample document:
<Article doctype="article>
<title>Some Name here</title>
<content>
<content type="paragraph">
<value>Some text</value>
</content>
<content type="paragraph">
<value>More text</value>
</content>
</content>
</Article
It works! Sam Mefford's comment about running in the console made me realize it would in fact return results, just not for my search string. I threw some wildcards around the search text and it now works; after adjusting my index and options to search the proper XML element, and leaving the namespace blank.