• Facebook
  • Twitter
  • Youtube
  • LinedIn
  • RSS
  • Docs
  • Comparisons
  • Blogs
  • Download
  • Contact Us
Download
Show / Hide Table of Contents

Interface ISearchService

This interface contains properties and methods required for Search Service.

Assembly: Alachisoft.NCache.Client.dll
Syntax
public interface ISearchService

Methods

ExecuteNonQuery(QueryCommand)

Executes delete statements on cache. Returns number of affected rows after query is executed.

Declaration
int ExecuteNonQuery(QueryCommand queryCommand)
Parameters
Type Name Description
QueryCommand queryCommand

QueryCommand containing query text and values.

Returns
Type Description
System.Int32

Number of rows affected after query is executed.

Remarks

Only Delete Query is supported yet.

These operators are supported by NCache Queries.

  1. Comparison Operators = , == , != , <> , < , > , <=, >=, IN
  2. Logical Operators AND , OR , NOT
  3. Miscellaneous () , DateTime.Now , DateTime("any date time compatible string")
Examples
ICache _cache = CacheManager.GetCache("demoCache");

string query = "delete Test.Application.Employee where this.Name = ?";
QueryCommand queryCommand = new QueryCommand(query);
queryCommand.Parameters.Add("Name", "Paul Jones");
int result = _cache.SearchService.ExecuteNonQuery(queryCommand);

query = "delete Test.Application.Employee where this.Salary > ?";
queryCommand = new QueryCommand(query);
queryCommand.Parameters.Add("Salary", 2000);
result = _cache.SearchService.ExecuteNonQuery(queryCommand);

query = "delete Test.Application.Employee where Not(this.Name = 'Paul Jones' and this.Salary > 2000)";
queryCommand = new QueryCommand(query);
queryCommand.Parameters.Add("Name", "Paul Jones");
queryCommand.Parameters.Add("Salary", 2000);
result = _cache.SearchService.ExecuteNonQuery(queryCommand);

ExecuteReader(QueryCommand, Boolean, Int32)

Performs search on the cache based on the query specified. Returns list of key-value pairs in a data reader which fulfills the query criteria. This key-value pair has cache key and its respective value. You can specify the flag for specifying if you want data with keys.

Declaration
ICacheReader ExecuteReader(QueryCommand queryCommand, bool getData = true, int chunkSize = -1)
Parameters
Type Name Description
QueryCommand queryCommand

QueryCommand containing query text and values.

System.Boolean getData

Flag to indicate whether the resulting values have to be returned with keys or not.

System.Int32 chunkSize

Size of data/keys packets received after search, default value is 512*1024 KB.

Returns
Type Description
ICacheReader

Reads forward-only stream of result sets of the query executed on cache.

Remarks

These operators are supported by NCache Queries.

  1. Comparison Operators = , == , != , <> , < , > , <=, >=, IN
  2. Logical Operators AND , OR , NOT
  3. Miscellaneous () , DateTime.Now , DateTime("any date time compatible string")
Examples
ICache cache = CacheManager.GetCache("demoCache");

Instead of Product, specify fully qualified name of your custom class.

string query = "SELECT Product where this.ProductName = ?";

QueryCommand queryCommand = new QueryCommand(query);
queryCommand.Parameters.Add("ProductName", "Chai");
queryCommand.Parameters.Add("UnitsInStock", 250);

try
{
    ICacheReader reader = cache.SearchService.ExecuteReader(queryCommand, true, 50);
    if (reader.FieldCount > 0)
    {
        while (reader.Read())
        {
            object category = reader.GetValue<object>(0);
            //perform operations
        }
    }
    else
    {
        //perform operations
    }
    reader.Close();
}

catch
{
    //handle exception
}

ExecuteScalar(QueryCommand)

Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.

Declaration
object ExecuteScalar(QueryCommand queryCommand)
Parameters
Type Name Description
QueryCommand queryCommand

QueryCommand containing query text and values.

Returns
Type Description
System.Object

The first column of the first row in the result set, or null if the result set is empty.

GetByTag<T>(Tag)

Gets all the cached items with the specified tag.

Declaration
IDictionary<string, T> GetByTag<T>(Tag tag)
Parameters
Type Name Description
Tag tag

Name of tag to search the cache items with.

Returns
Type Description
System.Collections.Generic.IDictionary<System.String, T>

Returns a dictionary containing the cache keys and associated objects with the type specified.

Type Parameters
Name Description
T

Specifies the type of value obtained from the cache.

Examples

