Right.  So, after looking through much of the code from the app builder app:

I created my own service (doing the search:suggest in the appropriate DB) based 
on what I found in: /marklogic.rest.resource/extsuggest/lib/resource.xqy

I then changed my copy of search.xqy to call this service instead of the REST 
api - actually only two lines had to change.

My service is definitely not as good as resource.xqy - there's some error 
handling that I don't do (i.e., possibly don't understand... :)) - some of the 
completions look goofy when I put a space in; etc....  but, in general it works.

Essentially HTML is the same as what's below, except for the fact that I had to 
get a copy of controller and widget and stick in there too:

  <script src="application/lib/controller.js" type="text/javascript"></script>
  <script src="application/lib/widget.js" type="text/javascript"></script>
  <script src="application/lib/viz/search/search.js" 
type="text/javascript"></script>

Now I just have to figure out how to merge this sample HTML with my app's HTML 
and hopefully I'll have something that'll demonstrate appropriately.  This will 
be figuring out how to execute a search from this instead of what I currently 
have, which is a form...

Thanks again,
David

From: [email protected] 
[mailto:[email protected]] On Behalf Of Colleen Whitney
Sent: Friday, December 13, 2013 11:13 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Lifting a portion of App Builder app to 
use in a different place

Ah, David, I think this is where the lines are getting tangled.

If your other environment is not a REST server instance, then this will not 
work.  A REST instance is an HTTP server that has a particular configuration, 
including a Modules database (where search configuration and extensions are 
stored), a rewriter, and an error handler, all of which work together to 
provide the services that come preconfigured.

If you're standing up your own application and not using the REST API 
underneath, then you can set up a main module that calls search:suggest() to 
service AJAX requests from your front end.

--Colleen

________________________________
From: 
[email protected]<mailto:[email protected]>
 [[email protected]] on behalf of Steiner, David J. 
(LNG-DAY) [[email protected]]
Sent: Thursday, December 12, 2013 10:18 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Lifting a portion of App Builder app to 
use in a different place
Thanks Colleen and Tim.  I will check them out...

There's still one thing that I'm uncertain about.  I understand that I can 
install extensions and create configurations in the "other" environment, which 
already has an appserver and uses the file system for a modules DB.  However, 
I'm not sure I understand how I'm actually "hitting" the DB in the original 
environment with these extensions.  Is there a way to specify the host and the 
DB that you want to use the extension with?  Because the DB that's associated 
with the app server is not the DB that has the suggestions in it.

David

From: 
[email protected]<mailto:[email protected]>
 [mailto:[email protected]] On Behalf Of Colleen Whitney
Sent: Thursday, December 12, 2013 11:38 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Lifting a portion of App Builder app to 
use in a different place

Hi David,

There are 3 parts to the suggestion feature.

 One is the Javascript portion, which handles the user interface portion.

The second is the XQuery portion;  in REST API terms it is an extension.  If 
you look at documentation for how to install and manage extensions, you'll find 
instructions on how to install extensions.  You can take the module from App 
Builder and install it in the other environment.

The third is a small bit of configuration that associates the suggestion 
capability with the range index or field that you want to derive suggestions 
from.  When the App Builder deploys an application, it stores a set of search 
options that includes the necessary bit of configuration. You can look at a 
list of stored options configurations at /v1/config/query (GET); I believe that 
you want "all" (odd naming, but that's what App Builder does).  You can store a 
similar set of search options in your target environment to drive your 
suggestion interface.

And Tim is right, RoXY does have some nice conveniences for working with REST 
extensions.

--Colleen

________________________________
From: 
[email protected]<mailto:[email protected]>
 [[email protected]] on behalf of Steiner, David J. 
(LNG-DAY) [[email protected]]
Sent: Thursday, December 12, 2013 8:12 AM
To: MarkLogic Developer Discussion
Subject: [MarkLogic Dev General] Lifting a portion of App Builder app to use in 
a different place
I built an app using App Builder and I also have a separate app that I built by 
just using xquery, html, jquery javascript, etc....

The separate app operates on a database that is different from the one that the 
App Builder app operates on.  However, I'd like to incorporate the "search 
suggestion" of the App Builder app in my separate app.

I found the code for the suggestion in "search.js".

I see that there is an endpoint in it for the search suggestion: 
/v1/resources/extsuggest" + '?rs:pqtxt='

Ideally, I guess, I'd like to be able to incorporate the appropriate HTML, 
javascript and css in my separate app, add the 
http://host:port/<UrlBlockedError.aspx> to the front of the endpoint and have 
the suggestion just work.

Has anyone ever attempted this?

I can also write a service that would replicate what the suggestion endpoint is 
doing, but I'd rather not if I don't have to, so if anyone has any experience 
in doing this, I'd appreciate the guidance.  By the way, I started the service 
and I'm sure that it'll have to do something different since it appears that 
there are extra backslashes and quotes that need to be inserted to make it good 
json (I noticed this by looking at the difference between my output and the 
output of the app builder extension?

I've already gotten this far in my test page, which I've created just to see if 
I can get the suggestion to work.  I tried sticking the fully qualified 
location in the suggestEndpoint variable (i.e., adding 
http://host:port<UrlBlockedError.aspx> to the front of the url) in search.js 
and nothing really happened, so I'm assuming that perhaps there's configuration 
stuff that I'm skipping, or possibly a wide variety of things that are 
missing...

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Title</title>
  <link rel="stylesheet" 
href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css";>
  <link type="text/css" rel="stylesheet" 
href="application/lib/viz/search/search.css" media="screen, print"/>
  <script src="http://code.jquery.com/jquery-1.9.1.min.js";></script>
  <script 
src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js";></script>
  <script src="application/lib/viz/search/search.js" 
type="text/javascript"></script>
</head>
<body>
<div data-role="page" data-theme="d" id="myPage">
        <div data-role="header">
                <h1>Header.</h1>
        </div>
        <div class="content-primary">
           <div id="search" class="search widget"></div>
        </div>
        <div class="content-secondary">
        </div>
</div>
</body>
<script>
var search = ML.createSearch("search");
</script>
</html>

Thanks for any help,
David
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to