public PredicateArgumentIndexer(object argument) { argument = Term.Deref(argument); if (argument == null) { this.Type = IndexerType.Null; this.Functor = null; this.Arity = 0; } else { if (argument is LogicVariable || argument is Indexical) { this.Type = IndexerType.Variable; this.Functor = null; this.Arity = 0; } else { var s = argument as Structure; if (s != null) { this.Type = IndexerType.Structure; this.Functor = s.Functor; this.Arity = (byte)s.Arity; } else { this.Type = IndexerType.Atom; this.Functor = argument; this.Arity = 0; } } } }
public bool Update(Document document, Field[] fields, IndexerType type) { bool success; string id = document.Get("Id"); ReplaceFields(document, fields); try { lock (this) { OpenIndexWriter(type); indexWriter.UpdateDocument(new Term("Id", id), document); indexWriter.ForceMergeDeletes(); indexWriter.DeleteUnusedFiles(); indexWriter.Commit(); indexWriter.Dispose(); } success = true; } catch (Exception ex) { success = false; } return(success); }
private void DoIndex(IndexerType it, bool b) { IWMIndexer pIndex; WMUtils.WMCreateIndexer(out pIndex); IWMIndexer2 pIndex2 = pIndex as IWMIndexer2; pIndex2.Configure(0, it, null, null); m_IndexComplete = false; m_MaxIndex = 0; m_IndexError = 0; pIndex2.StartIndexing(sFileName, this, IntPtr.Zero); while (!m_IndexComplete) { if (b) { pIndex.Cancel(); } else { System.Threading.Thread.Sleep(0); } } if (m_IndexError != 0) { throw new COMException("Indexing error", m_IndexError); } }
/// <summary> /// Applies the rule. /// </summary> /// <param name="node">The node instance to modify.</param> /// <param name="data">Private data from CheckConsistency().</param> public override void Apply(IIndexerType node, object data) { IClassType BaseType = ((Tuple <IClassType, ISealableList <IParameter> >)data).Item1; ISealableList <IParameter> ParameterTable = ((Tuple <IClassType, ISealableList <IParameter> >)data).Item2; IClass EmbeddingClass = node.EmbeddingClass; IObjectType BaseTypeItem = (IObjectType)node.BaseType; IObjectType EntityTypeItem = (IObjectType)node.EntityType; Debug.Assert(node.ParameterTable.Count == 0); node.ParameterTable.AddRange(ParameterTable); node.ParameterTable.Seal(); ITypeName BaseTypeName = BaseTypeItem.ResolvedTypeName.Item; ITypeName EntityTypeName = EntityTypeItem.ResolvedTypeName.Item; ICompiledType EntityType = EntityTypeItem.ResolvedType.Item; #if COVERAGE string TypeString = node.ToString(); Debug.Assert(!node.IsReference); Debug.Assert(node.IsValue); #endif IndexerType.ResolveType(EmbeddingClass.TypeTable, BaseTypeName, BaseType, EntityTypeName, EntityType, node.IndexerKind, node.IndexParameterList, node.ParameterEnd, node.GetRequireList, node.GetEnsureList, node.GetExceptionIdentifierList, node.SetRequireList, node.SetEnsureList, node.SetExceptionIdentifierList, out ITypeName ResolvedTypeName, out ICompiledType ResolvedType); node.ResolvedTypeName.Item = ResolvedTypeName; node.ResolvedType.Item = ResolvedType; }
private bool IndexEBook(BookViewModel bookViewModel, string path) { bool success; Document document = null; string language = LanguageService.Get(bookViewModel.LanguageId).Name; IndexerType type = AnalyzerService.GetIndexerType(language); BookDomainModelBuilder builder = BuilderResolverService.Get <BookDomainModelBuilder, BookViewModel>(bookViewModel); Constructor.ConstructDomainModelData(builder); BookData book = builder.GetDataModel(); try { document = DocumentHandler.GetDocument(book, path); if (book.Id != 0) { EBookIndexer.DeleteById(book.Id.ToString(), type); } EBookIndexer.Add(document, type); success = true; } catch (Exception e) { success = false; } return(success); }
public List <ResultData> Search(SingleFieldSearchViewModel sfsViewModel) { var results = new List <ResultData>(); string fieldName = sfsViewModel.FieldName.Trim(); string fieldValue = sfsViewModel.FieldValue.Trim(); QueryType queryType = (QueryType)Enum.Parse(typeof(QueryType), sfsViewModel.QueryType); IndexerType type = AnalyzerService.GetIndexerType(sfsViewModel.Language); try { Query query = QueryBuilder.BuildQuery(type, queryType, fieldName, fieldValue); InformationRetriever informationRetriever = new InformationRetriever(type, RAW_DIR_PATH, INDEX_DIR_PATH); var queriedHighlights = new List <string>() { fieldName }; results = informationRetriever.RetrieveEBooks(type, query, queriedHighlights, Sort.INDEXORDER); if (results.Count != 0) { MapLanguageAndCategory(results); } } catch (Exception e) { throw e; } return(results); }
private bool Delete(string fieldName, string fieldValue, IndexerType type) { bool success; Term term = new Term(fieldName, fieldValue); success = DeleteDocuments(type, term); return(success); }
public List <ResultData> Search(MultiFieldSearchViewModel mfsViewModel) { var results = new List <ResultData>(); var requiredHighlights = new List <string>(); var booleanQuery = new BooleanQuery(); IndexerType type = AnalyzerService.GetIndexerType(mfsViewModel.Language); InformationRetriever informationRetriever = new InformationRetriever(type, RAW_DIR_PATH, INDEX_DIR_PATH); QueryType queryType = (QueryType)Enum.Parse(typeof(QueryType), mfsViewModel.QueryType); QueryOperator queryOperator = (QueryOperator)Enum.Parse(typeof(QueryOperator), mfsViewModel.QueryOperator); Occur occur = queryOperator.Equals(QueryOperator.AND) ? Occur.MUST : Occur.SHOULD; try { if (!string.IsNullOrEmpty(mfsViewModel.Title)) { requiredHighlights.Add("Title"); booleanQuery.Add(QueryBuilder.BuildQuery(type, queryType, "Title", mfsViewModel.Title.Trim()), occur); } if (!string.IsNullOrEmpty(mfsViewModel.Author)) { requiredHighlights.Add("Author"); booleanQuery.Add(QueryBuilder.BuildQuery(type, queryType, "Author", mfsViewModel.Author.Trim()), occur); } if (!string.IsNullOrEmpty(mfsViewModel.Keywords)) { requiredHighlights.Add("Keyword"); List <Query> queries = BuildQueriesForKeywords(type, queryType, occur, mfsViewModel.Keywords); queries.ForEach(x => booleanQuery.Add(x, occur)); } if (!string.IsNullOrEmpty(mfsViewModel.Content)) { requiredHighlights.Add("Content"); booleanQuery.Add(QueryBuilder.BuildQuery(type, queryType, "Content", mfsViewModel.Content.Trim()), occur); } if (!string.IsNullOrEmpty(mfsViewModel.Language)) { requiredHighlights.Add("Language"); booleanQuery.Add(QueryBuilder.BuildQuery(type, queryType, "Language", mfsViewModel.Language.Trim()), occur); } results = informationRetriever.RetrieveEBooks(type, booleanQuery, requiredHighlights, Sort.INDEXORDER); } catch (Exception e) { results = null; } return(results); }
public bool DeleteByDocument(Document document, IndexerType type) { bool success = false; if (document != null) { success = Delete("Id", document.Get("Id"), type); } return(success); }
/// <summary> /// Return the name of the indexer function for a get or a set /// </summary> /// <param name="o">The instance</param> /// <param name="indexerType">Define get or set</param> /// <returns></returns> private static string GetIndexerMethodName(object o, IndexerType indexerType) { foreach (PropertyInfo property in o.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)) { if (property.GetIndexParameters().Length > 0) { return(string.Format("{0}_{1}", indexerType.ToString().ToLowerInvariant(), property.Name)); } } return(null); }
public List <ResultData> RetrieveEBooks(IndexerType indexerType, Query query, List <string> fieldNames, Sort sort) { var results = new List <ResultData>(); List <Document> documents = documentRetriever.RetrieveDocuments(query, true, sort); Analyzer analyzer = AnalyzerService.GetAnalyzer(indexerType); foreach (Document document in documents) { ResultData resultData = GenerateResultData(document); resultData.Highlights = GenerateHighlights(analyzer, query, document, fieldNames); results.Add(resultData); } return(results); }
public void TestIndexerType() { var original = new IndexerType(); original[0] = 1; original[1] = 5; var dup = Clone(original); // Silly test really; in an ideal world the below would succeed, // but serializing indexers is very hard so instead we test that FullSerializer doesn't crash while processing types with indexers! //Assert.AreEqual(original[0], dup[0]); //Assert.AreEqual(original[1], dup[1]); Assert.IsNotNull(dup); }
public static Analyzer GetAnalyzer(IndexerType type) { Analyzer analyzer = null; if (type.Equals(IndexerType.ENGLISH)) { analyzer = new EnglishAnalyzer(VERSION); } else { analyzer = new SerbianAnalyzer(VERSION); } return(analyzer); }
private void OpenIndexWriter(IndexerType type) { Analyzer analyzer; if (type == IndexerType.ENGLISH) { analyzer = new EnglishAnalyzer(VERSION); } else { analyzer = new SerbianAnalyzer(VERSION); } indexWriterConfig = new IndexWriterConfig(VERSION, analyzer); indexWriterConfig.OpenMode = OpenMode.CREATE_OR_APPEND; indexWriter = new IndexWriter(indexDirectory, indexWriterConfig); }
public bool Add(Document document, IndexerType type) { bool success; try { OpenIndexWriter(type); indexWriter.AddDocument(document); indexWriter.Commit(); indexWriter.Dispose(); success = true; } catch (IOException e) { success = false; } return(success); }
private bool DeleteEBookIndex(BookData book, string path, string language) { bool success = false; Document document; IndexerType type = AnalyzerService.GetIndexerType(language); try { document = DocumentHandler.GetDocument(book, path); EBookIndexer.DeleteByDocument(document, type); success = true; } catch (Exception e) { success = false; } return(success); }
public static Query BuildQuery(IndexerType indexerType, QueryType queryType, string fieldName, string fieldValue) { Query query = null; Analyzer analyzer = AnalyzerService.GetAnalyzer(indexerType); QueryParser queryParser = new QueryParser(VERSION, fieldName, analyzer); fieldName = fieldName.Trim(); fieldValue = fieldValue.Trim(); if (queryType.Equals(QueryType.STANDARD)) { try { query = queryParser.Parse(fieldValue); } catch (Exception e) { throw e; } } else if (queryType.Equals(QueryType.FUZZY)) { Term term = new Term(fieldName, fieldValue); query = new FuzzyQuery(term); } else if (queryType.Equals(QueryType.PHRASE)) { StringTokenizer tokenizedFieldValue = new StringTokenizer(fieldValue); query = new PhraseQuery(); while (tokenizedFieldValue.HasMoreTokens()) { Term term = new Term(fieldName, tokenizedFieldValue.NextToken()); ((PhraseQuery)query).Add(term); } } return(query); }
private bool DeleteDocuments(IndexerType type, params Term[] terms) { bool success; try { lock (this) { OpenIndexWriter(type); indexWriter.DeleteDocuments(terms); indexWriter.DeleteUnusedFiles(); indexWriter.ForceMergeDeletes(); indexWriter.Commit(); indexWriter.Dispose(); } success = true; } catch (IOException e) { success = false; } return(success); }
private List <Query> BuildQueriesForKeywords(IndexerType indexerType, QueryType queryType, Occur occur, string keywords) { var queries = new List <Query>(); if (keywords.Contains(",")) { string[] parts = keywords.Split(','); foreach (string part in parts) { if (!string.IsNullOrEmpty(part)) { try { Query query = QueryBuilder.BuildQuery(indexerType, queryType, "Keyword", part.Trim()); queries.Add(query); } catch (Exception e) { queries = new List <Query>(); } } } } else { try { Query query = QueryBuilder.BuildQuery(indexerType, queryType, "Keyword", keywords.Trim()); queries.Add(query); } catch (Exception e) { queries = new List <Query>(); } } return(queries); }
public PredicateArgumentIndexer(IndexerType type, object functor, byte arity) { this.Type = type; this.Functor = functor; this.Arity = arity; }
/// <summary> /// Applies the rule. /// </summary> /// <param name="node">The node instance to modify.</param> /// <param name="data">Private data from CheckConsistency().</param> public override void Apply(IIndexerFeature node, object data) { IClass EmbeddingClass = node.EmbeddingClass; IObjectType TypeToResolve = (IObjectType)node.EntityType; BaseNode.UtilityType IndexerKind = ((Tuple <BaseNode.UtilityType, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature> >)data).Item1; ISealableDictionary <string, IScopeAttributeFeature> CheckedScope = ((Tuple <BaseNode.UtilityType, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature> >)data).Item2; ISealableDictionary <string, IScopeAttributeFeature> CheckedGetScope = ((Tuple <BaseNode.UtilityType, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature> >)data).Item3; ISealableDictionary <string, IScopeAttributeFeature> CheckedSetScope = ((Tuple <BaseNode.UtilityType, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature>, ISealableDictionary <string, IScopeAttributeFeature> >)data).Item4; ITypeName BaseTypeName = EmbeddingClass.ResolvedClassTypeName.Item; IClassType BaseType = EmbeddingClass.ResolvedClassType.Item; ITypeName EntityTypeName = TypeToResolve.ResolvedTypeName.Item; ICompiledType EntityType = TypeToResolve.ResolvedType.Item; List <IEntityDeclaration> IndexParameterList = new List <IEntityDeclaration>(); foreach (IEntityDeclaration Item in node.IndexParameterList) { IndexParameterList.Add(Item); } BaseNode.ParameterEndStatus ParameterEnd = node.ParameterEnd; IList <IAssertion> GetRequireList = new List <IAssertion>(); IList <IAssertion> GetEnsureList = new List <IAssertion>(); IList <IIdentifier> GetExceptionIdentifierList = new List <IIdentifier>(); if (node.GetterBody.IsAssigned) { IBody GetterBody = (IBody)node.GetterBody.Item; foreach (IAssertion Item in GetterBody.RequireList) { GetRequireList.Add(Item); } foreach (IAssertion Item in GetterBody.EnsureList) { GetEnsureList.Add(Item); } foreach (IIdentifier Item in GetterBody.ExceptionIdentifierList) { GetExceptionIdentifierList.Add(Item); } } IList <IAssertion> SetRequireList = new List <IAssertion>(); IList <IAssertion> SetEnsureList = new List <IAssertion>(); IList <IIdentifier> SetExceptionIdentifierList = new List <IIdentifier>(); if (node.SetterBody.IsAssigned) { IBody SetterBody = (IBody)node.SetterBody.Item; foreach (IAssertion Item in SetterBody.RequireList) { SetRequireList.Add(Item); } foreach (IAssertion Item in SetterBody.EnsureList) { SetEnsureList.Add(Item); } foreach (IIdentifier Item in SetterBody.ExceptionIdentifierList) { SetExceptionIdentifierList.Add(Item); } } IndexerType.ResolveType(EmbeddingClass.TypeTable, BaseTypeName, BaseType, EntityTypeName, EntityType, IndexerKind, IndexParameterList, ParameterEnd, GetRequireList, GetEnsureList, GetExceptionIdentifierList, SetRequireList, SetEnsureList, SetExceptionIdentifierList, out ITypeName ResolvedIndexerTypeName, out ICompiledType ResolvedIndexerType); node.ResolvedEntityTypeName.Item = EntityTypeName; node.ResolvedEntityType.Item = EntityType; node.ResolvedAgentTypeName.Item = ResolvedIndexerTypeName; node.ResolvedAgentType.Item = ResolvedIndexerType; node.ResolvedEffectiveTypeName.Item = EntityTypeName; node.ResolvedEffectiveType.Item = EntityType; foreach (KeyValuePair <string, IScopeAttributeFeature> Entry in CheckedScope) { node.ParameterTable.Add(new Parameter(Entry.Key, Entry.Value)); } node.ParameterTable.Seal(); if (node.GetterBody.IsAssigned) { EmbeddingClass.BodyList.Add((IBody)node.GetterBody.Item); } if (node.SetterBody.IsAssigned) { EmbeddingClass.BodyList.Add((IBody)node.SetterBody.Item); } node.LocalGetScope.Merge(CheckedGetScope); node.LocalGetScope.Seal(); node.FullGetScope.Merge(node.LocalGetScope); node.LocalSetScope.Merge(CheckedSetScope); node.LocalSetScope.Seal(); node.FullSetScope.Merge(node.LocalSetScope); node.LocalScope.Seal(); node.FullScope.Merge(node.LocalScope); ScopeHolder.RecursiveAdd(node.FullGetScope, node.InnerGetScopes); ScopeHolder.RecursiveAdd(node.FullSetScope, node.InnerSetScopes); node.ResolvedFeature.Item = node; #if COVERAGE string TypeString = ResolvedIndexerType.ToString(); #endif }
/// <summary> /// Creates the specified indexer type. /// </summary> /// <param name="indexerType">Type of the indexer.</param> /// <returns></returns> public Index Create(IndexerType indexerType) { InternalIndex = Indexer.CreateIndex(indexerType, Array.Empty <Document>()); return(this); }
public bool DeleteById(string fieldValue, IndexerType type) { return(Delete("Id", fieldValue, type)); }
public DocumentRetriever(IndexerType indexerType, string indexDirPath) { indexDirectoryPath = indexDirPath; analyzer = AnalyzerService.GetAnalyzer(indexerType); }
public DocumentRetriever(IndexerType indexerType, string indexDirPath, int maxHits) { MAX_HITS = maxHits; indexDirectoryPath = indexDirPath; analyzer = AnalyzerService.GetAnalyzer(indexerType); }
public InformationRetriever(IndexerType indexerType, string rawPath, string indexPath) { rawDirectoryPath = rawPath; indexDirectoryPath = indexPath; documentRetriever = new DocumentRetriever(indexerType, indexDirectoryPath); }