예제 #1
0
def SearchIssueFullText(project_ids, query_ast_conj, shard_id):
    """Do full-text search in GAE FTS.

  Args:
    project_ids: list of project ID numbers to consider.
    query_ast_conj: One conjuctive clause from the AST parsed
        from the user's query.
    shard_id: int shard ID for the shard to consider.

  Returns:
    (issue_ids, capped) where issue_ids is a list of issue issue_ids that match
    the full-text query.  And, capped is True if the results were capped due to
    an implementation limitation.  Or, return (None, False) if the given AST
    conjunction contains no full-text conditions.
  """
    fulltext_query = fulltext_helpers.BuildFTSQuery(query_ast_conj,
                                                    ISSUE_FULLTEXT_FIELDS)
    if fulltext_query is None:
        return None, False

    if project_ids:
        project_clause = ' OR '.join('project_id:%d' % pid
                                     for pid in project_ids)
        fulltext_query = '(%s) %s' % (project_clause, fulltext_query)

    # TODO(jrobbins): it would be good to also include some other
    # structured search terms to narrow down the set of index
    # documents considered.  E.g., most queries are only over the
    # open issues.
    logging.info('FTS query is %r', fulltext_query)
    issue_ids = fulltext_helpers.ComprehensiveSearch(
        fulltext_query, settings.search_index_name_format % shard_id)
    capped = len(issue_ids) >= settings.fulltext_limit_per_shard
    return issue_ids, capped
 def testComprehensiveSearch(self):
     self.SetUpComprehensiveSearch()
     self.mox.ReplayAll()
     project_ids = fulltext_helpers.ComprehensiveSearch(
         'browser', 'search index name')
     self.mox.VerifyAll()
     self.assertItemsEqual([123, 234, 345], project_ids)
예제 #3
0
    def testSearchIssueFullText_CrossProject(self):
        self.mox.StubOutWithMock(fulltext_helpers, 'ComprehensiveSearch')
        fulltext_helpers.ComprehensiveSearch(
            '(project_id:789 OR project_id:678) (summary:"test")',
            settings.search_index_name_format % 1).AndReturn([123, 234])
        self.mox.ReplayAll()

        summary_fd = tracker_pb2.FieldDef(
            field_name='summary', field_type=tracker_pb2.FieldTypes.STR_TYPE)
        query_ast_conj = ast_pb2.Conjunction(conds=[
            ast_pb2.Condition(op=ast_pb2.QueryOp.TEXT_HAS,
                              field_defs=[summary_fd],
                              str_values=['test'])
        ])
        issue_ids, capped = tracker_fulltext.SearchIssueFullText(
            [789, 678], query_ast_conj, 1)
        self.mox.VerifyAll()
        self.assertItemsEqual([123, 234], issue_ids)
        self.assertFalse(capped)
예제 #4
0
 def SetUpSearchIssueFullText(self):
     self.mox.StubOutWithMock(fulltext_helpers, 'ComprehensiveSearch')
     fulltext_helpers.ComprehensiveSearch(
         '(project_id:789) (summary:"test")',
         settings.search_index_name_format % 1).AndReturn([123, 234])