You have been redirected from an outdated version of the article. Below is the content available on this topic. To view the old article click here.

Advanced Queries: Exact Search

Using exact search, you can search for a list of objects using the exact value you want the search field to contain. We look for a file with the name test1.txt first.

$ curl -si -HX-User:admin -HX-Password:admin "http://localhost:8082/structr/rest/files?name=test1.txt"

Response:

HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=xkn5bvu0vt3h124xf8c9w7a8x;Path=/
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: application/json; charset=utf-8
Vary: Accept-Encoding, User-Agent
Transfer-Encoding: chunked
Server: Jetty(9.1.3.v20140225)

{
   "query_time": "0.004941183",
   "result_count": 1,
   "result": [
      {
         "type": "File",
         "name": "test1.txt",
         "contentType": "text/plain",
         "size": 1,
         "url": null,
         "owner": {
            "type": "User",
            "name": "admin",
            "salutation": null,
            "firstName": null,
            "middleNameOrInitial": null,
            "lastName": null,
            "id": "f02e59a47dc9492da3e6cb7fb6b3ac25"
         },
         "path": "/test1.txt",
         "id": "e9545499d9144aada64909d9106c99d1"
      }
   ],
   "serialization_time": "0.000527189"
}

Exact search can of course return multiple results:

$ curl -si -HX-User:admin -HX-Password:admin "http://localhost:8082/structr/rest/files?contentType=text/plain"

Response:

HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=1c2jh95zjoggf1pylyfodp4t9u;Path=/
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: application/json; charset=utf-8
Vary: Accept-Encoding, User-Agent
Transfer-Encoding: chunked
Server: Jetty(9.1.3.v20140225)

{
   "query_time": "0.005492747",
   "result_count": 5,
   "result": [
      {
         "type": "File",
         "name": "test0.txt",
         "contentType": "text/plain",
         "size": 0,
         "url": null,
         "owner": {
            "type": "User",
            "name": "admin",
            "salutation": null,
            "firstName": null,
            "middleNameOrInitial": null,
            "lastName": null,
            "id": "f02e59a47dc9492da3e6cb7fb6b3ac25"
         },
         "path": "/test0.txt",
         "id": "2790ed17fce146f58b59f85cce8416f6"
      },
      {
         "type": "File",
         "name": "test1.txt",
         "contentType": "text/plain",
         "size": 1,
         "url": null,
         "owner": {
            "type": "User",
            "name": "admin",
            "salutation": null,
            "firstName": null,
            "middleNameOrInitial": null,
            "lastName": null,
            "id": "f02e59a47dc9492da3e6cb7fb6b3ac25"
         },
         "path": "/test1.txt",
         "id": "e9545499d9144aada64909d9106c99d1"
      },
      {
         "type": "File",
         "name": "test2.txt",
         "contentType": "text/plain",
         "size": 2,
         "url": null,
         "owner": {
            "type": "User",
            "name": "admin",
            "salutation": null,
            "firstName": null,
            "middleNameOrInitial": null,
            "lastName": null,
            "id": "f02e59a47dc9492da3e6cb7fb6b3ac25"
         },
         "path": "/test2.txt",
         "id": "f706618d96064049b33765865d206d7b"
      },
      {
         "type": "File",
         "name": "test3.txt",
         "contentType": "text/plain",
         "size": 3,
         "url": null,
         "owner": {
            "type": "User",
            "name": "admin",
            "salutation": null,
            "firstName": null,
            "middleNameOrInitial": null,
            "lastName": null,
            "id": "f02e59a47dc9492da3e6cb7fb6b3ac25"
         },
         "path": "/test3.txt",
         "id": "67de3d9ed3c449c5abb7eac14377b83e"
      },
      {
         "type": "File",
         "name": "test4.txt",
         "contentType": "text/plain",
         "size": 4,
         "url": null,
         "owner": {
            "type": "User",
            "name": "admin",
            "salutation": null,
            "firstName": null,
            "middleNameOrInitial": null,
            "lastName": null,
            "id": "f02e59a47dc9492da3e6cb7fb6b3ac25"
         },
         "path": "/test4.txt",
         "id": "8a85108f688f4097a2633cc7eb2df0e5"
      }
   ],
   "serialization_time": "0.001301977"
}

Or you can search for files using numerical values:

$ curl -si -HX-User:admin -HX-Password:admin "http://localhost:8082/structr/rest/files?size=5"

Response:

HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=w22w8i0yyy2y811h3fhfn3nk;Path=/
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: application/json; charset=utf-8
Vary: Accept-Encoding, User-Agent
Transfer-Encoding: chunked
Server: Jetty(9.1.3.v20140225)

