Search by Key (primary index)

Document.Key is unique per Bucket. Furthermore Documents are stored sorted (byte ordered) by its Key values, so you can do an exact match query or a range query.

Example of an exact match query by key:

IBucket bucket = siaqodb.Documents["invoices"];
Document doc= bucket.Load("Invoice-324r");

Or if you work directly with POCO objects:

IBucket bucket = siaqodb.Documents["invoices"];
Invoice invoice= bucket.Load<Invoice>("Invoice-324r");

Example of a range query that will load all Documents which has Keys that starts with 'Invoice-3':

using Sqo.Documents;
.....
Query query = new Query();
query.WhereStartsWith("key","Invoice-3");
IList<Document> docs= bucket.Find(query);

Search By Tags (secondary indexes)

Siaqodb gives developers the ability to tag a Document stored, at write time, with one or more queryable values. All tags are automatically indexed and stored also sorted and may have different data types: Int, Long, Float, Double, String, DateTime and Boolean and you do queries via built-in Query methods or using LINQ.

To decorate an object with tags at write time, you can choose to work directly with POCO or with Document.

Example:

Invoice inv = new Invoice { CustomerName = "My Company", InvoiceDate = DateTime.Now, Total = 2390 };
bucket.Store("Invoice-324r",inv, new { industry = "IT" } );

Or using Document:

Invoice inv = new Invoice { CustomerName = "My Company", InvoiceDate = DateTime.Now, Total = 2390 };
Document document = new Document();
document.Key = "Invoice-324r";
document.SetContent<Invoice>(inv);
document.SetTag<string>("industry", "IT");
bucket.Store(document);

Now the invoice document will have a Tag named 'industry' with the value 'IT'.

Example of an exact match query by tag:

Query query = new Query();
query.WhereEqual("industry","IT");
var docs = bucket.Find(query);

or using LINQ:

var linqQ1 = (from Document doc in siaqodb.Documents["invoices"]
    where doc.GetTag<string>("industry") == "IT"
    select doc).ToList();

Example of a range query that will load all Documents that have defined the tag 'year' and their values are between 2012-2016

Query query = new Query();
query.WhereGreaterThanOrEqual("year",2012)
    .WhereLessThanOrEqual("year",2016);
var docs = bucket.Find(query);

or using LINQ:

var linqQ2 = (from Document doc in siaqodb.Documents["invoices"]
    where doc.GetTag<int>("year") >=2012 && doc.GetTag<int>("year") <=2016
    select doc).ToList();

Complex queries

You can combine and use multiple tags in the same query using AND and OR, example using fluent API:

Query query = new Query();
query.WhereLessThan("year", 2014).WhereEqual("customer", "MyCompany");
var query2 = new Query();
query2 .WhereEqual("year", 2017).WhereEqual("customer", "AnotherCompany");
var complexQuery =query.Or(query2);
var docs = bucket.Find(complexQuery); 

or using LINQ:

List<Invoice> invoices = (from Document doc in siaqodb.Documents["invoices"]
    where (doc.GetTag<int>("year") < 2015 && doc.GetTag<string>("customer") == "MyCompany") 
    || (doc.GetTag<int>("year") == 2017 && doc.GetTag<string>("customer") == "AnotherCompany")
    select doc).ToObjects<Invoice>();