The following example demonstrates how to get the objects with the specified tag.

ICache cache = CacheManager.GetCache("demoCache");
Tag tag = new Tag("Sports");
IDictionary<string,Product> result = cache.SearchService.GetByTag<Product>(tag);

GetByTag<T>(String)

Gets all the cached objects with the wild card supported tag.

Declaration
IDictionary<string, T> GetByTag<T>(string wildCardExpression)
Parameters
Type Name Description
System.String wildCardExpression

The wild card Expression to search with.

Returns
Type Description
System.Collections.Generic.IDictionary<System.String, T>

Returns a dictionary containing the cache keys and associated objects with the type specified.

Type Parameters
Name Description
T

Specifies the type of value obtained from the cache.

Remarks

The special characters supported in wild search by NCache are: 1) "*" : Used as a substitute for zero or more characters in the string. 2)"?" : Used as a substitute for a single character in the string.

Examples

The following example demonstrates how to get the objects with the specified tag using wildcard.

ICache cache = CacheManager.GetCache("demoCache");

Following tags are created and items are added in the cache with these tags

Tag[] tags = new Tag[3];
tags[0] = new Tag("Important Customers");
tags[1] = new Tag("East Coast Customers");
tags[2] = new Tag("West Coast Customers");

IDictionary<string, Customer> result = cache.SearchService.GetByTag<Customer>("*Customers");

GetByTags<T>(IEnumerable<Tag>, TagSearchOptions)

Returns the cached objects that have tags with specified TagSearchOptions.

Declaration
IDictionary<string, T> GetByTags<T>(IEnumerable<Tag> tags, TagSearchOptions type)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<Tag> tags

IEnumerable collection of tags to search cache with.

TagSearchOptions type

TagSearchOptions specifies the search type for the tags.

Returns
Type Description
System.Collections.Generic.IDictionary<System.String, T>

A dictionary containing cache keys and associated objects with the specified type.

Type Parameters
Name Description
T

Specifies the type of value obtained from the cache.

Examples

The following example demonstrates how to get the objects that have the specified tags with TagSearchOptions.

ICache cache = CacheManager.GetCache("demoCache");

Tag[] tags = new Tag[2];
tags[0] = new Tag("Alpha");
tags[1] = new Tag("Beta");

IDictionary<string, Product> result = cache.SearchService.GetByTags<Product>(tags,TagSearchOptions.ByAllTags);

GetGroupData<T>(String)

Retrieves the key and value pairs of the specified group.

Declaration
IDictionary<string, T> GetGroupData<T>(string group)
Parameters
Type Name Description
System.String group

Name of group whose data is to be returned.

Returns
Type Description
System.Collections.Generic.IDictionary<System.String, T>

A dictionary containing key-value pairs of the specified group.

Type Parameters
Name Description
T

Specifies the type of value obtained from the cache.

Examples

The following example demonstrates how to retrieve data against group.

ICache cache = CacheManager.GetCache("demoCache");
IDictionary<string,Product> keys = cache.SearchService.GetGroupData<Product>("group_name");
Exceptions
Type Condition
System.ArgumentNullException

group contains a null reference.

GetGroupKeys(String)

Retrieves the keys of the items in the specified group.

Declaration
ICollection<string> GetGroupKeys(string group)
Parameters
Type Name Description
System.String group

Name of group whose keys are to be returned.

Returns
Type Description
System.Collections.Generic.ICollection<System.String>

The list of keys of the group.

Examples

The following example demonstrates how to retrieve key list against group.

ICache cache = CacheManager.GetCache("demoCache");
ICollection<string> keys = cache.SearchService.GetGroupKeys("group_name");
Exceptions
Type Condition
System.ArgumentNullException

Group contains a null reference.

GetKeysByTag(Tag)

Gets all keys of the objects with the specified tag.

Declaration
ICollection<string> GetKeysByTag(Tag tag)
Parameters
Type Name Description
Tag tag

The tag to search the cache with.

Returns
Type Description
System.Collections.Generic.ICollection<System.String>

Returns collection containing the cache keys.

Examples

The following example demonstrates how to get the keys with the specified tag.

ICache cache = CacheManager.GetCache("demoCache");
Tag tag = new Tag("Sports");
ICollection<string> keys = cache.SearchService.GetKeysByTag(tag);

GetKeysByTag(String)

Gets all the keys with the wild card supported tag.

Declaration
ICollection<string> GetKeysByTag(string wildCardExpression)
Parameters
Type Name Description
System.String wildCardExpression

