public async Task IndexPathsInheritance_DatabaseSpecificSettings() { var path1 = NewDataPath(); var path3 = NewDataPath(); using (var store = GetDocumentStore(new Options { Path = path1, ModifyDatabaseRecord = document => { document.Settings[RavenConfiguration.GetKey(x => x.Indexing.TempPath)] = path3; } })) { var index = new SimpleIndex(); index.Execute(store); var database = await Databases.GetDocumentDatabaseInstanceFor(store); Assert.Equal(path1, database.Configuration.Core.DataDirectory.FullPath); Assert.Equal(path3, database.Configuration.Indexing.TempPath.FullPath); var indexInstance = database.IndexStore.GetIndex(index.IndexName); var safeName = IndexDefinitionBaseServerSide.GetIndexNameSafeForFileSystem(indexInstance.Name); var tempPath = Path.Combine(path3, safeName); Assert.True(Directory.Exists(tempPath)); await store.Maintenance.SendAsync(new DeleteIndexOperation(index.IndexName)); Assert.False(Directory.Exists(tempPath)); } }
private ITypeMember Resolve(int index, Context context) { var row = _loader.Metadata.GetRow(TableId.MemberRef, index); string name = row[Schema.MemberRef.Name].String; var sigBlob = row[Schema.MemberRef.Signature].Blob; var sig = MetadataSignature.DecodeMember(sigBlob); SimpleIndex ownerIndex = row[Schema.MemberRef.Class].Value; var owner = ResolveOwner(ownerIndex, context); var member = FindMember(owner, name, sig, context); if (member == null) { //TODO: Report warning #if DEBUG if (DebugHooks.BreakInvalidMemberReference) { Debugger.Break(); FindMember(owner, name, sig, context); } #endif throw new BadMetadataException(string.Format("Unable to resolve member ref {0}", ownerIndex)); } return(member); }
private ITypeMember ResolveAssociation() { if (_associationResolved) { return(null); } _associationResolved = true; SimpleIndex token = MetadataToken; var row = Loader.Metadata.LookupRow(TableId.MethodSemantics, Schema.MethodSemantics.Method, token.Index - 1, true); if (row == null) { return(null); } SimpleIndex assoc = row[Schema.MethodSemantics.Association].Value; var index = assoc.Index - 1; switch (assoc.Table) { case TableId.Property: var property = Loader.Properties[index]; return(property); case TableId.Event: var @event = Loader.Events[index]; return(@event); default: throw new ArgumentOutOfRangeException(); } }
private IEnumerable <IType> Populate() { var mdb = _owner._loader.Metadata; var rows = mdb.LookupRows(TableId.GenericParamConstraint, Schema.GenericParamConstraint.Owner, OwnerIndex, true); foreach (var row in rows) { SimpleIndex cid = row[Schema.GenericParamConstraint.Constraint].Value; var constraint = _owner._loader.GetTypeDefOrRef(cid, CreateContext()); if (constraint == null) { throw new BadMetadataException(string.Format("Invalid constraint index {0}", cid)); } if (constraint.TypeKind == TypeKind.Interface) { yield return(constraint); } else { if (_baseType == null) { _baseType = constraint; } } } }
protected override IType ParseRow(MetadataRow row, int index) { SimpleIndex scopeIdx = row[Schema.TypeRef.ResolutionScope].Value; var name = row[Schema.TypeRef.TypeName].String; var ns = row[Schema.TypeRef.TypeNamespace].String; var fullname = QName(ns, name); var scope = GetTypeContainer(scopeIdx); if (scope == null) { throw new BadMetadataException(); } var type = scope.Types.FindType(fullname); if (type == null) { //TODO: Report error #if DEBUG if (DebugHooks.BreakInvalidTypeReference) { Debugger.Break(); scope.Types.FindType(fullname); } #endif throw new BadMetadataException(string.Format("Unable to resolve type reference {0}", fullname)); } return(type); }
private bool IsExposed(int index) { //TODO: return true when base type is NUnit.Framework.Assertion or NUnit.Framework.TestCase var token = SimpleIndex.MakeToken(TableId.TypeDef, index + 1); var rows = Metadata.LookupRows(TableId.CustomAttribute, Schema.CustomAttribute.Parent, token, false); return(rows.Select(x => CustomAttributes.GetFullName(Loader, x)).Any(name => ExposeAttributes.Contains(name))); }
public void FailingTest_MapReduce() { using (var store = GetDocumentStore()) { const int count = 300; using (var bulk = store.BulkInsert()) { for (int i = 0; i < count; i++) { bulk.Store(new Order() { Company = $"companies/{i}", Employee = $"employee/{i}", Lines = new List <OrderLine>() { new OrderLine() { Product = $"products/{i}", ProductName = new string((char)0, 1) + "/" + i }, new OrderLine() { Product = $"products/{i}", ProductName = new string((char)0, 1) + "/" + i }, } }); } } var index = new SimpleIndex(); index.Execute(store); for (int i = 0; i < 10; i++) { var stats = store.Maintenance.Send(new GetStatisticsOperation()); Assert.Equal(count + 1, stats.CountOfDocuments); // + hilo var collectionStats = store.Maintenance.Send(new GetCollectionStatisticsOperation()); Assert.Equal(1 + 1, collectionStats.Collections.Count); // + hilo Assert.Equal(count, collectionStats.Collections["Orders"]); using (var session = store.OpenSession()) { var c = session.Query <Order, SimpleIndex>().Customize(x => { x.NoCaching(); x.WaitForNonStaleResults(TimeSpan.FromMinutes(2)); }).Count(); Assert.Equal(count, c); } } } }
public static EnumerationBase Parse(string text) { var enumeration = SimpleIndex.Parse(text); if (enumeration != null) { return(enumeration); } return(ComplexEnumeration.Parse(text)); }
public InternalModule(AssemblyLoader loader, MetadataRow row, int index) { _loader = loader; MetadataToken = SimpleIndex.MakeToken(TableId.Module, index + 1); Name = row[Schema.Module.Name].String; Version = row[Schema.Module.Mvid].Guid; CustomAttributes = new CustomAttributes(_loader, this); }
private string BuildFullName(int index) { var row = _loader.Metadata.GetRow(TableId.MemberRef, index); string name = row[Schema.MemberRef.Name].String; SimpleIndex ownerIndex = row[Schema.MemberRef.Class].Value; string owner = GetOwnerName(ownerIndex); return(owner + "." + name); }
private int ResolveOffset() { if (_offsetResolved) { return(-1); } _offsetResolved = true; SimpleIndex token = MetadataToken; return(GetOffset(Loader.Metadata, token.Index - 1)); }
private object ResolveValue() { if (_valueResolved) { return(null); } _valueResolved = true; SimpleIndex token = MetadataToken; return(Loader.Const[token] ?? ResolveBlobValue(Loader.Metadata, Type, token.Index - 1)); }
public IType ResolveType(IMethod method, int sig) { if (method == null) { return(null); } SimpleIndex i = sig; var type = GetTypeDefOrRef(i, new Context(method)); return(type); }
public async Task DisableAndEnableClusterWideEndPoint() { var(_, leader) = await CreateRaftCluster(3); var database = GetDatabaseName(); await CreateDatabaseInClusterInner(new DatabaseRecord(database), 3, leader.WebUrl, null); var indexName = "SimpleIndex"; DocumentDatabase documentDatabase = null; using (var store = new DocumentStore { Database = database, Urls = new[] { leader.WebUrl } }.Initialize()) { var indexDefinition = new SimpleIndex().CreateIndexDefinition(); indexDefinition.Name = indexName; var putIndexResults = await store.Maintenance.SendAsync(new PutIndexesOperation(indexDefinition)); await Cluster.WaitForRaftIndexToBeAppliedInClusterAsync(putIndexResults.First().RaftCommandIndex); await store.Maintenance.SendAsync(new DisableIndexOperation(indexName, true)); foreach (var server in Servers) { await WaitForValueAsync(async() => { documentDatabase = await server.ServerStore.DatabasesLandlord.TryGetOrCreateResourceStore(database); return(documentDatabase.IndexStore.GetIndex(indexName).State); }, IndexState.Disabled); Assert.Equal(IndexState.Disabled, documentDatabase.IndexStore.GetIndex(indexName).State); Assert.Equal(IndexRunningStatus.Disabled, documentDatabase.IndexStore.GetIndex(indexName).Status); } await store.Maintenance.SendAsync(new EnableIndexOperation(indexName, true)); foreach (var server in Servers) { await WaitForValueAsync(async() => { documentDatabase = await server.ServerStore.DatabasesLandlord.TryGetOrCreateResourceStore(database); return(documentDatabase.IndexStore.GetIndex(indexName).Status); }, IndexRunningStatus.Running); var index = documentDatabase.IndexStore.GetIndex(indexName); Assert.Equal(IndexState.Normal, index.State); Assert.Equal(IndexRunningStatus.Running, index.Status); } } }
public async Task IndexPathsInheritance_ServerWideSettings() { var path1 = NewDataPath(); var path2 = NewDataPath(); var path3 = NewDataPath(); var path4 = NewDataPath(); DoNotReuseServer(new Dictionary <string, string> { { RavenConfiguration.GetKey(x => x.Indexing.StoragePath), path2 }, { RavenConfiguration.GetKey(x => x.Indexing.TempPath), path3 }, { RavenConfiguration.GetKey(x => x.Indexing.JournalsStoragePath), path4 } }); using (GetNewServer()) { using (var store = GetDocumentStore(new Options { Path = path1 })) { var index = new SimpleIndex(); index.Execute(store); var database = await GetDocumentDatabaseInstanceFor(store); Assert.Equal(path1, database.Configuration.Core.DataDirectory.FullPath); Assert.Equal(Path.Combine(path2, "Databases", store.Database), database.Configuration.Indexing.StoragePath.FullPath); Assert.Equal(Path.Combine(path3, "Databases", store.Database), database.Configuration.Indexing.TempPath.FullPath); Assert.Equal(Path.Combine(path4, "Databases", store.Database), database.Configuration.Indexing.JournalsStoragePath.FullPath); var indexInstance = database.IndexStore.GetIndex(index.IndexName); var safeName = IndexDefinitionBase.GetIndexNameSafeForFileSystem(indexInstance.Name); var storagePath = Path.Combine(path2, "Databases", store.Database, safeName); var tempPath = Path.Combine(path3, "Databases", store.Database, safeName); var journalsStoragePath = Path.Combine(path4, "Databases", store.Database, safeName); Assert.True(Directory.Exists(storagePath)); Assert.True(Directory.Exists(tempPath)); Assert.True(Directory.Exists(journalsStoragePath)); await store.Admin.SendAsync(new DeleteIndexOperation(index.IndexName)); Assert.False(Directory.Exists(storagePath)); Assert.False(Directory.Exists(tempPath)); Assert.False(Directory.Exists(journalsStoragePath)); } } }
protected override IEnumerable <IType> Populate() { var rows = _loader.Metadata.LookupRows(TableId.InterfaceImpl, Schema.InterfaceImpl.Class, OwnerIndex, true); return(rows.Select(row => { SimpleIndex ifaceIndex = row[Schema.InterfaceImpl.Interface].Value; var iface = _loader.GetTypeDefOrRef(ifaceIndex, new Context(_owner)); if (iface == null) { throw new BadMetadataException(); } return iface; })); }
private void RunTest(DocumentStore store, string endOfPatchReason) { using (var bulk = store.BulkInsert()) { for (int i = 0; i < 2000; i++) { bulk.Store(new Order() { Company = $"companies/{i}", Employee = $"employee/{i}", Lines = new List <OrderLine>() { new OrderLine() { Product = $"products/{i}", ProductName = new string((char)i, i) }, new OrderLine() { Product = $"products/{i}", ProductName = new string((char)i, i) }, } }); } } SimpleIndex index = new SimpleIndex(); index.Execute(store); var indexInstance = GetDatabase(store.Database).Result.IndexStore.GetIndex(index.IndexName); indexInstance._indexStorage.Environment().Options.MaxNumberOfPagesInJournalBeforeFlush = 4; using (var session = store.OpenSession()) { var count = session.Query <Order, SimpleIndex>().Customize(x => x.WaitForNonStaleResults(TimeSpan.FromMinutes(2))).Count(); Assert.Equal(4000, count); } var stats = indexInstance.GetIndexingPerformance(); var mapRunDetails = stats.Select(x => x.Details.Operations.Select(y => y.MapDetails)).SelectMany(x => x).Where(x => x != null).ToList(); Assert.True(mapRunDetails.Any(x => x.BatchCompleteReason.Contains(endOfPatchReason))); }
public GenericParameterImpl(AssemblyLoader loader, MetadataRow row, int index, long id) { _loader = loader; MetadataToken = SimpleIndex.MakeToken(TableId.GenericParam, index + 1); Name = row[Schema.GenericParam.Name].String; Id = id; var position = (int)row[Schema.GenericParam.Number].Value; _flags = (GenericParamAttributes)row[Schema.GenericParam.Flags].Value; _owner = row[Schema.GenericParam.Owner].Value; _constraints = new ConstraintsImpl(this); _info = new GenericParameterInfo(position, Variance, SpecialConstraints); }
internal ITypeMember GetTypeOrMethodDef(SimpleIndex i) { int index = i.Index - 1; switch (i.Table) { case TableId.TypeDef: return(Types[index]); case TableId.MethodDef: return(Methods[index]); default: throw new ArgumentOutOfRangeException("i"); } }
internal IMethod GetMethodDefOrRef(SimpleIndex i, Context context) { int index = i.Index - 1; switch (i.Table) { case TableId.MethodDef: return(Methods[index]); case TableId.MemberRef: return(MemberRefs.Get(index, context) as IMethod); default: throw new ArgumentOutOfRangeException("i"); } }
public IMethod ResolveEntryPoint() { SimpleIndex token = Metadata.EntryPointToken; if (token.Table != TableId.MethodDef) { return(null); } int index = token.Index - 1; if (index < 0 || index >= Methods.Count) { return(null); } return(Methods[index]); }
private string GetOwnerName(SimpleIndex owner) { int index = owner.Index - 1; switch (owner.Table) { case TableId.TypeDef: return(_loader.Types.GetFullName(index)); case TableId.TypeRef: return(_loader.TypeRefs.GetFullName(index)); default: throw new NotSupportedException(); } }
public object this[SimpleIndex parent] { get { var row = _loader.Metadata.LookupRow(TableId.Constant, Schema.Constant.Parent, parent, false); if (row == null) { return(null); } var type = (ElementType)row[Schema.Constant.Type].Value; var reader = row[Schema.Constant.Value].Blob; return(ReadValue(type, reader)); } }
protected override IAssembly ParseRow(MetadataRow row, int index) { var token = SimpleIndex.MakeToken(TableId.AssemblyRef, index + 1); var name = new AssemblyReference { Version = GetVersion(row, 0), Flags = ((AssemblyFlags)row[Schema.AssemblyRef.Flags].Value), PublicKeyToken = row[Schema.AssemblyRef.PublicKeyOrToken].Blob.ToArray(), Name = row[Schema.AssemblyRef.Name].String, Culture = row[Schema.AssemblyRef.Culture].Culture, HashValue = row[Schema.AssemblyRef.HashValue].Blob.ToArray(), MetadataToken = token }; return(Loader.ResolveAssembly(name)); }
public void Isolated() { var ramDirectory = new RAMDirectory(); using (new IndexWriter(ramDirectory, new StandardAnalyzer(Version.LUCENE_29), IndexWriter.MaxFieldLength.UNLIMITED)){} var inMemoryRavenConfiguration = new InMemoryRavenConfiguration(); inMemoryRavenConfiguration.Initialize(); var simpleIndex = new SimpleIndex(ramDirectory, 0, new IndexDefinition { Map = @"from s in docs.Softs select new { s.f_platform, s.f_name, s.f_alias,s.f_License,s.f_totaldownload}", Analyzers = { { "f_name", typeof(KeywordAnalyzer).AssemblyQualifiedName }, { "f_alias", typeof(KeywordAnalyzer).AssemblyQualifiedName }, }, Indexes = { { "f_platform", FieldIndexing.NotAnalyzed }, { "f_License", FieldIndexing.NotAnalyzed }, { "f_totaldownload", FieldIndexing.NotAnalyzed }, { "f_name", FieldIndexing.Analyzed }, { "f_alias", FieldIndexing.Analyzed }, }, SortOptions = { { "f_totaldownload", SortOptions.Int }, { "f_License", SortOptions.Int }, } }, new MapOnlyView(), new WorkContext() { Configuration = inMemoryRavenConfiguration }); var perFieldAnalyzerWrapper = simpleIndex.CreateAnalyzer(new LowerCaseKeywordAnalyzer(), new List <Action>()); var tokenStream = perFieldAnalyzerWrapper.TokenStream("f_name", new StringReader("hello Shrek")); while (tokenStream.IncrementToken()) { var attribute = (TermAttribute)tokenStream.GetAttribute <ITermAttribute>(); Assert.Equal("hello Shrek", attribute.Term); } }
public static string GetFullName(AssemblyLoader loader, MetadataRow row) { SimpleIndex ctorIndex = row[Schema.CustomAttribute.Type].Value; var index = ctorIndex.Index - 1; switch (ctorIndex.Table) { case TableId.MethodDef: return(loader.Methods.GetFullName(index)); case TableId.MemberRef: return(loader.MemberRefs.GetFullName(index)); default: throw new BadMetadataException(string.Format("Invalid custom attribute type index {0}", ctorIndex)); } }
public IVariableCollection ResolveLocalVariables(IMethod method, int sig, out bool hasGenericVars) { hasGenericVars = false; var list = new VariableCollection(); if (sig == 0) { return(list); } var context = new Context(method); SimpleIndex idx = sig; var row = Metadata.GetRow(TableId.StandAloneSig, idx.Index - 1); var reader = row[Schema.StandAloneSig.Signature].Blob; int prolog = reader.ReadPackedInt(); if (prolog != 0x07) { throw new BadSignatureException("Invalid local variable signature."); } int varCount = reader.ReadPackedInt(); for (int i = 0; i < varCount; ++i) { var typeSig = TypeSignature.Decode(reader); var type = ResolveType(typeSig, context); if (!hasGenericVars && type.IsGenericContext()) { hasGenericVars = true; } var v = new Variable { Index = i, Type = type, Name = string.Format("v{0}", i) }; list.Add(v); } return(list); }
protected override IModule ParseRow(MetadataRow row, int index) { string name = row[Schema.ModuleRef.Name].String; //var f = GetFile(name); //var res = GetResource(name); var token = SimpleIndex.MakeToken(TableId.ModuleRef, index + 1); var mod = new Module { Name = name, MetadataToken = token }; Loader.Assembly.Modules.Add(mod); return(mod); }
protected override IManifestFile ParseRow(MetadataRow row, int index) { var flags = (FileFlags)row[Schema.File.Flags].Value; var token = SimpleIndex.MakeToken(TableId.File, index + 1); var file = new ManifestFile { Name = row[Schema.File.Name].String, HashValue = row[Schema.File.HashValue].Blob.ToArray(), ContainsMetadata = flags == FileFlags.ContainsMetadata, MetadataToken = token }; file.CustomAttributes = new CustomAttributes(Loader, file); return(file); }
private IType ResolveBaseType() { if (_baseTypeResolved) { return(null); } _baseTypeResolved = true; if (this.Is(SystemTypeCode.Object)) { return(null); } var row = Loader.Metadata.GetRow(TableId.TypeDef, this.RowIndex()); SimpleIndex baseIndex = row[Schema.TypeDef.Extends].Value; return(Loader.GetTypeDefOrRef(baseIndex, new Context(this))); }
public void TestBuildQuery() { var index = new SimpleIndex(); index.AddItem(new mockindex.Document { Id = 1, Value = "foo one" }); index.AddItem(new mockindex.Document { Id = 2, Value = "two" }); index.AddItem(new mockindex.Document { Id = 3, Value = "three two" }); index.AddItem(new mockindex.Document { Id = 4, Value = "four six" }); index.AddItem(new mockindex.Document { Id = 5, Value = "five two three" }); index.AddItem(new mockindex.Document { Id = 6, Value = "five" }); index.AddItem(new mockindex.Document { Id = 7, Value = "five two" }); index.AddItem(new mockindex.Document { Id = 8, Value = "five three" }); index.AddItem(new mockindex.Document { Id = 9, Value = "three" }); index.AddItem(new mockindex.Document { Id = 10, Value = "four two three" }); foreach (var result in index.Inversions.Documents(DocumentComparer.Default)) { Console.Out.WriteLine("doc: {0}, text: {1}", result.Id, result.Value); } Console.Out.WriteLine("==== five OR (two -three)"); var rootQuery = index.QueryExecutor.Should("five"); var subQuery = index.QueryExecutor.Should("two").MustNot("three"); var finalQuery = rootQuery.Should(subQuery); foreach (var result in finalQuery.Invertables()) { Console.Out.WriteLine("doc: {0}, text: {1}", result.Id, result.Value); } //var queryText = "-six foo four +one"; var queryText = "+(five (four AND two)) +(three two nothing here to see) -two"; DoQuery(index, queryText, new StringInverter()); //Console.Out.WriteLine("=== graph for " + queryText + "==="); //var parser = new Parser(new Scanner()); //var tree = parser.Parse(queryText); //var rootExpressionNode = // tree.Nodes.FirstOrDefault(a => a.Token.Type == TokenType.Start).Nodes.FirstOrDefault( // a => a.Token.Type == TokenType.Expression); //if(default(ParseNode) == rootExpressionNode) // throw new Exception("No query in parse tree."); //var rootQueryClause = AnalyzeQueryNode(rootExpressionNode, ); //var queryExecutor = index.GetQueryExecutor(rootQueryClause); //Console.Out.WriteLine("=== results for: " + queryText + " ==="); //foreach (var result in queryExecutor.Invertables()) //{ // Console.Out.WriteLine("doc: {0}, text: {1}", result.Id, result.Value); //} //foreach (var leafnode in FindLeafNodes(tree)) //{ // // build leaf node // // TERM|QUOTEDTERM OP? (TERM|QUOTEDTERM)? // for (int i = 0; i < leafnode.Nodes.Count; i+=2) // { // var termExp = leafnode.Nodes[i]; // var termNode = termExp.Nodes.Find(a => a.Token.Type == TokenType.TERM || a.Token.Type == TokenType.QUOTEDTERM); // if (null == termNode) throw new Exception("WTF"); // var term = termNode.Token.ToString(); // var prefixNode = termExp.Nodes.Find(a => a.Token.Type == TokenType.PREFIX); // if (null != prefixNode) // { // } // } // PrintParseNode(leafnode); //} }
public void TestSomeExamples() { IIndex<int, string, string> index = new SimpleIndex(); IInverter<string, string> inverter = new StringInverter(); index.AddItem(new mockindex.Document { Id = 1, Value = "A B C D E F" }, inverter); index.AddItem(new mockindex.Document { Id = 2, Value = "B C" }, inverter); index.AddItem(new mockindex.Document { Id = 3, Value = "A B E F" }, inverter); index.AddItem(new mockindex.Document { Id = 4, Value = "C D E F" }, inverter); index.AddItem(new mockindex.Document { Id = 5, Value = "E F" }, inverter); index.AddItem(new mockindex.Document { Id = 6, Value = "D D D D E F" }, inverter); index.AddItem(new mockindex.Document { Id = 7, Value = "D E F" }, inverter); // index.AddDocument(new Document { DocID = 8, Text = "A B C D E F" }, inverter); // index.AddDocument(new Document { DocID = 9, Text = "A B C D E F" }, inverter); index.AddItem(new mockindex.Document { Id = 10, Value = "A B" }, inverter); index.AddItem(new mockindex.Document { Id = 11, Value = "E E E A B" }, inverter); index.AddItem(new mockindex.Document { Id = 12, Value = "C A B" }, inverter); foreach (var result in index.Inversions.Documents(DocumentComparer.Default)) { Console.Out.WriteLine("doc: {0}, text: {1}", result.Id, result.Value); } Console.Out.WriteLine("-------------------------"); Console.Out.WriteLine("find documents that match clause A and clause B (other clauses don't affect matching) "); Console.Out.WriteLine("-------------------------"); var queryText = "A AND B OR C OR D OR E OR F"; DoQuery(index, queryText, inverter); queryText = "+A +B C D E F"; DoQuery(index, queryText, inverter); Console.Out.WriteLine("-------------------------"); Console.Out.WriteLine("find documents matching at least one of these clauses "); Console.Out.WriteLine("-------------------------"); queryText = "C OR D OR E OR F"; DoQuery(index, queryText, inverter); queryText = "C D E F"; DoQuery(index, queryText, inverter); Console.Out.WriteLine("-------------------------"); Console.Out.WriteLine("find documents that match A, and match one of B, C, D, E, or F "); Console.Out.WriteLine("-------------------------"); queryText = "A AND (B OR C OR D OR E OR F)"; DoQuery(index, queryText, inverter); queryText = "+A +(B C D E F)"; DoQuery(index, queryText, inverter); Console.Out.WriteLine("-------------------------"); Console.Out.WriteLine("find documents that match at least one of C, D, E, F, or both of A and B"); Console.Out.WriteLine("-------------------------"); queryText = "(A AND B) OR C OR D OR E OR F "; DoQuery(index, queryText, inverter); queryText = "(+A +B) C D E F"; DoQuery(index, queryText, inverter); }
public void TestMockLinq() { var index = new SimpleIndex(); index.AddItem(new mockindex.Document { Id = 1, Value= "foo one" }); index.AddItem(new mockindex.Document { Id = 2, Value = "two" }); index.AddItem(new mockindex.Document { Id = 3, Value = "three two" }); index.AddItem(new mockindex.Document { Id = 4, Value = "four six" }); index.AddItem(new mockindex.Document { Id = 5, Value = "five two three" }); index.AddItem(new mockindex.Document { Id = 6, Value = "five" }); index.AddItem(new mockindex.Document { Id = 7, Value = "five two" }); index.AddItem(new mockindex.Document { Id = 8, Value = "five three" }); index.AddItem(new mockindex.Document { Id = 9, Value = "three" }); foreach (var result in index.Inversions.Documents(DocumentComparer.Default)) { Console.Out.WriteLine("doc: {0}, text: {1}", result.Id, result.Value); } foreach (var term in index.Inversions) { //Console.Out.WriteLine("term: {0}, docs: {1}", term.Text, string.Join(",", term.Documents.Select(a=>a.DocID.ToString()).ToArray())); } //.ButNot("three") Console.Out.WriteLine(""); Console.Out.WriteLine("==== five OR two OR three "); var results = index.QueryExecutor.MustHave("five").Should("two").Should("three"); foreach (var result in results.Invertables()) { Console.Out.WriteLine("doc: {0}, text: {1}", result.Id, result.Value); } Console.Out.WriteLine("==== five OR two OR three "); var subQuery = index.QueryExecutor.MustHave("two").MustNot("three"); results = index.QueryExecutor.MustHave("five").Should(subQuery); foreach (var result in results.Invertables()) { Console.Out.WriteLine("doc: {0}, text: {1}", result.Id, result.Value); } }