PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/htdig-3.2.0b6/htsearch/Query.cc

#
C++ | 89 lines | 41 code | 11 blank | 37 comment | 8 complexity | ffcd3c9212f94a422b08b5f83ec1d265 MD5 | raw file
Possible License(s): LGPL-2.0, GPL-2.0, BSD-3-Clause, LGPL-2.1
  1. //
  2. // Query.cc
  3. //
  4. // Query: (abstract) a parsed, 'executable' digger database query
  5. // a query tree is formed by leaf objects (ExactWordQuery) and
  6. // node objects (OperatorQuery) derived from this class.
  7. // Query execution results are returned as ResultList objects.
  8. // Query evaluation is cached. Cache policy is delegated to the
  9. // QueryCache class family.
  10. //
  11. // Part of the ht://Dig package <http://www.htdig.org/>
  12. // Copyright (c) 1995-2004 The ht://Dig Group
  13. // For copyright details, see the file COPYING in your distribution
  14. // or the GNU Library General Public License (LGPL) version 2 or later
  15. // <http://www.gnu.org/copyleft/lgpl.html>
  16. //
  17. // $Id: Query.cc,v 1.4 2004/05/28 13:15:24 lha Exp $
  18. //
  19. #include "Query.h"
  20. #include "VolatileCache.h"
  21. //
  22. // the in-memory query result cache. the default instance is
  23. // defined static so its destructor is called at program exit
  24. //
  25. VolatileCache theDefaultCache;
  26. QueryCache *
  27. Query::cache = &theDefaultCache;
  28. extern int debug;
  29. //
  30. // destructor
  31. //
  32. Query::~Query()
  33. {
  34. }
  35. //
  36. // return a ResultList with the query results
  37. // results are initially fetched from the cache
  38. // if not cached, the query is evaluated
  39. // Weight of the results is adjusted at each invocation, as
  40. // the same result list may be shared by different queries
  41. // but different weights may be assigned to the word
  42. //
  43. //
  44. ResultList *
  45. Query::GetResults()
  46. {
  47. ResultList *result = 0;
  48. // try to find in cache before trying eval
  49. String signature;
  50. if(cache)
  51. {
  52. signature = GetSignature();
  53. result = cache->Lookup(signature);
  54. }
  55. // no cache or not in cache, evaluate
  56. if(!result)
  57. {
  58. if(debug) cerr << "EVAL: " << signature << endl;
  59. result = Evaluate();
  60. if(cache)
  61. {
  62. cache->Add(signature, result);
  63. }
  64. }
  65. // adjust if something found/returned
  66. if(result)
  67. {
  68. if(result->Count())
  69. {
  70. AdjustWeight(*result);
  71. }
  72. else if(!result->IsIgnore())
  73. {
  74. result = 0;
  75. }
  76. }
  77. return result;
  78. }