Range Search

From DBSight Full-Text Search Engine/Platform Wiki

Table of contents


Multiple-Choice Query

Some field you want to specify an OR boolean operator for a specific field. For exampe:

status:"new,unassigned"             # "status" field is "new" or "unassigned".

An valid multiple-choice query need to have a valid field name, and quoted string with comma separated values.

Regular Expression Query

All searchable columns can have regular expression support.(since 1.5.5 beta). For example:

+note:{java.*cript}                 # in "note" field, there is words matching regular expression /java.*cript/
 note:{java.*cript}  note:{soft.*}  # in "note" field, there is words matching regular expression /java.*cript/ and /soft.*/
+note:{java.*cript} -note:{soft.*}  # in "note" field exists words matching /java.*cript/, but not /soft.*/

This is only available through "q=...", which uses DBSight query parser.

Numeric Range Query

If "price" is a Keyword, Number type, the grammar will be like this

price:[10,)            #price >= 10
price:[10,14.5]        #price >= 10 and price <= 14.5
price:[10,14.5)        #price >= 10 and price < 14.5
price:(10,14.5]        #price > 10 and price <= 14.5
price:(10,14.5)        #price > 10 and price < 14.5
price:(,9.8]           #price <= 9.8

For Date Range Query, if "updated_at" is a Keyword, "Date"/"DateTime"/"Time" type, the grammar will be like this

updated_at:[2006/03/15,)            #updated_at later or equal to 2006/03/15
updated_at:[2006/03/15,2006/04/15)  #updated_at between 2006/03/15 and 2006/04/15(not inclusive)

This is only available through "q=...", which uses DBSight query parser.

Range Query Can be Combined

price:[10,) updated_at:[2006/03/15,)            #price >= 10 and updated_at later or equal to 2006/03/15
price:[10,) -updated_at:[2006/03/15,)            #price >= 10 and not ( updated_at later or equal to 2006/03/15 )

Faceted Search for Preset Ranges

DBSight provides "Narrow By" functionality. For your field, you can select data like this:

SELECT title, price,
       Budget = CASE price
        WHEN price > 20.00 THEN 'Expensive'
         WHEN price BETWEEN 10.00 AND 19.99 THEN 'Moderate'
         WHEN price < 10.00 THEN 'Inexpensive'
         ELSE 'Unknown'
       END,
FROM titles
  1. You can set "Budget" as a "Keyword" field when indexing.
  2. you can use our "search engine" template, with "narrowBy" option checked.
  3. Configure "Filterable Columns" to include "Budget" column.

Then for each search, users can see how many results are "Expensive", "Moderate", "Inexpensive", or "Unknown".

Location based search

Often, some sites have search like "within 20 miles". How to implement it? Pretty easy.

Assume you have "longitude" and "latitude" field stored in the database, and selected as numbers.

Also, assumed that 1 degree of latitude and longitude is equal to 75 miles (this is actually overestimated)

For search within 20 miles of location (x,y), you can have

 a = x - 20/75  //latitude.minumum
 b = x + 20/75  //latitude.maximum
 c = y - 20/75  //longitude.minumum
 d = y + 20/75  //longitude.maximum

Then you can search

 latitude:(a,b) longitude:(c,d)