I have the following XQuery which I use to fetch documents for a directory.
xquery version "1.0-ml";
cts:search(fn:collection(), cts:directory-query("/Path/To/Docs/", "infinity"))
Now I need to translate this into a REST call but I can't seem to crack it following the documentation on this page.
https://docs.marklogic.com/REST/GET/v1/search
Update:
using the Jersey REST API, It tried this but got 406 Error
String query = "{\"queries\":[ {\"directory-query\":{\"uri\":[\"/Path/to/Docs/\"]},\"infinite\":true} ]}";
String encodedQuery = URLEncoder.encode(query, "UTF-8");
WebTarget target = searchWebTarget.queryParam("structuredQuery", encodedQuery);
final Response response = target.request().get();
Any ideas?
As David said, you don't need to use structured query for this purpose, but in case you have future need:
I believe your original issue was that this is not a well-formed structured query:
{\"queries\":[ {\"directory-query\":{\"uri\":[\"/Path/to/Docs/\"]},\"infinite\":true} ]}
You're missing the top level "query" property. You can find an example of a fully formed structured query that uses directory-query here:
http://docs.marklogic.com/guide/search-dev/structured-query#id_97452
Also, you're probably already aware, but there is a native Java API that sits atop the REST API. You can learn more about this API here:
https://docs.marklogic.com/javadoc/client/index.html
http://docs.marklogic.com/guide/java
Constraining by directory is a query parameter directly on the search API. NO other notation needed.
See the docs here: https://docs.marklogic.com/REST/GET/v1/search
Related
I'm using the latest version of the here javascript sdk 3.1.32.0
When I use H.service.Url.MultiValueQueryParameter for my via points like
{
...,
via: new H.service.Url.MultiValueQueryParameter(['50.1234,8.7654', '51.2234,9.1123']);
}
I see in the URL params of my request this: &via=%5Bobject%20Object%5D
Someone an idea why this happens?
Thanks in advance!
When you use "via" parameter, you define a list of via waypoints. A via waypoint is not a native datatype recongnized by JavaScript, therefore, you will see in the URL params the word object refering to a particular data structure, in this case the via Waypoint composed mainly by Latitude, Longitude.
Regards.
This took a while to figure out the actual issue with the malformed url params. I was dynamically loading the here maps service script on mount of a component. Accidentally this happened in some cases twice. In both cases H was globally available and everything worked like expected. BUT when the script was loaded twice H.service.Url.MultiValueQueryParameter didn't return the correct params. It basically encoded them twice, or tried to.
The other side issue was that https://www.npmjs.com/package/#types/heremaps is outdated and doesn't cover MultiValueQueryParameter. So I had to remove the types and use my own. Else I probably would have realized the issue earlier.
I want to list all users that have OneDrive license.
I an using this URL but doesn't work.
https://graph.microsoft.com/v1.0/users?$filter=assignedLicenses/any(x:x/skuId eq 4b585984-651b-448a-9e53-3b10f069cf7f or x/skuId eq c7df2760-2c81-4ef7-b578-5b5392b571df)
Do you have any idea how to do it?
Unfortunately complex query (Whatever you're trying to do above) on property assignedLicenses is not supported. If you do so, the API will throw the error:
Complex query on property assignedLicenses is not supported
Being said that i can see it
works for simple filter, like,
https://graph.microsoft.com/v1.0/users?$filter=assignedLicenses/any(x:x/skuId eq 4b585984-651b-448a-9e53-3b10f069cf7f)
I try to manipulate a CosmosDB (SQL) using entity framework core 3.0 (Microsoft.EntityFrameworkCore.Cosmos 3.0.0).
Everything works fine except when I try to use Contains, StartWith, …
For example:
var query = _context.Challenges.Where(c => c.Name.Contains( "string"));
EF is supposed to translate it to the following SQL (that works perfectly on the CosmosDB – Query Explorer)
SELECT * FROM c WHERE CONTAINS(c.Name, "string")
But I receive the following error message:
The LINQ expression 'Where<Challenge>(\n source: DbSet<Challenge>, \n predicate: (c) => c.Name.Contains(\"string\"))' could not be translated.
Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync().
See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
Of course, I don’t want to code it like the following, that will execute the entire contains on the client, just to make a simple LIKE…
List<Challenge> entities = _context.Challenges.AsEnumerable().Where(c => c.Name.Contains( "string")).ToList();
Anyone has an idea of to evaluate the "contains" on the server side ?
Note: I try the exact same code using UseSqlServer rather than UseCosmos (and by adding the needed [Key] annotation and creating a SQL server) and it works like a charm.... So it's a definitively a CosmosDB vs EF issue.
By posting the same issue on entity framework core forum (https://github.com/aspnet/EntityFrameworkCore/), the answer was that this feature is not yet implemented:
https://github.com/aspnet/EntityFrameworkCore/issues/18673
https://github.com/aspnet/EntityFrameworkCore/issues/16143
https://github.com/aspnet/EntityFrameworkCore/issues/18451
https://feedback.azure.com/forums/263030-azure-cosmos-db/suggestions/6333414-implement-like-keyword
First time using api-platform and Symfony 4 to create an API interface for a MySQL db.
I'm updating an old search interface for the db for which I need to replicate many of the search options. This includes being able to search on a given field using various matching operators/strategies. e.g. starts with, contains exactly equals, etc.
I've set everything up for the api using Annotations.
The #ApiFilter(SearchFilter::class, properties={"fieldname": "strategy"} annotation on my table class works as designed, but I am limited to one-and-only-one strategy per field. I need to be able to pass the strategy to the api search function in the url. something like:
/api/staff?lastname[start]=dav
or
/api/staff?lastname=david&match=contains
or
/api/staff/lastname/son?searchtype=end
would be fine.
I can't figure out how to set this up. Shockingly, to me anyway, this common requirement doesn't seem to be documented at all.
The file CustomSearchFilter.php located at the repo https://github.com/jordonedavidson/custom_search_filter solves this use-case using the
/api/staff?lastname[start]=dav
syntax.
The file was written by Kévin Dunglas (the author of Api Platform) and is presented with his blessing.
I am new to MarkLogic and we are evaluating MarkLogic for our product use case.
We evaluated few NoSQL databases like MongoDB, Couchbase etc.
I am looking for a below type of query search.
(Condition1 OR Condition2) AND (Condition3 OR Condition4) AND (Condition5)
Can MarkLogic provide such type of search query?
I am just started learning MarkLogic and trying to understand the architecture.
Thanks,
Sameer
Yes, MarkLogic provides some high level libraries for this type of functionality. Take a look at Search API.
Start here: https://developer.marklogic.com/learn/2009-07-search-api-walkthrough
And more thorough documentation is here: https://docs.marklogic.com/guide/search-dev/search-api
MarkLogic can handle this kind of logic in many ways as mentioned.
For example, this is how you could setup a search query using the CTS library (I highly recommend the CTS library, since it uses indexes much better, and the construction of them are so much more flexible):
cts:search(//elementName,
cts:and-query((
cts:element-attribute-value-query(xs:QName("entry"), xs:QName("private"), "true"),
cts:or-query((
cts:element-attribute-value-query(xs:QName("entry"), xs:QName("forced"), "false"),
cts:element-attribute-value-query(xs:QName("entry"), xs:QName("forced"), "pending")
))
))
)
This snippet shows both AND and OR logic. The cts:and-query() and cts:or-query() functions can take a list of nodes. The above query says: "Find an element (called elementName) that has an attribute of private='true' AND has either one of the following: forced='true' or forced='pending'".
For much simpler data, you can use xQuery predicates by doing something like the following:
for $node in $xml/parent/child[#param1 eq "test" AND #param2 eq "OK"]/grandchild[#service eq "yahoo" or #service eq "google"]
return $node
The short answer to the original question is "yes". The details of "how" will depend on the approach used to express the queries.
The reference architecture recommends a three-tier approach using the Java or Node.js Client APIs if you use one of those, or HTTP calls to the REST API if you use a different language in your middle tier.
You can also use the Search API (as mentioned by wst) if you're working in MarkLogic's application server (typically as a two-tier architecture). You can do that with either XQuery or Server-side JavaScript, as of MarkLogic 8.