{
   "query_time": "0.004543886",
   "result_count": 1,
   "result": [
      {
         "type": "File",
         "name": "test5.html",
         "contentType": "text/html",
         "size": 5,
         "url": null,
         "owner": {
            "type": "User",
            "name": "admin",
            "salutation": null,
            "firstName": null,
            "middleNameOrInitial": null,
            "lastName": null,
            "id": "f02e59a47dc9492da3e6cb7fb6b3ac25"
         },
         "path": "/test5.html",
         "id": "b17269ac328248819d03051edbff7028"
      }
   ],
   "serialization_time": "0.000345816"
}

To use inexact search, set the request parameter loose=1. In the following example, we look for files with the number “1” in the name, which should return file1.txt and file10.html.

$ curl -si -HX-User:admin -HX-Password:admin "http://localhost:8082/structr/rest/files?name=1&loose=1"

Response:

HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=zbp76ut1zofm1esf23bya42fd;Path=/
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: application/json; charset=utf-8
Vary: Accept-Encoding, User-Agent
Transfer-Encoding: chunked
Server: Jetty(9.1.3.v20140225)

{
   "query_time": "0.004745825",
   "result_count": 2,
   "result": [
      {
         "type": "File",
         "name": "test1.txt",
         "contentType": "text/plain",
         "size": 1,
         "url": null,
         "owner": {
            "type": "User",
            "name": "admin",
            "salutation": null,
            "firstName": null,
            "middleNameOrInitial": null,
            "lastName": null,
            "id": "f02e59a47dc9492da3e6cb7fb6b3ac25"
         },
         "path": "/test1.txt",
         "id": "e9545499d9144aada64909d9106c99d1"
      },
      {
         "type": "File",
         "name": "test10.html",
         "contentType": "text/html",
         "size": 10,
         "url": null,
         "owner": {
            "type": "User",
            "name": "admin",
            "salutation": null,
            "firstName": null,
            "middleNameOrInitial": null,
            "lastName": null,
            "id": "f02e59a47dc9492da3e6cb7fb6b3ac25"
         },
         "path": "/test10.html",
         "id": "6bcc3051881b450bba4f74dbf855b652"
      }
   ],
   "serialization_time": "0.000647588"
}

You can even query for multiple values in the same field, using ; (semicolon) as a field separator for OR.

$ curl -si -HX-User:admin -HX-Password:admin "http://localhost:8082/structr/rest/files?name=test1.txt;test2.txt"

Response:

HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=4yl2j1j259wbmz03lvz85alj;Path=/
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: application/json; charset=utf-8
Vary: Accept-Encoding, User-Agent
Transfer-Encoding: chunked
Server: Jetty(9.1.3.v20140225)

{
   "query_time": "0.017328418",
   "result_count": 2,
   "result": [
      {
         "type": "File",
         "name": "test1.txt",
         "contentType": "text/plain",
         "size": 1,
         "url": null,
         "owner": {
            "type": "User",
            "name": "admin",
            "salutation": null,
            "firstName": null,
            "middleNameOrInitial": null,
            "lastName": null,
            "id": "f02e59a47dc9492da3e6cb7fb6b3ac25"
         },
         "path": "/test1.txt",
         "id": "c712190737374462a8c7b220e06f5ca7"
      },
      {
         "type": "File",
         "name": "test2.txt",
         "contentType": "text/plain",
         "size": 2,
         "url": null,
         "owner": {
            "type": "User",
            "name": "admin",
            "salutation": null,
            "firstName": null,
            "middleNameOrInitial": null,
            "lastName": null,
            "id": "f02e59a47dc9492da3e6cb7fb6b3ac25"
         },
         "path": "/test2.txt",
         "id": "37b648f875f046aebbab91fad6660710"
      }
   ],
   "serialization_time": "0.006950845"
}

The range search feature allows you to specify range of values which the returned objects must match. This is done using a special parameter format in the URL:

http://localhost:8082/structr/rest/files?size=[3 TO 5]

Since we are using curl on the command line, we need to urlencode the non-URL characters:

$ curl -si -HX-User:admin -HX-Password:admin "http://localhost:8082/structr/rest/files?size=$(urlencode '[3 TO 5]')"

Response:

HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=1rkhi4o8nmzya1356x2oqzbx4s;Path=/
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: application/json; charset=utf-8
Vary: Accept-Encoding, User-Agent
Transfer-Encoding: chunked
Server: Jetty(9.1.3.v20140225)

