Skip to content

Instantly share code, notes, and snippets.

@eedeebee
Last active October 11, 2015 06:08
Show Gist options
  • Select an option

  • Save eedeebee/3815111 to your computer and use it in GitHub Desktop.

Select an option

Save eedeebee/3815111 to your computer and use it in GitHub Desktop.
Search APIs
// TODO: transform for results
jQuery.ajax({
url: host + "/search",
username: "foo:bar",
type: "POST",
data: {
length: 10,
structuredQuery: {
and: [
{
element: "article",
attribute: "year",
equals: 2010
},
{
element: "description",
contains: "pet grooming"
},
{
near:
[{
wordAnywhere: "cat"
},{
wordAnywhere: "puppy dog"
}],
distance, 10
},
{
not: {
element: "keyword",
contains: "fish"
}
}
]
}
}
});
for $result in cts:search(
/article[@year = 2010],
cts:and-query((
cts:element-word-query(
xs:QName("description"), cts:word-query("pet grooming")
),
cts:near-query(
(cts:word-query("cat"), cts:word-query("puppy dog")), 10
),
cts:not-query(
cts:element-word-query(
xs:QName("keyword"), cts:word-query("fish")
)
)
))
)[1 to 10]
return
<p>{
<b>{ string($result/title) }</b>
<i>{ string($result/@date }</i>
(<small>{ cts:score($result) }</small>)
}</p>
// TODO, response transform
jQuery.ajax({
url: host + "/config/query/myopts&format=json",
username: "foo:bar",
type: "POST",
processData: false,
data: Stringify({
options: {
constraint: [
{
name: "article-year",
value: {
element: {
name: "article",
ns: ""
},
attribute: {
name: "year",
ns: ""
}
}
}, {
name: "description",
word: {
element: {
name: "description",
ns: ""
}
}
}, {
name: "keyword",
word: {
element: {
name: "keyword",
ns: ""
}
}
}
]
}
})
});
// when above completes
jQuery.ajax({
url: host + "/search?format=json&pageLength=10&options=myopts",
username: "foo:bar",
type: "POST",
processData: false,
data: Stringify({ "query":
{ and-query:
{ queries : [
{
value-constraint-query: {
constraint-name: "article-year",
value: "2010"
}
},
{
word-constraint-query: {
constraint-name: "description",
text: "pet grooming"
}
},
{
near-query: {
queries : [
{
term-query: {
text: "cat"
}
},
{
term-query: {
text: "puppy dog"
}
}
],
distance: 10
}
},
{
not-query: {
queries : [
element-word-query: {
constraint-name: "keyword",
text: "fish"
}
]
}
},
] }
}
})
});
// TODO, response transform
jQuery.ajax({
url: host + "/config/query/myopts&format=json",
username: "foo:bar",
type: "POST",
processData: false,
data: Stringify({
search: {
query: { and-query:
{ queries : [
{
value-constraint-query: {
constraint-name: "article-year",
value: "2010"
}
},
{
word-constraint-query: {
constraint-name: "description",
text: "pet grooming"
}
},
{
near-query: {
queries : [
{
term-query: {
text: "cat"
}
},
{
term-query: {
text: "puppy dog"
}
}
],
distance: 10
}
},
{
not-query: {
queries : [
element-word-query: {
constraint-name: "keyword",
text: "fish"
}
]
}
},
] }
}
}, {
options: {
constraint: [
{
name: "article-year",
value: {
element: {
name: "article",
ns: ""
},
attribute: {
name: "year",
ns: ""
}
}
}, {
name: "description",
word: {
element: {
name: "description",
ns: ""
}
}
}, {
name: "keyword",
word: {
element: {
name: "keyword",
ns: ""
}
}
}
]
}
}
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment