Ninja Database Pro
SearchByRegex<T> Method (NinjaDbPro)
Example 



KellermanSoftware.NinjaDatabasePro Namespace > NinjaDbPro Class : SearchByRegex<T> Method
Search a full text index by a regular expression
Syntax
Public Function SearchByRegex(Of T As {Class, New})( _
   ByVal indexName As String, _
   ByVal searchRegex As Regex _
) As List(Of SingleIndexRecord(Of T,String))
Dim instance As NinjaDbPro
Dim indexName As String
Dim searchRegex As Regex
Dim value As List(Of SingleIndexRecord(Of T,String))
 
value = instance.SearchByRegex(Of T)(indexName, searchRegex)
public List<SingleIndexRecord<T,string>> SearchByRegex<T>( 
   string indexName,
   Regex searchRegex
)
where T: class, new()
public:
List<SingleIndexRecord<T^,String^>^>^ SearchByRegexgeneric<typename T>
( 
   String^ indexName,
   Regex^ searchRegex
) 
where T: ref class, gcnew()

Parameters

indexName
searchRegex

Type Parameters

T
Example
NinjaDbPro db = new NinjaDbPro("FullTextIndexExampleDir", "FullTextIndexExampleDir.db");
 
//Licensed Mode
//db.UserName = "John Smith 101224";
//db.LicenseKey = "aousdf832jasf==";
 
//Set before OpenDatabase. Default storage is IsolatedStorageDatabase. Other options are:
//db.Storage = new MemoryDatabase(); //In memory database
//db.Storage = new FileDatabase();  
 
//Open the database
db.OpenDatabase();
 
//Add a single property index if it doesn't already exist
if (!db.IndexExists<Quote>("QuoteTextIndex"))
    db.AddFullTextIndex<Quote>("QuoteTextIndex", "QuoteText");
 
//Add a couple record to the database
Quote quote = new Quote();
quote.Author = "John";
quote.QuoteText = "The quick brown fox jumps over the lazy dog.";
db.Save(quote);
 
//Add a couple record to the database
quote = new Quote();
quote.Author = "Jane";
quote.QuoteText = "The rain in spain falls mainly on the plain.";
db.Save(quote);
 
//Find a quote by a phrase
var phraseQuery = db.SearchPhrase<Quote>("QuoteTextIndex", "brown fox", true);
 
//Lazy load the first record and write out a property
Console.WriteLine(phraseQuery[0].LazyValue.Author);
 
//Find a quote by any keywords
var anyQuery = db.SearchAnyKeywords<Quote>("QuoteTextIndex", "fox spain", true);
 
//Lazy load the second record and write out a property
Console.WriteLine(anyQuery[1].LazyValue.Author);
 
//Find a quote by all keywords
var allQuery = db.SearchAllKeywords<Quote>("QuoteTextIndex", "jumps dog", true);
 
//Lazy load the second record and write out a property
Console.WriteLine(allQuery[0].LazyValue.Author);
 
//Find a quote by Regex
Regex searchRegex = new Regex(@"brown\sfox");
var regexQuery = db.SearchByRegex<Quote>("QuoteTextIndex", searchRegex);
 
//Lazy load the second record and write out a property
Console.WriteLine(regexQuery[0].LazyValue.Author);
 
//Close the database
db.CloseDatabase();
Dim db As New NinjaDbPro("FullTextIndexExampleDir", "FullTextIndexExampleDir.db")
 
'Licensed Mode
'db.UserName = "John Smith 101224";
'db.LicenseKey = "aousdf832jasf==";
 
'Set before OpenDatabase. Default storage is IsolatedStorageDatabase. Other options are:
'db.Storage = new MemoryDatabase(); //In memory database
'db.Storage = new FileDatabase();  
 
'Open the database
db.OpenDatabase()
 
'Add a single property index if it doesn't already exist
If Not db.IndexExists(Of Quote)("QuoteTextIndex") Then
    db.AddFullTextIndex(Of Quote)("QuoteTextIndex", "QuoteText")
End If
 
'Add a couple record to the database
Dim quote As New Quote()
quote.Author = "John"
quote.QuoteText = "The quick brown fox jumps over the lazy dog."
db.Save(quote)
 
'Add a couple record to the database
quote = New Quote()
quote.Author = "Jane"
quote.QuoteText = "The rain in spain falls mainly on the plain."
db.Save(quote)
 
'Find a quote by a phrase
Dim phraseQuery = db.SearchPhrase(Of Quote)("QuoteTextIndex", "brown fox", True)
 
'Lazy load the first record and write out a property
Console.WriteLine(phraseQuery(0).LazyValue.Author)
 
'Find a quote by any keywords
Dim anyQuery = db.SearchAnyKeywords(Of Quote)("QuoteTextIndex", "fox spain", True)
 
'Lazy load the second record and write out a property
Console.WriteLine(anyQuery(1).LazyValue.Author)
 
'Find a quote by all keywords
Dim allQuery = db.SearchAllKeywords(Of Quote)("QuoteTextIndex", "jumps dog", True)
 
'Lazy load the second record and write out a property
Console.WriteLine(allQuery(0).LazyValue.Author)
 
'Find a quote by Regex
Dim searchRegex As New Regex("brown\sfox")
Dim regexQuery = db.SearchByRegex(Of Quote)("QuoteTextIndex", searchRegex)
 
'Lazy load the second record and write out a property
Console.WriteLine(regexQuery(0).LazyValue.Author)
 
'Close the database
db.CloseDatabase()
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

NinjaDbPro Class
NinjaDbPro Members