Open the first document with the given ``title`` that is
        returned by document search.
487822
def by_title(cls, title, conn=None, google_user=None,
                 google_password=None):
        
        conn = Connection.connect(conn=conn, google_user=google_user,
                                  google_password=google_password)
        q = DocsQuery(categories=['spreadsheet'], title=title)
        feed = conn.docs_client.GetResources(q=q)
        for entry in feed.entry:
            if entry.title.text == title:
                id = entry.id.text.rsplit('%3A', 1)[-1]
                return cls.by_id(id, conn=conn)
1351486
def first(self, default=None, as_dict=False, as_ordereddict=False):
        """"""

        # Try to get a record, or return/raise default.
        try:
            record = self[0]
        except IndexError:
            if isexception(default):
                raise default
            return default

        # Cast and return.
        if as_dict:
            return record.as_dict()
        elif as_ordereddict:
            return record.as_dict(ordered=True)
        else:
            return record
780449
@View(name = "by_name", map = "function(doc) { if(doc.name && doc.value) { emit(doc.name, doc) } }")
    public CouchDbSamlMetadataDocument findFirstByName(final String name) {
        val view = createQuery("by_name").key(name).limit(1);
        return db.queryView(view, CouchDbSamlMetadataDocument.class).stream().findFirst().orElse(null);
    }
866751
def search(title)
      results = get '/', { s: title }
      if results[:search]
        # Return the title if there is only one result, otherwise return the seach results
        search = results.search
        search.size == 1 ? title(search[0].title) : search
      else
        results
      end
    end
512394
def find_first(self, name=None, ns_uri=None):
        
        return self.find(name=name, ns_uri=ns_uri, first_only=True)
1031852
def _extract_url_and_title(self, text, start):
        """"""
        # text[start] equals the opening parenthesis
        idx = self._whitespace.match(text, start + 1).end()
        if idx == len(text):
            return None, None
        end_idx = idx
        has_anglebrackets = text[idx] == "<"
        if has_anglebrackets:
            end_idx = self._find_balanced(text, end_idx+1, "<", ">")
        end_idx = self._find_balanced(text, end_idx, "(", ")")
        match = self._inline_link_title.search(text, idx, end_idx)
        if not match:
            return None, None
        url = text[idx:match.start()]
        if has_anglebrackets:
            url = self._strip_anglebrackets.sub(r'\1', url)
        return url, end_idx
554687
def get_document_field(instance):
        
        for name, field in instance.searchindex.fields.items():
            if field.document is True:
                return name
72099
def first(self):
        """"""
        if self._results_cache:
            return self._results_cache[0]

        query = PaginatedResponse(func=self._func, lwrap_type=self._lwrap_type, **self._kwargs)
        try:
            return next(query)
        except StopIteration:
            return None
188652
def createDocument_(self, initDict = None) :
        ""
        if initDict is None :
            initV = {}
        else :
            initV = initDict

        return self.documentClass(self, initV)
904078
def query_one(cls, *args, **kwargs):
        
        doc = cls._coll.find_one(*args, **kwargs)
        if doc:
            return cls.from_storage(doc)
1343886
def _find_title(html_file):
    """"""
    # TODO Is it necessary to read files like this?
    with html_file.open() as f:
        for line in f:
            if '<title>' in line:
                # + 7 to skip len('<title>')
                return line[line.index('<title>') + 7:line.index('</title>')]

    return '(Unknown)'
754463
def open_wordfile (app, filename):
    """"""
    return app.Documents.Open(filename, ReadOnly=True,
      AddToRecentFiles=False, Visible=False, NoEncodingDialog=True)
1282910
def openall(self, title=None):
        
        spreadsheet_files = self.list_spreadsheet_files()

        return [
            Spreadsheet(self, dict(title=x['name'], **x))
            for x in spreadsheet_files
        ]
1059869
def first
      reply = read_preference.with_node(cluster) do |node|
        node.query(
          operation.database,
          operation.collection,
          operation.selector,
          query_options(
            fields: operation.fields,
            flags: operation.flags,
            skip: operation.skip,
            limit: -1
          )
        )
      end
      reply.documents.first
    end
4685
def one(cls, filter=None, **kwargs):
        """"""
        from mongoframes.queries import Condition, Group, to_refs

        # Flatten the projection
        kwargs['projection'], references, subs = \
                cls._flatten_projection(
                    kwargs.get('projection', cls._default_projection)
                    )

        # Find the document
        if isinstance(filter, (Condition, Group)):
            filter = filter.to_dict()

        document = cls.get_collection().find_one(to_refs(filter), **kwargs)

        # Make sure we found a document
        if not document:
            return

        # Dereference the document (if required)
        if references:
            cls._dereference([document], references)

        # Add sub-frames to the document (if required)
        if subs:
            cls._apply_sub_frames([document], subs)

        return cls(document)
185913
def get_or_create_by_title(self, title):
        
        try:
            obj = self.get_by_title(title)
            created = False
        except DoesNotExistError:
            obj = self.create(title=title)
            created = True
        return obj, created
498828
def create(self, title):
    
    return self.send_request(C.POST, self.end, data={'title':title})