Ninja Database Pro
AddFullTextIndex<T> Method
Example 



KellermanSoftware.NinjaDatabasePro Namespace > NinjaDbPro Class : AddFullTextIndex<T> Method
Add a full text index
Syntax
Public Sub AddFullTextIndex(Of T As {Class, New})( _
   ByVal indexName As String, _
   ByVal propertyName As String _
) 
Dim instance As NinjaDbPro
Dim indexName As String
Dim propertyName As String
 
instance.AddFullTextIndex(Of T)(indexName, propertyName)
public void AddFullTextIndex<T>( 
   string indexName,
   string propertyName
)
where T: class, new()
public:
void AddFullTextIndexgeneric<typename T>
( 
   String^ indexName,
   String^ propertyName
) 
where T: ref class, gcnew()

Parameters

indexName
propertyName

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