0

I have these commands

> FT.CREATE feeders ON HASH PREFIX 1 MOC: SCHEMA MOC TEXT  H_W TEXT H_Y TEXT F TEXT

...

> FT.SEARCH feeders "@MOC: MOC111"

How to do this using NRediSearch ?

1 Answers1

0

Initalize Library

NRediSearch is centered around a different Client Object that is standard in the base StackExchange.Redis library:

var mux = ConnectionMultiplexer.Connect("localhost");
var client = new Client("feeders", mux.GetDatabase());

Create index

You will initialize one of those objects passing in your desired index name and an IDatabase object, then create a schema object which you will add the desired fields too, Next you will create an ConfiguredIndexOptions object to define the desired prefix, finally you'll call CreateIndexAsync

//initialize schema
var schema = new Schema();

//AddTextFields
schema.AddTextField("Moc");
schema.AddTextField("H_W");
schema.AddTextField("H_Y");
schema.AddTextField("F");

//declare prefixes
var options = new Client.ConfiguredIndexOptions(new Client.IndexDefinition(prefixes: new[]{"MOC"}));

//create index
await client.CreateIndexAsync(schema, options);

Query

Finally, you'll create a Query object, initializing it with the query string, and you'll query with Search or SearchAsync, the resulting object will hold all the documents retrieved from the database

var query = new Query("@MOC: MOC111");
var res = await client.SearchAsync(query);            
Console.WriteLine(res.Documents.Count);
slorello
  • 901
  • 5
  • 6