Chapter 9. Understanding Your Data and How It Gets Used
MarkLogic provides a platform for storing large amounts of heterogeneous data. Understanding what a database holds and how your users interact with it is key to improving the content over time. The first recipe in this chapter shows how to log the searches that your users are running. Based on this information, you can discover gaps in your content or see what provides the best draw to your application. The second recipe analyzes how content is divided among directories, which are likely used to contain logical or physical segments of your data.
Logging Search Requests
Problem
Record searches run by users, in order to build a recommendation system, understand user needs, or determine what type of content to add. The goal is to record more information than the access logs would provide, and perhaps to associate it with user profiles.
Solution
Applies to MarkLogic versions 7 and higher
There are a variety of ways to implement your search feature. If you are using XQuery or JavaScript main modules to provide this capability, as opposed to working with the REST API, then you can combine logging the search parameters with executing the search request.
import
module
namespace
search
=
"http://marklogic.com/appservices/search"
at
"/MarkLogic/appservices/search/search.xqy"
;
let
$
query
:=
xdmp:get-request-field
(
"query"
,
""
)
let
$
parsed
:=
search:parse
(
$
query
)
let
$
user-info
:=
<user>
<!--
username, timestamp,
-->
</user>
let ...
Get MarkLogic Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.