The wild card expression to search with.

Returns
Type Description
System.Collections.Generic.ICollection<System.String>

Returns collection containing the cache keys.

Remarks

The special characters supported in wild search by NCache are:
1) "*" : Used as a substitute for zero or more characters in the string.
2) "?" : Used as a substitute for a single character in the string.

Examples

The following example demonstrates how to get the keys with the specified tag using wildcard.

ICache cache = CacheManager.GetCache("demoCache");

Following tags are created and items are added in the cache with these tags

Tag[] tags = new Tag[3];
tags[0] = new Tag("Important Customers");
tags[1] = new Tag("East Coast Customers");
tags[2] = new Tag("West Coast Customers");

ICollection<string> keys = cache.SearchService.GetKeysByTag("*Customers");

GetKeysByTags(IEnumerable<Tag>, TagSearchOptions)

Returns keys of the cached items that have tags with specified TagSearchOptions.

Declaration
ICollection<string> GetKeysByTags(IEnumerable<Tag> tags, TagSearchOptions type)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<Tag> tags

IEnumerable collection of tags to search cache with.

TagSearchOptions type

TagSearchOptions specifies the search type for the tags.

Returns
Type Description
System.Collections.Generic.ICollection<System.String>

Returns collection containing the cache keys.

Examples

The following example demonstrates how to get the keys that have the specified tags with TagSearchOptions.

ICache cache = CacheManager.GetCache("demoCache");

Tag[] tags = new Tag[2];
tags[0] = new Tag("Alpha");
tags[1] = new Tag("Beta");

ICollection<string> result = cache.SearchService.GetKeysByTags(tags, TagSearchOptions.ByAllTags);

RemoveByTag(Tag)

Removes the cached objects with the specified tag.

Declaration
void RemoveByTag(Tag tag)
Parameters
Type Name Description
Tag tag

A Tag to search cache with.

Examples

The following example demonstrates how to remove the objects with the specified tag.

ICache cache = CacheManager.GetCache("demoCache");
Tag tag = new Tag("Alpha");
cache.SearchService.RemoveByTag(tag);

RemoveByTags(IEnumerable<Tag>, TagSearchOptions)

Removes the cached objects that have tags with specified TagSearchOptions.

Declaration
void RemoveByTags(IEnumerable<Tag> tags, TagSearchOptions type)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<Tag> tags

IEnumerable collection of tags to search cache with.

TagSearchOptions type

TagSearchOptions specifies the search type for the tags.

Examples

The following example demonstrates how to remove the objects with the specified tags with TagSearchOptions.

ICache cache = CacheManager.GetCache("demoCache");

Tag[] tags = new Tag[2];
tags[0] = new Tag("Alpha");
tags[1] = new Tag("Beta");

cache.SearchService.RemoveByTags(tags, TagSearchOptions.ByAllTags);

RemoveGroupData(String)

Remove the data items pertaining to the specified group from cache.

Declaration
void RemoveGroupData(string group)
Parameters
Type Name Description
System.String group

Name of group to be removed.

Examples

Example demonstrates how you can remove an item from cache using its group.

ICache cache = CacheManager.GetCache("demoCache");
cache.SearchService.RemoveGroupData("group_name");

Contact Us

PHONE

+1 (214) 764-6933   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • NCache Enterprise
  • NCache Community
  • Edition Comparison
  • NCache Architecture
  • Benchmarks
Download
Pricing
Try Playground

Deployments
  • Cloud (SaaS & Software)
  • On-Premises
  • Kubernetes
  • Docker
Technical Use Cases
  • ASP.NET Sessions
  • ASP.NET Core Sessions
  • Pub/Sub Messaging
  • Real-Time ASP.NET SignalR
  • Internet of Things (IoT)
  • NoSQL Database
  • Stream Processing
  • Microservices
Resources
  • Magazine Articles
  • Third-Party Articles
  • Articles
  • Videos
  • Whitepapers
  • Shows
  • Talks
  • Blogs
  • Docs
Customer Case Studies
  • Testimonials
  • Customers
Support
  • Schedule a Demo
  • Forum (Google Groups)
  • Tips
Company
  • Leadership
  • Partners
  • News
  • Events
  • Careers
Contact Us

  • EnglishChinese (Simplified)FrenchGermanItalianJapaneseKoreanPortugueseSpanish

  • Contact Us
  •  
  • Sitemap
  •  
  • Terms of Use
  •  
  • Privacy Policy
© Copyright Alachisoft 2002 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top