Hi Sam, thanks so much for your code example, the above code is what I am looking for.
On Tue, Feb 24, 2015 at 12:18 AM, Sam Mefford <[email protected]> wrote: > Ah well, my last reply was redundant as you seem to have found the > answer yourself. Good on you! > > Here's an update with a working sample. Notice I changed > search:constraint to search:values. And notice I pass the options name > to the newValuesDefintion method. > > import com.marklogic.client.DatabaseClientFactory; > import static > com.marklogic.client.DatabaseClientFactory.Authentication.DIGEST; > import com.marklogic.client.DatabaseClient; > import com.marklogic.client.admin.QueryOptionsManager; > import com.marklogic.client.query.CountedDistinctValue; > import com.marklogic.client.query.QueryManager; > import com.marklogic.client.query.ValuesDefinition; > import com.marklogic.client.io.StringHandle; > import com.marklogic.client.io.ValuesHandle; > > public class Test { > public static void main(String[] args) { > DatabaseClient client = DatabaseClientFactory.newClient("localhost", > 8000, "admin", "admin", DIGEST); > > QueryOptionsManager optionsMgr = > client.newServerConfigManager().newQueryOptionsManager(); > > // construct the query options > String optionXml = > "<search:options "+ > > "xmlns:search='http://marklogic.com/appservices/search'>"+ > "<search:values name='country'>"+ > "<search:range > collation='http://marklogic.com/collation/' type='xs:string' facet='true'>"+ > > "<search:facet-option>frequency-order</search:facet-option>"+ > > "<search:facet-option>descending</search:facet-option>"+ > "<search:facet-option>limit=10</search:facet-option>"+ > "<search:element ns='' name='country'/>"+ > "</search:range>"+ > " </search:values>"+ > "</search:options>"; > > // create a handle to send the query options > StringHandle writeHandle = new StringHandle(optionXml); > > // write the query options to the database > optionsMgr.writeOptions("myOptions", writeHandle); > QueryManager queryMgr = client.newQueryManager(); > ValuesDefinition query = queryMgr.newValuesDefinition("country", > "myOptions"); > ValuesHandle values = queryMgr.values(query, new ValuesHandle()); > for (CountedDistinctValue value : values.getValues() ) { > String textValue = value.get("xs:string", String.class); > System.out.println(textValue + " " + value.getCount()); > } > } > } > > > Sam Mefford > Senior Engineer > MarkLogic [email protected] > Cell: +1 801 706 9731www.marklogic.com > > This e-mail and any accompanying attachments are confidential. The > information is intended > solely for the use of the individual to whom it is addressed. Any review, > disclosure, copying, > distribution, or use of this e-mail communication by others is strictly > prohibited. If you > are not the intended recipient, please notify us immediately by returning > this message to > the sender and delete all copies. Thank you for your cooperation. > > On 2/22/2015 10:58 PM, Maisnam Ns wrote: > > Hi, > > Can someone help me on creating the query options , the first one using > > 1. QueryOptionsBuilder in Java API works but with xml it is not working, > the result I am getting is > > 1. US 100 > 2. JP 49 > 3. ES 23 > > Basically , I am getting the country and the counts . > > QueryOptionsBuilder qob = new QueryOptionsBuilder(); > > // expose the "SPEAKER" element range index as "speaker" values > QueryOptionsHandle options = new QueryOptionsHandle().withValues( > qob.values("country", > qob.range( > qob.elementRangeIndex(new QName("country"), > > qob.stringRangeType(QueryOptions.DEFAULT_COLLATION))), > "frequency-order")); > > > 2. QueryOptionsManager optionsMgr = > client.newServerConfigManager().newQueryOptionsManager(); > > // construct the query options > String optionXml = > "<search:options "+ > "xmlns:search=' > http://marklogic.com/appservices/search'>"+ > "<search:constraint name='country'>"+ > "<search:range collation=' > http://marklogic.com/collation/' type='xs:string' facet='true'>"+ > "<search:facet-option>frequency-order</ > search:facet-option>"+ > "<search:facet-option>descending</ > search:facet-option>"+ > "<search:facet-option>limit=10</ > search:facet-option>"+ > "<search:element ns='' name='country'/>"+ > "</search:range>"+ > " </search:constraint>"+ > "</search:options>"; > > // create a handle to send the query options > StringHandle writeHandle = new StringHandle(optionXml); > > // write the query options to the database > optionsMgr.writeOptions(OPTIONS_NAME, writeHandle); > QueryManager queryMgr = client.newQueryManager(); > > > _______________________________________________ > General mailing > [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
