Last active
October 11, 2015 06:08
-
-
Save eedeebee/3815111 to your computer and use it in GitHub Desktop.
Search APIs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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" | |
| } | |
| } | |
| ] | |
| } | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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" | |
| } | |
| ] | |
| } | |
| }, | |
| ] } | |
| } | |
| }) | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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