Advanced Query Syntax Verification Guide
This document provides comprehensive verification that all advanced query syntax features are supported across:
- Daemon/Server: Core query parsing and execution
- REST API: HTTP endpoints (GET and POST)
- Client Libraries: All language clients (Node.js, Python, PHP, Perl, C++, Rust)
- hanalyzer: Web interface search functionality
- Advanced Filters:
filter_byparameter support
Complete Query Syntax Reference
Inline Directives
You can prepend inline directives to the query text to change daemon-side behavior.
Examples:
q=do:casesensitive Art
q=do:casesensitive title:"Modern Art"
Currently supported:
do:casesensitiveenables case-sensitive matching for terms, phrases, and wildcards.
1. NOT Operator
Syntax: !term or NOT term
Examples:
# Exclude term
q=!apple
q=NOT apple
# In filter_by
filter_by=category:!=Electronics
Verification:
- Daemon parses
!termcorrectly - Daemon parses
NOT termcorrectly - REST API accepts both syntaxes
- All client libraries support both
- hanalyzer search input accepts both
- Works in
filter_byparameter
Test Queries:
# Basic NOT
curl "http://localhost:9200/collections/products/documents/search?q=!apple"
# NOT with AND
curl "http://localhost:9200/collections/products/documents/search?q=laptop AND !apple"
# NOT in filter
curl "http://localhost:9200/collections/products/documents/search?q=*&filter_by=category:!=Electronics"
2. FIELD Query
Syntax: field:value
Examples:
# Text field
q=title:laptop
q=description:computer
# Numeric field
q=price:100
q=quantity:5
# Multiple fields
q=title:laptop description:computer
Verification:
- Daemon supports field-specific search
- Works with string fields
- Works with numeric fields (int32, float)
- Works with boolean fields
- Multiple field queries work
- REST API supports field queries
- All client libraries support field queries
- hanalyzer supports field queries
- Case-sensitive field names
Test Queries:
# Single field
curl "http://localhost:9200/collections/products/documents/search?q=title:laptop"
# Numeric field
curl "http://localhost:9200/collections/products/documents/search?q=price:100"
# Multiple fields
curl "http://localhost:9200/collections/products/documents/search?q=title:laptop description:computer"
# Boolean field
curl "http://localhost:9200/collections/products/documents/search?q=in_stock:true"
3. RANGE Query
Syntax: field:[min TO max] (inclusive) or field:{min TO max} (exclusive)
Examples:
# Inclusive range
q=price:[100 TO 500]
q=created_at:[2024-01-01 TO 2024-12-31]
# Exclusive range
q=price:{100 TO 500}
q=created_at:{2024-01-01 TO 2024-12-31}
# Open-ended ranges
q=price:[100 TO *]
q=price:[* TO 500]
Verification:
- Daemon parses
[min TO max](inclusive) - Daemon parses
{min TO max}(exclusive) - Works with numeric fields (int32, float)
- Works with date/string fields
- Open-ended ranges work
- REST API supports range queries
- All client libraries support range queries
- hanalyzer supports range queries
- Works in
filter_byparameter
Test Queries:
# Inclusive range
curl "http://localhost:9200/collections/products/documents/search?q=price:[100 TO 500]"
# Exclusive range
curl "http://localhost:9200/collections/products/documents/search?q=price:{100 TO 500}"
# Open-ended
curl "http://localhost:9200/collections/products/documents/search?q=price:[100 TO *]"
# In filter_by
curl "http://localhost:9200/collections/products/documents/search?q=*&filter_by=price:[100 TO 500]"
4. WILDCARD Query
Syntax: term*, *term, term*term
Examples:
# Prefix wildcard
q=laptop*
q=title:laptop*
# Suffix wildcard
q=*laptop
q=title:*laptop
# Middle wildcard
q=lap*top
q=title:lap*top
# Multiple wildcards
q=laptop* computer*
Verification:
- Daemon supports prefix wildcards (
term*) - Daemon supports suffix wildcards (
*term) - Daemon supports middle wildcards (
term*term) - Works with field queries (
field:term*) - Multiple wildcards work
- REST API supports wildcards
- All client libraries support wildcards
- hanalyzer supports wildcards
- Performance is acceptable
Test Queries:
# Prefix wildcard
curl "http://localhost:9200/collections/products/documents/search?q=laptop*"
# Suffix wildcard
curl "http://localhost:9200/collections/products/documents/search?q=*laptop"
# Middle wildcard
curl "http://localhost:9200/collections/products/documents/search?q=lap*top"
# Field with wildcard
curl "http://localhost:9200/collections/products/documents/search?q=title:laptop*"
5. REGEX Query
Syntax: field:/pattern/
Examples:
# Basic regex
q=title:/laptop.*computer/
q=title:/[Ll]aptop/
# Case-insensitive
q=title:/laptop/i
# Complex patterns
q=title:/^laptop.*computer$/
q=email:/^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/
Verification:
- Daemon parses regex patterns correctly
- Supports standard regex syntax
- Field-specific regex works (
field:/pattern/) - Case-insensitive flag works (
/pattern/i) - Complex patterns work
- REST API supports regex
- All client libraries support regex
- hanalyzer supports regex
- Error handling for invalid patterns
Test Queries:
# Basic regex
curl "http://localhost:9200/collections/products/documents/search?q=title:/laptop.*computer/"
# Case-insensitive
curl "http://localhost:9200/collections/products/documents/search?q=title:/laptop/i"
# Complex pattern
curl "http://localhost:9200/collections/products/documents/search?q=email:/^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,}$/"
6. FUZZY Query
Syntax: term~ or term~N (where N is edit distance)
Examples:
# Default fuzzy (distance 2)
q=laptop~
q=title:laptop~
# Custom distance
q=laptop~1
q=laptop~3
q=title:laptop~2
# Multiple fuzzy terms
q=laptop~ computer~
Verification:
- Daemon supports default fuzzy (
term~) - Daemon supports custom distance (
term~N) - Works with field queries
- Multiple fuzzy terms work
- Distance limits are enforced
- REST API supports fuzzy
- All client libraries support fuzzy
- hanalyzer supports fuzzy
- Performance is acceptable
Test Queries:
# Default fuzzy
curl "http://localhost:9200/collections/products/documents/search?q=laptop~"
# Custom distance
curl "http://localhost:9200/collections/products/documents/search?q=laptop~2"
# Field with fuzzy
curl "http://localhost:9200/collections/products/documents/search?q=title:laptop~"
7. BOOST Query
Syntax: term^N or term^N.N (where N is boost factor)
Examples:
# Integer boost
q=laptop^2 computer
q=title:laptop^2
# Float boost
q=laptop^2.0 computer
q=laptop^1.5 computer^2.0
# Multiple boosts
q=laptop^2.0 computer^1.5 monitor^3.0
Verification:
- Daemon supports integer boost (
term^N) - Daemon supports float boost (
term^N.N) - Works with field queries
- Multiple boosts work
- Boost values are applied correctly
- REST API supports boost
- All client libraries support boost
- hanalyzer supports boost
- Ranking reflects boost values
Test Queries:
# Integer boost
curl "http://localhost:9200/collections/products/documents/search?q=laptop^2 computer"
# Float boost
curl "http://localhost:9200/collections/products/documents/search?q=laptop^2.0 computer"
# Multiple boosts
curl "http://localhost:9200/collections/products/documents/search?q=laptop^2.0 computer^1.5"
8. Boolean AND/OR
Syntax: term1 AND term2, term1 OR term2
Examples:
# AND operator
q=laptop AND computer
q=title:laptop AND description:computer
# OR operator
q=laptop OR notebook
q=title:laptop OR title:notebook
# Combined
q=(laptop OR notebook) AND computer
q=title:laptop AND (description:computer OR description:pc)
Verification:
- Daemon supports AND operator
- Daemon supports OR operator
- Parentheses for grouping work
- Case-insensitive operators
- Works with field queries
- Complex boolean expressions work
- REST API supports boolean operators
- All client libraries support boolean operators
- hanalyzer supports boolean operators
- Operator precedence is correct
Test Queries:
# AND
curl "http://localhost:9200/collections/products/documents/search?q=laptop AND computer"
# OR
curl "http://localhost:9200/collections/products/documents/search?q=laptop OR notebook"
# Combined with parentheses
curl "http://localhost:9200/collections/products/documents/search?q=(laptop OR notebook) AND computer"
9. Required Term (+)
Syntax: +term
Examples:
# Required term
q=+laptop computer
q=+title:laptop description:computer
# Multiple required
q=+laptop +computer monitor
Verification:
- Daemon supports required term (
+term) - Works with field queries
- Multiple required terms work
- Required terms must be present
- REST API supports required terms
- All client libraries support required terms
- hanalyzer supports required terms
Test Queries:
# Single required
curl "http://localhost:9200/collections/products/documents/search?q=+laptop computer"
# Multiple required
curl "http://localhost:9200/collections/products/documents/search?q=+laptop +computer"
10. Excluded Term (-)
Syntax: -term
Examples:
# Excluded term
q=laptop -apple
q=title:laptop -category:Electronics
# Multiple excluded
q=laptop -apple -microsoft
Verification:
- Daemon supports excluded term (
-term) - Works with field queries
- Multiple excluded terms work
- Excluded terms are filtered out
- REST API supports excluded terms
- All client libraries support excluded terms
- hanalyzer supports excluded terms
Test Queries:
# Single excluded
curl "http://localhost:9200/collections/products/documents/search?q=laptop -apple"
# Multiple excluded
curl "http://localhost:9200/collections/products/documents/search?q=laptop -apple -microsoft"
11. Phrase Query
Syntax: "exact phrase"
Examples:
# Simple phrase
q="laptop computer"
q="high performance"
# Phrase with field
q=title:"laptop computer"
q=description:"high performance laptop"
# Multiple phrases
q="laptop computer" "wireless mouse"
Verification:
- Daemon supports phrase queries (
"phrase") - Preserves word order
- Works with field queries
- Multiple phrases work
- Case-insensitive by default
- REST API supports phrases
- All client libraries support phrases
- hanalyzer supports phrases
- URL encoding works correctly
Test Queries:
# Simple phrase
curl "http://localhost:9200/collections/products/documents/search?q=\"laptop computer\""
# URL encoded
curl "http://localhost:9200/collections/products/documents/search?q=%22laptop%20computer%22"
# Field with phrase
curl "http://localhost:9200/collections/products/documents/search?q=title:\"laptop computer\""
Combined Query Examples
Complex Queries
# Field + Range + Boolean
q=title:laptop AND price:[100 TO 500]
# Fuzzy + Boost + NOT
q=laptop~2^2.0 AND !apple
# Wildcard + Field + Phrase
q=title:laptop* AND description:"high performance"
# Regex + Range + Boolean
q=title:/laptop.*computer/ AND price:[100 TO 500] OR category:Electronics
# Multiple operators
q=(laptop OR notebook)^2.0 AND price:[100 TO 500] AND !apple
filter_by Parameter Support
The filter_by parameter should support all query syntax features:
Filter Operators
| Operator | Example | Description |
|---|---|---|
: | category:Electronics | Exact match |
> | price:>1000 | Greater than |
>= | price:>=1000 | Greater than or equal |
< | price:<1000 | Less than |
<= | price:<=1000 | Less than or equal |
!= | category:!=Electronics | Not equal |
~ | title:~laptop | Contains |
[value1,value2] | category:[Electronics,Computers] | In array |
&& | price:>1000 && in_stock:true | AND operator |
|| | category:Electronics || category:Computers | OR operator |
[min TO max] | price:[100 TO 500] | Range (inclusive) |
{min TO max} | price:{100 TO 500} | Range (exclusive) |
Filter Examples
# Single filter
filter_by=price:>1000
# Multiple filters with AND
filter_by=price:>1000&&category:Electronics
# Multiple filters with OR
filter_by=category:Electronics||category:Computers
# Range filter
filter_by=price:[100 TO 500]
# Complex filter
filter_by=price:>1000&&in_stock:true&&category:Electronics
# Combined with q parameter
q=laptop&filter_by=price:[100 TO 500]&&category:Electronics
Verification Checklist
Daemon/Server
- All query syntax types are parsed correctly
- Query execution returns correct results
- Error handling for invalid syntax
- Performance is acceptable
- Memory usage is reasonable
REST API
- GET endpoint supports all syntax (URL encoded)
- POST endpoint supports all syntax (JSON body)
- Error responses are clear
- Response format is consistent
Client Libraries
- Node.js client supports all syntax
- Python client supports all syntax
- PHP client supports all syntax
- Perl client supports all syntax
- C++ client supports all syntax
- Rust client supports all syntax
- Examples in each client library
hanalyzer (Web Interface)
- Search input accepts all syntax
- Query builder supports all features
- Results display correctly
- Error messages are helpful
- Advanced filter UI supports all operators
- Query examples/help available
Documentation
- API documentation covers all syntax
- Examples for each syntax type
- Quick reference guide
- Troubleshooting guide
- Performance tips
Testing Script
Create comprehensive test suite covering all syntax types:
#!/bin/bash
# test-advanced-queries.sh
BASE_URL="http://localhost:9200"
COLLECTION="test_products"
# Test NOT operator
echo "Testing NOT operator..."
curl -s "$BASE_URL/collections/$COLLECTION/documents/search?q=!apple" | jq .
# Test FIELD query
echo "Testing FIELD query..."
curl -s "$BASE_URL/collections/$COLLECTION/documents/search?q=title:laptop" | jq .
# Test RANGE query
echo "Testing RANGE query..."
curl -s "$BASE_URL/collections/$COLLECTION/documents/search?q=price:[100 TO 500]" | jq .
# Test WILDCARD query
echo "Testing WILDCARD query..."
curl -s "$BASE_URL/collections/$COLLECTION/documents/search?q=laptop*" | jq .
# Test REGEX query
echo "Testing REGEX query..."
curl -s "$BASE_URL/collections/$COLLECTION/documents/search?q=title:/laptop.*computer/" | jq .
# Test FUZZY query
echo "Testing FUZZY query..."
curl -s "$BASE_URL/collections/$COLLECTION/documents/search?q=laptop~2" | jq .
# Test BOOST query
echo "Testing BOOST query..."
curl -s "$BASE_URL/collections/$COLLECTION/documents/search?q=laptop^2.0 computer" | jq .
# Test Boolean AND/OR
echo "Testing Boolean operators..."
curl -s "$BASE_URL/collections/$COLLECTION/documents/search?q=laptop AND computer" | jq .
# Test Required term
echo "Testing Required term..."
curl -s "$BASE_URL/collections/$COLLECTION/documents/search?q=+laptop computer" | jq .
# Test Excluded term
echo "Testing Excluded term..."
curl -s "$BASE_URL/collections/$COLLECTION/documents/search?q=laptop -apple" | jq .
# Test Phrase query
echo "Testing Phrase query..."
curl -s "$BASE_URL/collections/$COLLECTION/documents/search?q=%22laptop%20computer%22" | jq .
# Test Combined queries
echo "Testing Combined queries..."
curl -s "$BASE_URL/collections/$COLLECTION/documents/search?q=title:laptop AND price:[100 TO 500]" | jq .
Next Steps
- Run Verification Tests: Execute test suite against daemon
- Update Documentation: Ensure all features are documented
- Client Library Updates: Verify all clients support all syntax
- hanalyzer Updates: Ensure web UI supports all features
- Performance Testing: Verify performance with complex queries
- Error Handling: Test error cases and edge conditions
Related Documentation
- Search API - Complete search API reference
- Quick Reference - Quick syntax reference
- Examples - Real-world examples
- Web Interface - hanalyzer documentation
- Client Libraries - Client library documentation