Logo Search packages:      
Sourcecode: zeitgeist-extensions version File versions  Download package

def fts::Indexer::search (   self,
  query_string,
  time_range = None,
  filters = None,
  offset = 0,
  maxhits = 10,
  result_type = 100 
)

Do a full text search over the indexed corpus. The `result_type`
parameter may be a zeitgeist.datamodel.ResultType or 100. In case it is
100 the textual relevancy of the search engine will be used to sort the
results. Result type 100 is the fastest (and default) mode.

The filters argument should be a list of event templates.

Definition at line 191 of file fts.py.

00191                                                                                                            :
            """
            Do a full text search over the indexed corpus. The `result_type`
            parameter may be a zeitgeist.datamodel.ResultType or 100. In case it is
            100 the textual relevancy of the search engine will be used to sort the
            results. Result type 100 is the fastest (and default) mode.
            
            The filters argument should be a list of event templates.
            """
            # Expand event template filters if necessary
            if filters:
                  query_string = "(%s) AND (%s)" % (query_string, self._compile_event_filter_query (filters))
            
            # Expand time range value query
            if time_range and not time_range.is_always():
                  query_string = "(%s) AND (%s)" % (query_string, self._compile_time_range_filter_query (time_range))
            
            # If the result type coalesces the events we need to fetch some extra
            # events from the index to have a chance of actually holding 'maxhits'
            # unique events
            if result_type in COALESCING_RESULT_TYPES:
                  raw_maxhits = maxhits * 3
            else:
                  raw_maxhits = maxhits
            
            # Allow wildcards
            query_start = time.time()
            query = self._query_parser.parse_query (query_string,
                                                    self.QUERY_PARSER_FLAGS)
            self._enquire.set_query (query)
            hits = self._enquire.get_mset (offset, raw_maxhits)
            hit_count = hits.get_matches_estimated()
            log.debug("Search '%s' gave %s hits in %sms" %
                      (query_string, hits.get_matches_estimated(), (time.time() - query_start)*1000))
            
            if result_type == 100:
                  event_ids = []
                  for m in hits:
                        event_id = int(xapian.sortable_unserialise(
                                                  m.document.get_value(VALUE_EVENT_ID)))
                        log.debug("%i: %i%% docid=%i eventid=%s" %
                                  (m.rank + 1, m.percent, m.docid, event_id))
                        event_ids.append (event_id)
                  if event_ids:
                        return self._engine.get_events(ids=event_ids), hit_count
                  else:
                        return [], 0
            else:
                  templates = []
                  for m in hits:
                        event_id = int(xapian.sortable_unserialise(
                                                  m.document.get_value(VALUE_EVENT_ID)))
                        log.debug("%i: %i%% docid=%i eventid=%s" %
                                  (m.rank + 1, m.percent, m.docid, event_id))
                        ev = Event()
                        ev[0][Event.Id] = str(event_id)
                        templates.append(ev)
            
                  if templates:
                        return self._engine._find_events(1, TimeRange.always(),
                                                         templates,
                                                         StorageState.Any,
                                                         maxhits,
                                                         result_type), hit_count
                  else:
                        return [], 0
      
      def _worker_thread (self):


Generated by  Doxygen 1.6.0   Back to index