{
   "query_time": "0.003258328",
   "result_count": 3,
   "result": [
      {
         "type": "File",
         "name": "test3.txt",
         "contentType": "text/plain",
         "size": 3,
         "url": null,
         "owner": {
            "type": "User",
            "name": "admin",
            "salutation": null,
            "firstName": null,
            "middleNameOrInitial": null,
            "lastName": null,
            "id": "f02e59a47dc9492da3e6cb7fb6b3ac25"
         },
         "path": "/test3.txt",
         "id": "498db44cf6af4ade966f72114dd1fe83"
      },
      {
         "type": "File",
         "name": "test4.txt",
         "contentType": "text/plain",
         "size": 4,
         "url": null,
         "owner": {
            "type": "User",
            "name": "admin",
            "salutation": null,
            "firstName": null,
            "middleNameOrInitial": null,
            "lastName": null,
            "id": "f02e59a47dc9492da3e6cb7fb6b3ac25"
         },
         "path": "/test4.txt",
         "id": "420997552b8844ceb65a78bd68bc72fd"
      },
      {
         "type": "File",
         "name": "test5.html",
         "contentType": "text/html",
         "size": 5,
         "url": null,
         "owner": {
            "type": "User",
            "name": "admin",
            "salutation": null,
            "firstName": null,
            "middleNameOrInitial": null,
            "lastName": null,
            "id": "f02e59a47dc9492da3e6cb7fb6b3ac25"
         },
         "path": "/test5.html",
         "id": "b17269ac328248819d03051edbff7028"
      }
   ],
   "serialization_time": "0.000534139"
}

In addition to the various query methods, you can use the HTTP Accept header field to select individual properties in the REST result.

$ curl -si -HX-User:admin -HX-Password:admin -H"Accept:application/json; properties=name,type" "http://localhost:8082/structr/rest/files?name=test1.txt;test2.txt"

Response:

HTTP/1.1 200 OK
Set-Cookie: JSESSIONID=6a32plzqhbat13k60o0n3774a;Path=/
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: application/json; charset=utf-8
Vary: Accept-Encoding, User-Agent
Transfer-Encoding: chunked
Server: Jetty(9.1.3.v20140225)

{
   "query_time": "0.017328418",
   "result_count": 2,
   "result": [
      {
         "name": "test1.txt",
         "type": "File"
      },
      {
         "name": "test2.txt",
         "type": "File"
      }
   ],
   "serialization_time": "0.006950845"
}

Please note that the properties list of the Accept header must not contain spaces.

To support the examples in the following sections, we create a set of test files:
$ curl -si -HX-User:admin -HX-Password:admin -XPOST http://localhost:8082/structr/rest/files -d '{ "name": "test0.txt", "contentType": "text/plain", "size": 0 }'
$ curl -si -HX-User:admin -HX-Password:admin -XPOST http://localhost:8082/structr/rest/files -d '{ "name": "test1.txt", "contentType": "text/plain", "size": 1 }'
$ curl -si -HX-User:admin -HX-Password:admin -XPOST http://localhost:8082/structr/rest/files -d '{ "name": "test2.txt", "contentType": "text/plain", "size": 2 }'
$ curl -si -HX-User:admin -HX-Password:admin -XPOST http://localhost:8082/structr/rest/files -d '{ "name": "test3.txt", "contentType": "text/plain", "size": 3 }'
$ curl -si -HX-User:admin -HX-Password:admin -XPOST http://localhost:8082/structr/rest/files -d '{ "name": "test4.txt", "contentType": "text/plain", "size": 4 }'
$ curl -si -HX-User:admin -HX-Password:admin -XPOST http://localhost:8082/structr/rest/files -d '{ "name": "test5.html", "contentType": "text/html", "size": 5 }'
$ curl -si -HX-User:admin -HX-Password:admin -XPOST http://localhost:8082/structr/rest/files -d '{ "name": "test6.html", "contentType": "text/html", "size": 6 }'
$ curl -si -HX-User:admin -HX-Password:admin -XPOST http://localhost:8082/structr/rest/files -d '{ "name": "test7.html", "contentType": "text/html", "size": 7 }'
$ curl -si -HX-User:admin -HX-Password:admin -XPOST http://localhost:8082/structr/rest/files -d '{ "name": "test8.html", "contentType": "text/html", "size": 8 }'
$ curl -si -HX-User:admin -HX-Password:admin -XPOST http://localhost:8082/structr/rest/files -d '{ "name": "test9.html", "contentType": "text/html", "size": 9 }'
$ curl -si -HX-User:admin -HX-Password:admin -XPOST http://localhost:8082/structr/rest/files -d '{ "name": "test10.html", "contentType": "text/html", "size": 10 }'

Note: Structr uses the Lucene search engine which is embedded into Neo4j.

Search results for "Advanced Queries: Exact Search"

We could not find anything matching "Advanced Queries: Exact Search" in our documentation. Please rephrase your search.

You can also ask your questions in the Structr Google Group or create a free account in the Structr Support Portal.
Click here to send feedback to the Structr team.