Exemplo n.º 1
0
		static public SnippetReader GetSnippet (string[] query_terms, TextReader line_reader, bool full_text, int ctx_length, int snp_length)
		{
			// FIXME: If the query doesn't have search text (or is null), we should
			// generate a 'summary snippet'.

			if (line_reader == null)
				return null;

			SnippetReader snippet_reader = new SnippetReader (line_reader, query_terms, full_text, ctx_length, snp_length);
			return snippet_reader;
		}
Exemplo n.º 2
0
        static public SnippetReader GetSnippet(string[] query_terms, TextReader line_reader, bool full_text, int ctx_length, int snp_length)
        {
            // FIXME: If the query doesn't have search text (or is null), we should
            // generate a 'summary snippet'.

            if (line_reader == null)
            {
                return(null);
            }

            SnippetReader snippet_reader = new SnippetReader(line_reader, query_terms, full_text, ctx_length, snp_length);

            return(snippet_reader);
        }
Exemplo n.º 3
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));
		}
Exemplo n.º 4
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)));
        }
Exemplo n.º 5
0
	private static List<SnippetLine> GetSnippet (SnippetRequest request)
	{
		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) {
			Console.WriteLine ("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);

		List<SnippetLine> snippetlines = new List<SnippetLine> ();
		if (snippet_reader == null)
			return snippetlines;

		if (! full_text) {
 			foreach (SnippetLine snippet_line in snippet_reader.GetSnippet ())
				snippetlines.Add (snippet_line);
		} else {
			SnippetLine snippet_line = new SnippetLine ();
			snippet_line.Line = 1;

			Fragment fragment = new Fragment ();
			fragment.QueryTermIndex = -1;
			StringBuilder sb = new StringBuilder ();

			string line;
			// Read data from snippet_reader and write
			while ((line = snippet_reader.ReadLine ()) != null) {
				sb.Append (StringFu.CleanupInvalidXmlCharacters (line));
				sb.Append ("\n");
			}

			fragment.Text = sb.ToString ();
			snippet_line.Fragments = new ArrayList ();
			snippet_line.Fragments.Add (fragment);
			snippetlines.Add (snippet_line);
		}

		snippet_reader.Close ();

		return snippetlines;
	}