public void UpdateProjectNamesAndReloadOldOnes() { var projectNames = GenerateRandomWordList(10); var wordDictionary = new Dictionary <String, IEnumerable <String> >(); foreach (string project in projectNames) { CreateDirectory(tempFolder + project + @"\"); _dictionaryBasedSplitter.Initialize(tempFolder + project + @"\"); var words = GenerateRandomWordList(100); _dictionaryBasedSplitter.AddWords(words); wordDictionary.Add(project, words); _dictionaryBasedSplitter.Dispose(); } foreach (string project in projectNames) { _dictionaryBasedSplitter.Initialize(tempFolder + project + @"\"); var words = wordDictionary[project]; foreach (string word in words) { Assert.IsTrue(_dictionaryBasedSplitter.DoesWordExist(word, DictionaryOption.NoStemming)); } } }
private void CreateIndexer() { ServiceLocator.Resolve <UIPackage>(); ServiceLocator.RegisterInstance(new IndexFilterManager()); PerFieldAnalyzerWrapper analyzer = new PerFieldAnalyzerWrapper(new SnowballAnalyzer("English")); analyzer.AddAnalyzer(SandoField.Source.ToString(), new KeywordAnalyzer()); analyzer.AddAnalyzer(SandoField.AccessLevel.ToString(), new KeywordAnalyzer()); analyzer.AddAnalyzer(SandoField.ProgramElementType.ToString(), new KeywordAnalyzer()); ServiceLocator.RegisterInstance <Analyzer>(analyzer); var currentIndexer = new DocumentIndexer(TimeSpan.FromSeconds(10), GetTimeToCommit()); ServiceLocator.RegisterInstance(currentIndexer); ServiceLocator.RegisterInstance(new IndexUpdateManager()); currentIndexer.ClearIndex(); ServiceLocator.Resolve <InitialIndexingWatcher>().InitialIndexingStarted(); var dictionary = new DictionaryBasedSplitter(); dictionary.Initialize(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve <SolutionKey>())); var reformer = new QueryReformerManager(dictionary); reformer.Initialize(null); ServiceLocator.RegisterInstance(reformer); var history = new SearchHistory(); history.Initialize(PathManager.Instance.GetIndexPath (ServiceLocator.Resolve <SolutionKey>())); ServiceLocator.RegisterInstance(history); }
public void CreateIndexer() { TestUtils.InitializeDefaultExtensionPoints(); _indexerPath = Path.GetTempPath() + "luceneindexer"; Directory.CreateDirectory(_indexerPath); _solutionKey = new SolutionKey(Guid.NewGuid(), "C:/SolutionPath"); ServiceLocator.RegisterInstance(_solutionKey); ServiceLocator.RegisterInstance <Analyzer>(new SimpleAnalyzer()); _indexer = new DocumentIndexer(TimeSpan.FromSeconds(1)); ServiceLocator.RegisterInstance(_indexer); // xige var dictionary = new DictionaryBasedSplitter(); dictionary.Initialize(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve <SolutionKey>())); ServiceLocator.RegisterInstance(dictionary); var reformer = new QueryReformerManager(dictionary); reformer.Initialize(null); ServiceLocator.RegisterInstance(reformer); var history = new SearchHistory(); history.Initialize(PathManager.Instance.GetIndexPath (ServiceLocator.Resolve <SolutionKey>())); ServiceLocator.RegisterInstance(history); ClassElement classElement = SampleProgramElementFactory.GetSampleClassElement( accessLevel: AccessLevel.Public, definitionLineNumber: 11, extendedClasses: "SimpleClassBase", fullFilePath: "C:/Projects/SimpleClass.cs", implementedInterfaces: "IDisposable", name: "SimpleName", namespaceName: "Sanod.Indexer.UnitTests" ); SandoDocument sandoDocument = DocumentFactory.Create(classElement); _indexer.AddDocument(sandoDocument); MethodElement methodElement = SampleProgramElementFactory.GetSampleMethodElement( accessLevel: AccessLevel.Protected, name: "SimpleName", returnType: "Void", fullFilePath: "C:/stuff" ); sandoDocument = DocumentFactory.Create(methodElement); _indexer.AddDocument(sandoDocument); }
/// <summary> /// Respond to solution opening. /// Still use Sando's SolutionMonitorFactory because Sando's SolutionMonitorFactory has too much indexer code which is specific with Sando. /// </summary> private void RespondToSolutionOpened(object sender, DoWorkEventArgs ee) { try { updatedForThisSolution = false; //TODO if solution is reopen - the guid should be read from file - future change var solutionId = Guid.NewGuid(); var openSolution = ServiceLocator.Resolve <DTE2>().Solution; var solutionPath = openSolution.FileName; var key = new SolutionKey(solutionId, solutionPath); ServiceLocator.RegisterInstance(key); var sandoOptions = ServiceLocator.Resolve <ISandoOptionsProvider>().GetSandoOptions(); bool isIndexRecreationRequired = IndexStateManager.IsIndexRecreationRequired(); isIndexRecreationRequired = isIndexRecreationRequired || !PathManager.Instance.IndexPathExists(key); ServiceLocator.RegisterInstance(new IndexFilterManager()); ServiceLocator.RegisterInstance <Analyzer>(GetAnalyzer()); SrcMLArchiveEventsHandlers srcMLArchiveEventsHandlers = ServiceLocator.Resolve <SrcMLArchiveEventsHandlers>(); var currentIndexer = new DocumentIndexer(srcMLArchiveEventsHandlers, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10)); ServiceLocator.RegisterInstance(currentIndexer); ServiceLocator.RegisterInstance(new IndexUpdateManager()); if (isIndexRecreationRequired) { currentIndexer.ClearIndex(); } ServiceLocator.Resolve <InitialIndexingWatcher>().InitialIndexingStarted(); // JZ: SrcMLService Integration // Get the SrcML Service. srcMLService = GetService(typeof(SSrcMLGlobalService)) as ISrcMLGlobalService; if (null == srcMLService) { throw new Exception("Can not get the SrcML global service."); } else { ServiceLocator.RegisterInstance(srcMLService); } // Register all types of events from the SrcML Service. if (!SetupHandlers) { SetupHandlers = true; srcMLService.SourceFileChanged += srcMLArchiveEventsHandlers.SourceFileChanged; srcMLService.MonitoringStopped += srcMLArchiveEventsHandlers.MonitoringStopped; } //This is done here because some extension points require data that isn't set until the solution is opened, e.g. the solution key or the srcml archive //However, registration must happen before file monitoring begins below. RegisterExtensionPoints(); SwumManager.Instance.Initialize(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve <SolutionKey>()), !isIndexRecreationRequired); //SwumManager.Instance.Archive = _srcMLArchive; ////XQ: for testing //ISandoGlobalService sandoService = GetService(typeof(SSandoGlobalService)) as ISandoGlobalService; //var res = sandoService.GetSearchResults("Monster"); // xige var dictionary = new DictionaryBasedSplitter(); dictionary.Initialize(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve <SolutionKey>())); ServiceLocator.Resolve <IndexUpdateManager>().indexUpdated += dictionary.UpdateProgramElement; ServiceLocator.RegisterInstance(dictionary); var reformer = new QueryReformerManager(dictionary); reformer.Initialize(null); ServiceLocator.RegisterInstance(reformer); var history = new SearchHistory(); history.Initialize(PathManager.Instance.GetIndexPath (ServiceLocator.Resolve <SolutionKey>())); ServiceLocator.RegisterInstance(history); // End of code changes if (sandoOptions.AllowDataCollectionLogging) { SandoLogManager.StartDataCollectionLogging(PathManager.Instance.GetExtensionRoot()); } else { SandoLogManager.StopDataCollectionLogging(); } LogEvents.SolutionOpened(this, Path.GetFileName(solutionPath)); if (isIndexRecreationRequired) { //just recreate the whole index var indexingTask = System.Threading.Tasks.Task.Factory.StartNew(() => { Collection <string> files = null; while (files == null) { try { files = srcMLService.GetSrcMLArchive().GetFiles(); } catch (NullReferenceException ne) { System.Threading.Thread.Sleep(3000); } } foreach (var file in srcMLService.GetSrcMLArchive().FileUnits) { var fileName = ABB.SrcML.SrcMLElement.GetFileNameForUnit(file); srcMLArchiveEventsHandlers.SourceFileChanged(srcMLService, new FileEventRaisedArgs(FileEventType.FileAdded, fileName)); } srcMLArchiveEventsHandlers.WaitForIndexing(); }); } else { //make sure you're not missing any files var indexingTask = System.Threading.Tasks.Task.Factory.StartNew(() => { Collection <string> files = null; while (files == null) { try { files = srcMLService.GetSrcMLArchive().GetFiles(); } catch (NullReferenceException ne) { System.Threading.Thread.Sleep(3000); } } foreach (var fileName in srcMLService.GetSrcMLArchive().GetFiles()) { srcMLArchiveEventsHandlers.SourceFileChanged(srcMLService, new FileEventRaisedArgs(FileEventType.FileRenamed, fileName)); } srcMLArchiveEventsHandlers.WaitForIndexing(); }); } } catch (Exception e) { LogEvents.UIRespondToSolutionOpeningError(this, e); } var updateListedFoldersTask = System.Threading.Tasks.Task.Factory.StartNew(() => { bool done = false; while (!done) { System.Threading.Thread.Sleep(2000); if (srcMLService != null) { if (srcMLService.MonitoredDirectories != null) { UpdateIndexingFilesList(); done = true; } } } }); }
public DictionaryBasedQueryReformerTests() { this.dictionary = new DictionaryBasedSplitter(); this.reformer = new QueryReformerManager(dictionary); dictionary.Initialize(directory); }
public void SetUp() { this._dictionaryBasedSplitter = new DictionaryBasedSplitter(); CreateDirectory(tempFolder); _dictionaryBasedSplitter.Initialize(tempFolder); }
public void Intialize() { dictionary.Initialize(@"TestFiles\"); }