1

I am trying to build a typeahead/suggestion feature similar to the one developed using App Builder.

My XQuery is:

xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"
    at "/MarkLogic/appservices/search/search.xqy";
let $options := 
<options xmlns="http://marklogic.com/appservices/search">
<additional-query>{cts:and-query((cts:collection-query("NY"),cts:element-value-query(xs:QName("Office"),"47","exact"),cts:element-value-query(xs:QName("Person"),"15","exact")))}
 </additional-query>
 <constraint name="Search_Element">
 <range collation="http://marklogic.com/collation/" 
          type="xs:string" >
      <element name="Account"/>
   </range>
   </constraint>
 <suggestion-source ref="Search_Element">
   <range collation="http://marklogic.com/collation/" 
          type="xs:string" facet="true" >
      <element name="NUM_ACCT"/>
   </range>
 </suggestion-source>
 </options>
return    
search:suggest("Search_Element:103", $options)

This returns the desired suggestions. But, now when i wish to integrate this in UI, I am unable to understand how it could be implemented.

  1. REST API doesnt seem to be rich enough for above query as its does key/value, element value search etc.I want to implement typehead for instance,for account element in NY collection,for a particular office-person element values as in the above XQUERY

  2. The App Builder uses extsuggest extension, but i could not get much information on this.

I have a text box, which on typeahead, will query marklogic server via REST or JSON/XML wayaround whichever can be implemented and display the results. I am currently trying to use AngularJS typeahead feature as given here. Please Advise !!!

Shrey Shivam
  • 1,107
  • 1
  • 7
  • 16

3 Answers3

2

From the looks of it, the extsuggest extension is just a convenience wrapper around search:suggest, mainly to easily get hold of the search options of an App Builder app, and returning any results as JSON.

Otherwise I am a little confused by your question. You say the above code gives the correct suggestions, but the second paragraph below the code seems to indicate it doesn't?

Or is your problem that you have correct suggestions, but don't know how to visualize them in the UI?

HTH!

grtjn
  • 20,254
  • 1
  • 24
  • 35
2

To your first point about the REST API, you put the XQuery code above in a REST extension, as described here. If you call it "suggest", you'll end up accessing it at /v1/resources/suggest.

I'm not clear on your overall architecture, but you mentioned AngularJS and XCC for Java, so I'm guessing you have something like Tomcat serving up the UI and implementing business logic, with Java using XCC to talk to MarkLogic to get data. (An aside: since you're using the REST API, you might want to go with the MarkLogic Java API, which sits on top of the REST API.)

From the AngularJS side, the typeahead is going to need to work with a service that sends what has been typed so far back to your Java server, which will forward the request onto the MarkLogic endpoint. I found another StackOverflow question that shows how to set up the directive to send the request to a server.

Community
  • 1
  • 1
Dave Cassel
  • 8,352
  • 20
  • 38
  • I worked around with REST for sometime and I wasnt able to develop above query as I believe REST doesnot support for instance,localhost:8011/v1/keyvalue?element=Person&value=15**&element=abc&value=xyz‌​**&collection=NY ...code supports just 1 element parameter but, i need to apply filter on office,person,collection and then search on the account element.Hence I thought of using XCC which works well by executing the XQUERY.And yes, I have something like tomcat for Ui on AngularJS and using XCC to talk to ML.let me see the REST extension, will get back soon !!! – Shrey Shivam Nov 07 '13 at 06:07
1

The REST API in V7 has suggestions built in. You can access that directly.

http://docs.marklogic.com/REST/GET/v1/suggest

One of the things I've not yet covered in my MLJS JavaScript wrapper for MarkLogic[1] is auto suggest for the text search query bar widget. I have built this for the semantic (SPARQL) query bar widget though. If you're writing in JavaScript, MLJS has all the hard work done for you. Easy to plug in new rest functions of your own using the mljs core API's do() function. There's also a search widget API too.

[1] https://github.com/adamfowleruk/mljs/blob/master/README.md

adamfowleruk
  • 257
  • 2
  • 10