Esempio n. 1
0
int nm_read_query(CONTEXT *ctx)
{
    notmuch_query_t *q;
    struct nm_ctxdata *data;
    int rc = -1;

    if (init_context(ctx) != 0)
        return -1;

    data = get_ctxdata(ctx);
    if (!data)
        return -1;

    dprint(1, (debugfile, "nm: reading messages...[current count=%d]\n",
               ctx->msgcount));

    nm_progress_reset(ctx);

    q = get_query(data, FALSE);
    if (q) {
        switch(get_query_type(data)) {
        case NM_QUERY_TYPE_MESGS:
            read_mesgs_query(ctx, q, 0);
            break;
        case NM_QUERY_TYPE_THREADS:
            read_threads_query(ctx, q, 0, get_limit(data));
            break;
        }
        notmuch_query_destroy(q);
        rc = 0;

    }

    if (!is_longrun(data))
        release_db(data);

    ctx->mtime = time(NULL);

    mx_update_context(ctx, ctx->msgcount);
    data->oldmsgcount = 0;

    dprint(1, (debugfile, "nm: reading messages... done [rc=%d, count=%d]\n",
               rc, ctx->msgcount));
    return rc;
}
Esempio n. 2
0
void 
query (void)
{
  ProgTime TotalStartTime, TotalInvfTime, TotalTextTime;
  InitQueryTimes iqt;
  query_data *qd;

  TotalStartTime.RealTime = TotalStartTime.CPUTime = 0;
  TotalInvfTime.RealTime = TotalInvfTime.CPUTime = 0;
  TotalTextTime.RealTime = TotalTextTime.CPUTime = 0;

  qd = InitQuerySystem (GetDefEnv ("mgdir", "./"),
			GetDefEnv ("mgname", ""),
			&iqt);
  if (!qd)
    FatalError (1, mg_errorstrs[mg_errno], mg_error_data);
  start_up_stats (qd, iqt);


  while (1)
    {
      ProgTime StartTime, InvfTime, TextTime;
      char QueryType;
      char OutputType;
      char *line;
      ResetFileStats (qd);
      qd->max_mem_in_use = qd->mem_in_use = 0;

      qd->tot_hops_taken += qd->hops_taken;
      qd->tot_num_of_ptrs += qd->num_of_ptrs;
      qd->tot_num_of_accum += qd->num_of_accum;
      qd->tot_num_of_terms += qd->num_of_terms;
      qd->tot_num_of_ans += qd->num_of_ans;
      qd->tot_text_idx_lookups += qd->text_idx_lookups;
      qd->hops_taken = qd->num_of_ptrs = 0;
      qd->num_of_accum = qd->num_of_ans = qd->num_of_terms = 0;
      qd->text_idx_lookups = 0;

      Display_Stats (stderr);
      Clear_Stats ();
      line = get_query (qd);
      if (!line || Quitting)
	break;

      GetPostProc (line);

      GetTime (&StartTime);

      FreeQueryDocs (qd);

      QueryType = get_query_type ();
      OutputType = get_output_type ();
      /* No point in hiliting words on a docnum query */
      if (OutputType == OUTPUT_HILITE && QueryType == QUERY_DOCNUMS)
	OutputType = OUTPUT_TEXT;

      switch (QueryType)
	{
	case QUERY_BOOLEAN:
	  {
	    char *maxdocs;
	    BooleanQueryInfo bqi;
	    maxdocs = GetDefEnv ("maxdocs", "all");
	    bqi.MaxDocsToRetrieve = strcmp (maxdocs, "all") ? atoi (maxdocs) : -1;
	    BooleanQuery (qd, line, &bqi);
	    break;
	  }
	case QUERY_APPROX:
	case QUERY_RANKED:
	  {
	    char *maxdocs;
	    char *maxterms;
	    char *maxaccum;
	    RankedQueryInfo rqi;
	    maxdocs = GetDefEnv ("maxdocs", "all");
	    maxterms = GetDefEnv ("max_terms", "all");
	    maxaccum = GetDefEnv ("max_accumulators", "all");
	    rqi.Sort = BooleanEnv (GetEnv ("sorted_terms"), 0);
	    rqi.QueryFreqs = BooleanEnv (GetEnv ("qfreq"), 1);
	    rqi.Exact = QueryType == QUERY_RANKED;
	    rqi.MaxDocsToRetrieve = strcmp (maxdocs, "all") ? atoi (maxdocs) : -1;
	    rqi.MaxTerms = strcmp (maxterms, "all") ? atoi (maxterms) : -1;
	    rqi.MaxParasToRetrieve = rqi.MaxDocsToRetrieve;
	    if (qd->id->ifh.InvfLevel == 3 && GetEnv ("maxparas"))
	      rqi.MaxParasToRetrieve = atoi (GetEnv ("maxparas"));
	    rqi.AccumMethod = toupper (*GetDefEnv ("accumulator_method", "A"));
	    rqi.MaxAccums = strcmp (maxaccum, "all") ? atoi (maxaccum) : -1;
	    rqi.HashTblSize = IntEnv (GetEnv ("hash_tbl_size"), 1000);
	    rqi.StopAtMaxAccum = BooleanEnv (GetEnv ("stop_at_max_accum"), 0);
	    rqi.skip_dump = GetEnv ("skip_dump");
	    RankedQuery (qd, line, &rqi);
	    break;
	  }
	case QUERY_DOCNUMS:
	  {
	    DocnumsQuery (qd, line);
	    break;
	  }
	}

      GetTime (&InvfTime);

      if (qd->DL)
	MoreDocs (qd, line, OutputType);

      GetTime (&TextTime);

      if (BooleanEnv (GetEnv ("timestats"), 0) ||
	  BooleanEnv (GetEnv ("briefstats"), 0))
	QueryTimeStats (&StartTime, &InvfTime, &TextTime);

      if (BooleanEnv (GetEnv ("diskstats"), 0) ||
	  BooleanEnv (GetEnv ("briefstats"), 0))
	File_Stats (qd);

      if (BooleanEnv (GetEnv ("memstats"), 0) ||
	  BooleanEnv (GetEnv ("briefstats"), 0))
	MemStats (qd);

      if (BooleanEnv (GetEnv ("sizestats"), 0))
	SizeStats (qd);

      TotalInvfTime.RealTime += InvfTime.RealTime - StartTime.RealTime;
      TotalInvfTime.CPUTime += InvfTime.CPUTime - StartTime.CPUTime;
      TotalTextTime.RealTime += TextTime.RealTime - StartTime.RealTime;
      TotalTextTime.CPUTime += TextTime.CPUTime - StartTime.CPUTime;
    }

  if (isatty (fileno (InFile)) && !Quitting)
    fprintf (stderr, "\n");

  shut_down_stats (qd, &TotalStartTime, &TotalInvfTime, &TotalTextTime);

  Display_Stats (stderr);

}
Esempio n. 3
0
static int 
ProcessDocs (query_data * qd, int num, int verbatim,
	     char OutputType, FILE * Output)
{
  int max_buf = 0;
  int DocCount = 0;
  char *doc_sepstr = NULL;
  char *para_sepstr = NULL;
  char *para_start = NULL;
  int heads_length = atoi (GetDefEnv ("heads_length", "50"));
  char QueryType = get_query_type ();
  int need_text = (OutputType == OUTPUT_TEXT || OutputType == OUTPUT_HILITE ||
	       OutputType == OUTPUT_HEADERS || OutputType == OUTPUT_SILENT);

  if (OutputType == OUTPUT_TEXT || OutputType == OUTPUT_HILITE)
    {
      if (QueryType == QUERY_APPROX || QueryType == QUERY_RANKED)
	{
	  doc_sepstr = de_escape_string (
				    Xstrdup (GetDefEnv ("ranked_doc_sepstr",
			   "---------------------------------- %n %w\\n")));
	}
      else
	{
	  doc_sepstr = de_escape_string (
					  Xstrdup (GetDefEnv ("doc_sepstr",
			      "---------------------------------- %n\\n")));
	}
      para_sepstr = de_escape_string (
				       Xstrdup (GetDefEnv ("para_sepstr",
				  "\\n######## PARAGRAPH %n ########\\n")));

      para_start = de_escape_string (
				      Xstrdup (GetDefEnv ("para_start",
					    "***** Weight = %w *****\\n")));
    }

  if (need_text)
    {
      max_buf = atoi (GetDefEnv ("buffer", "1048576"));
    }

  do
    {
      u_char *UDoc = NULL;
      unsigned long ULen;

      if (need_text)
	{
	  /* load the compressed text */
	  if (LoadCompressedText (qd, max_buf))
	    {
	      Message ("Unable to load compressed text.");
	      FatalError (1, "This is probably due to lack of memory.");
	    }

	  /* uncompress the loaded text */
	  UDoc = GetDocText (qd, &ULen);
	  if (UDoc == NULL)
	    FatalError (1, "UDoc is unexpectedly NULL");
	}


      if (!UDoc || PostProc ((char *) UDoc, verbatim))
	{
	  switch (OutputType)
	    {
	    case OUTPUT_COUNT:
	    case OUTPUT_SILENT:
	      break;
	    case OUTPUT_DOCNUMS:	/* This prints out the docnums string */
	      if (PagerRunning)
		fprintf (Output, "%8d   %6.4f   %7lu\n", GetDocNum (qd),
			 GetDocWeight (qd), GetDocCompLength (qd));
	      break;
	    case OUTPUT_HEADERS:	/* This prints out the headers of the documents */
	      if (PagerRunning)
		fprintf (Output, "%d ", GetDocNum (qd));
	      HeaderOut (Output, UDoc, ULen, heads_length);
	      if (PagerRunning)
		fputc ('\n', Output);
	      break;
#if TREC_MODE
	    case OUTPUT_EXTRAS:	/* This prints out the docnums string */
	      if (PagerRunning && trec_ids)
		{
		  long DN, PN = GetDocNum (qd) - 1;
		  if (trec_paras)
		    DN = trec_paras[PN];
		  else
		    DN = PN;
		  fprintf (Output, "%-14.14s  %8ld  %10.5f\n",
			   &trec_ids[DN * 14], PN + 1, GetDocWeight (qd));
		}
	      break;
#endif
	    case OUTPUT_TEXT:
	    case OUTPUT_HILITE:
	      {
		int j, para = -1, curr_para = 0;
		int init_para = -1;
		DocEntry *de, *doc_chain = NULL;
		int p_on = 0;
		register char ch = ' ';
		register char lch = '\n';
		if (PagerRunning)
		  {
		    StringOut (Output, doc_sepstr,
			       1, GetDocNum (qd),
			       QueryType == 'A' || QueryType == 'R',
			       GetDocWeight (qd));
		  }
		if (qd->id->ifh.InvfLevel == 3)
		  {
		    init_para = FetchInitialParagraph (qd->td, GetDocNum (qd));
		    doc_chain = GetDocChain (qd);
		    para = GetDocNum (qd) - init_para;

		    StringOut (Output, para_sepstr,
			       1, curr_para + 1,
			       0, 0);

		    if ((de = in_chain (0, init_para, doc_chain)))
		      StringOut (Output, para_start,
				 0, 0,
				 1, de->Weight);

		    if (doc_chain->DocNum - init_para == 0)
		      p_on = 1;
		  }
		for (j = 0; j < ULen; j++)
		  {
		    ch = UDoc[j];
		    switch (ch)
		      {
		      case '\02':
			break;
		      case '\01':
			ch = '\n';
		      case '\03':
			p_on = 0;
			curr_para++;
			StringOut (Output, para_sepstr,
				   1, curr_para + 1,
				   0, 0);
			lch = *(strchr (para_sepstr, '\0') - 1);
			if ((de = in_chain (curr_para, init_para, doc_chain)))
			  StringOut (Output, para_start,
				     0, 0,
				     1, de->Weight);
			if (doc_chain &&
			    doc_chain->DocNum - init_para == curr_para)
			  p_on = 1;
			break;
		      default:
			{
			  if (PagerRunning)
			    {
			      fputc (ch, Output);
			      if (p_on && isprint (ch))
				{
				  fputc ('\b', Output);
				  fputc ('_', Output);
				}
			    }

			  lch = ch;
			}
		      }
		  }
		if (PagerRunning && lch != '\n')
		  fputc ('\n', Output);
		p_on = 0;
	      }
	    }
	  if (PagerRunning)
	    fflush (Output);
	}
      DocCount++;

    }
  while (NextDoc (qd) && PagerRunning && (!Ctrl_C));

  if (need_text)
    {
      FreeTextBuffer (qd);
    }

  if (OutputType == OUTPUT_TEXT || OutputType == OUTPUT_HILITE)
    {
      Xfree (doc_sepstr);
      Xfree (para_sepstr);
      Xfree (para_start);
    }

  return (DocCount);
}