private void OnQueryDriverChanged (Queryable queryable, IQueryableChangeData change_data)
		{
			bool is_indexing = QueryDriver.IsIndexing;

			if (is_indexing && crawl_status == IndexingStatus.NotRunning)
				SendIndexingStatusResponse (IndexingStatus.Running);
			else if (! is_indexing && crawl_status == IndexingStatus.Running)
				SendIndexingStatusResponse (IndexingStatus.NotRunning);
		}
示例#2
0
        public override ResponseMessage Execute(RequestMessage req)
        {
            SnippetRequest request   = (SnippetRequest)req;
            Queryable      queryable = QueryDriver.GetQueryable(request.Hit.Source);
            ISnippetReader snippet_reader;
            bool           full_text  = request.FullText;
            int            ctx_length = request.ContextLength;
            int            snp_length = request.SnippetLength;

            if (queryable == null)
            {
                Log.Error("SnippetExecutor: No queryable object matches '{0}'", request.Hit.Source);
                snippet_reader = new SnippetReader(null, null, false, -1, -1);
                full_text      = false;
            }
            else
            {
                snippet_reader = queryable.GetSnippet(request.QueryTerms, request.Hit, full_text, ctx_length, snp_length);
            }

            return(new SnippetResponse(new SnippetList(full_text, snippet_reader)));
        }
示例#3
0
		// Instantiates and loads a StaticQueryable from an index directory
		internal static Queryable LoadStaticQueryable (DirectoryInfo index_dir, QueryDomain query_domain)
		{
			StaticQueryable static_queryable = null;
			
			if (!index_dir.Exists)
				return null;
			
			try {
				static_queryable = new StaticQueryable (index_dir.Name, index_dir.FullName, true);
			} catch (InvalidOperationException) {
				Logger.Log.Warn ("Unable to create read-only index (likely due to index version mismatch): {0}", index_dir.FullName);
				return null;
			} catch (Exception e) {
				Logger.Log.Error (e, "Caught exception while instantiating static queryable: {0}", index_dir.Name);
				return null;
			}

			if (static_queryable == null)
				return null;

			// Load StaticIndex.xml from index_dir.FullName/config
			string config_file_path = Path.Combine (index_dir.FullName, "StaticIndex.xml");
			Config static_index_config;
			try {
				static_index_config = Conf.LoadFrom (config_file_path);
				if (static_index_config == null) {
					Log.Error ("Unable to read config from {0}", config_file_path);
					return null;
				}
			} catch (Exception e) {
				Log.Error (e, "Caught exception while reading config from {0}", config_file_path);
				return null;
			}

			string source = static_index_config.GetOption ("Source", null);
			if (source == null) {
				Log.Error ("Invalid config file: {0}", config_file_path);
				return null;
			}

			QueryableFlavor flavor = new QueryableFlavor ();
			flavor.Name = source;
			flavor.Domain = query_domain;

			Queryable queryable = new Queryable (flavor, static_queryable);
			return queryable;
		}
示例#4
0
		static public void DoOneQuery (Queryable            queryable,
					       Query                query,
					       QueryResult          result,
					       IQueryableChangeData change_data)
		{
			try {
				if (queryable.AcceptQuery (query)) {
					QueryClosure qc = new QueryClosure (queryable, query, result, change_data);
					result.AttachWorker (qc);
				}
			} catch (Exception ex) {
				Logger.Log.Warn (ex, "Caught exception calling DoOneQuery on '{0}'", queryable.Name);
			}
		}
示例#5
0
			public QueryClosure (Queryable            queryable,
					     Query                query,
					     QueryResult          result,
					     IQueryableChangeData change_data)
			{
				this.queryable = queryable;
				this.query = query;
				this.result = result;
				this.change_data = change_data;
			}
示例#6
0
		// (1) register themselves in AssemblyInfo.cs:IQueryableTypes and
		// (2) has a QueryableFlavor attribute attached
		// assemble a Queryable object and stick it into our list of queryables.
		static void ScanAssemblyForQueryables (Assembly assembly)
		{
			int count = 0;

			foreach (Type type in ReflectionFu.GetTypesFromAssemblyAttribute (assembly, typeof (IQueryableTypesAttribute))) {
				foreach (QueryableFlavor flavor in ReflectionFu.ScanTypeForAttribute (type, typeof (QueryableFlavor))) {
					if (! UseQueryable (flavor.Name))
						continue;

					if (flavor.RequireInotify && ! Inotify.Enabled) {
						Logger.Log.Warn ("Can't start backend '{0}' without inotify", flavor.Name);
						continue;
					}

					if (flavor.RequireExtendedAttributes && ! ExtendedAttribute.Supported) {
						Logger.Log.Warn ("Can't start backend '{0}' without extended attributes", flavor.Name);
						continue;
					}

					IQueryable iq = null;
					try {
						iq = Activator.CreateInstance (type) as IQueryable;
					} catch (Exception e) {
						Logger.Log.Error (e, "Caught exception while instantiating {0} backend", flavor.Name);
					}

					if (iq != null) {
						Queryable q = new Queryable (flavor, iq);
						iqueryable_to_queryable [iq] = q;
						++count;
						break;
					}
				}
			}
			Logger.Log.Debug ("Found {0} backends in {1}", count, assembly.Location);
		}
示例#7
0
		private void OnQueryDriverChanged (Queryable queryable, IQueryableChangeData change_data)
		{
			if (this.result != null)
				QueryDriver.DoOneQuery (queryable, this.query, this.result, change_data);
		}